Skip to content

How do I save data in the free version #858

Discussion options

You must be logged in to vote

You can read out all layers on the map and save them as geojson to the localstorage or db.

var data = localStorage.getItem('data');
if(data){
	var geoLayer = L.geoJSON(JSON.parse(data)).addTo(map);
}


function saveToDb(){
	var allLayers = L.featureGroup();
        map.eachLayer(function(layer){
  	    if(layer instanceof L.Path || layer instanceof L.Marker){
    	      allLayers.addLayer(layer);
            }
         });
	var geojson = allLayers.toGeoJSON();
        localStorage.setItem('data', JSON.stringify(geojson));
}

But you have to add properties to the geojson which color, options the layer has and what type of layer it is. A Circle will displayed as Marker by default. But this …

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Falke-Design
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #588 on April 14, 2021 20:20.