I'm using Leaflet-geoman to draw circles and polygons in a map.
How can I get the geojson of all features drawn in the map ?
To get all layers of the map you can use this:
var fg = L.featureGroup();
map.eachLayer((layer)=>{
if(layer instanceof L.Path || layer instanceof L.Marker){
fg.addLayer(layer);
}
});
console.log(fg.toGeoJSON());
If you want only the layers they are used from the plugin:
var fg = L.featureGroup();
map.eachLayer((layer)=>{
if((layer instanceof L.Path || layer instanceof L.Marker) && layer.pm){
fg.addLayer(layer);
}
});
console.log(fg.toGeoJSON());