mam kod odłogowania:jak wyczyścić mapę ulotek wszystkich znaczników i warstw przed dodaniem nowych?
map: function (events) {
var arrayOfLatLngs = [];
var _this = this;
// setup a marker group
var markers = L.markerClusterGroup();
events.forEach(function (event) {
// setup the bounds
arrayOfLatLngs.push(event.location);
// create the marker
var marker = L.marker([event.location.lat, event.location.lng]);
marker.bindPopup(View(event));
// add marker
markers.addLayer(marker);
});
// add the group to the map
// for more see https://github.com/Leaflet/Leaflet.markercluster
this.map.addLayer(markers);
var bounds = new L.LatLngBounds(arrayOfLatLngs);
this.map.fitBounds(bounds);
this.map.invalidateSize();
}
początkowo wywołać tę funkcję i doda wszystkie events
na mapie za pomocą markerów i klastrów.
W niektórych punktach piany przechodzę w inne zdarzenia, mapa będzie powiększać do nowych zdarzeń, ale stare są nadal na mapie.
Próbowałem this.map.removeLayer(markers);
i kilka innych rzeczy, ale nie mogę dostać stare znaczniki zniknąć
jakieś pomysły?
dzięki, 'markers.clearLayers();' wystarczyły, ale miał dobry punkt przy użyciu 'this' inaczej nie mogłem zrobić – Patrioticcow