I have a leaflet map that tracks realtime data and i currently have it updating the positions correctly every x seconds, but the old markers are not being deleted. Im at the point that I will just remove all markers and re-add them. I think this is also impacting memory for the page, because the values increase by 166 every time
I have to be overlooking something really silly.
My json is like:
{"_items": [{"uniqueID": "a123", "isMoving": false, "bearing": 231, "longitude": -xx.xxxxx, "latitude": xx.xxxxx}]}
And here is the code that adds the markers
var marker = new Array();
for(i=0;i<myjson._items.length;i++){
var LamMarker = new L.marker([myjson._items[i].latitude, myjson._items[i].longitude],{
icon: autotop
});
console.log(myjson._items[i].latitude)
marker.push(LamMarker);
map.addLayer(marker[i]);
}
}
i have been trying something along the lines of
if (map.hasLayer(marker)) {
for(i=0;i<marker.length;i++) {
map.removeLayer(marker[i])
}
}
before my function fires.
Any help would be great.