سؤال

I searched a possible solution but I have not been able to find. In my application a number of leaflet markers which are updated every few minutes is displayed. I need to find each of these markers either by name or id, and update your position on the map. Is this possible? or could do. Thank you in advance.

هل كانت مفيدة؟

المحلول

You can save your markers in an array and then update them.

var layer = new Array();
var plot = L.marker([lat, long], {"icon": icon});
map.addLayer(plot);
layer["myId"] = plot;

...

var lat = (xxxx);
var lng = (xxxxx);
var newLatLng = new L.LatLng(lat, lng);
layer["myId"].setLatLng(newLatLng);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top