Answer the question
In order to leave comments, you need to log in
How to dynamically display, remove and change markers on a leaflet map?
Hello.
There is such a script for displaying markers on the site:
var markers;
function reload_marker(map_left,map_right,map_top,map_down) {
$.getJSON('/json.php', {left:map_left,right:map_right,top:map_top,down:map_down}, function (serv) {
massiv =[]; // Создаем массив
// Получаем данные из json.php
serv.features.forEach(function(n) {
marker = new L.marker([n.geometry.coordinates[0],n.geometry.coordinates[1]]);
massiv.push(marker); // добавляем marker к массиву
});
})
.done(function() {
// Удаляем старые маркеры
if(markers) {
markers.clearLayers();
}
// Добавляем новые
markers = L.featureGroup(massiv).addTo(map);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question