Using ESRI Leaflet I am adding markers to the map from an ArcGIS online feature service. I do this using the L.esri.query method similar to:
function slideChange(time1, time2, service) {
L.esri.query({
url: service
}).where("(date_cst BETWEEN DATE '" + time1 + "' AND DATE '" + time2 + "')").run(function (error, pings) {
trucks = L.geoJSON(pings);
// remove previously added markers
removeAllLayers();
map.addLayer(trucks);
});
}
Each time I try to call the function I need to remove previously placed markers using leaflet removeLayer() function.
function removeAllLayers() {
map.removeLayer(trucks)
}
The markers are never removed and the map freezes. How can I remove this specific layer from the map using esri leaflet?