vendredi 27 mars 2015

Reset Leaflet map


I'm creating a map like this:



var map_object = new L.Map('map', {
center: [39.8282, -98.5795],
zoom: 5,

});

var sublayers = [];

L.tileLayer('http://ift.tt/1v7mT0j',{
attribution: '&copy; <a href="http://ift.tt/ItuEqj">OpenStreetMap</a> contributors, &copy; <a href="http://ift.tt/1vMtqR2">CartoDB</a>'
}).addTo(map_object);

cartodb.createLayer(map_object,layerSource,options)
.addTo(map_object)
.done(function(layer) {
for (var i = 0; i < layer.getSubLayerCount(); i++) {
sublayers[i] = layer.getSubLayer(i);

}
})


This works great. I'm then changing the zoom and adding circles based on user clicking buttons.


Is there a simple way to get the map back to its original condition (i.e., before all the changes and additions created by user actions)? I'm looking to see if there's something better than removing each layer and rezooming, etc.


I tried to use map.remove and then run all the code above again, but this gives me an error:



Uncaught Error: Map container not found.


Which is referring to this line: var map_object = new L.Map('map', {





Aucun commentaire:

Enregistrer un commentaire