Hello, I have a similar problem - When adding some points to the map I would like to update them every 5 sec. When adding the code it seems like the browser are running out of memory within a few minutes. Please advice. Or am I doing something that is possible?
var map;
function init() {
map = L.map('map').setView([54.55004,11.7428], 13);
}).addTo(map);
var loadData = function() {
map.removeLayer(L.circleMarker);
map.removeLayer(L.geoJson);
var bodyContent = $.ajax({
url: "connectdong.php",
global: true,
type: "POST",
data: "name=value",
dataType: "json",
async:false,
success: function(msg){
}
}).responseText;
var mills_geojson = "var mills_geojson = " + bodyContent;
eval(mills_geojson);
var on_mill = {
radius: 8,
fillColor: "#FF0000",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 1
};
var off_mill = {
radius: 8,
fillColor: "#00FF00",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 1
};
function onEachFeature(feature, layer) {
if (feature.properties && feature.properties.radio ) {
layer.bindPopup(feature.properties.radio);
}
if (feature.properties && feature.properties.nix ) {
layer.bindPopup(feature.properties.nix);
}
}
L.geoJson(mills_geojson, {
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
if (feature.properties.radio){
return L.circleMarker(latlng, on_mill);
}
else{
return L.circleMarker(latlng, off_mill);
}
}
}).addTo(map);
}
loadData();
setInterval(loadData, 5000); //5 seconds
};
How to prevent memory loss. Anybody ??