Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to get the geojson of all features added by Leaflet-geoman #605

Closed
AnubhabMondal opened this issue Jun 9, 2020 · 5 comments
Labels

Comments

@AnubhabMondal
Copy link

HI @codeofsumit ,
What code should I implement to get geojson all the features added by geoman ?

@Falke-Design
Copy link
Collaborator

You can get all layers from the map and check if they have the pm property and not temporary layers.


function generateGeoJson(){
	var fg = L.featureGroup();    
	var layers = findLayers(map);
        layers.forEach(function(layer){
  	    fg.addLayer(layer);
         });
	console.log(fg.toGeoJSON());
}

function findLayers(map) {
    var layers = [];
    map.eachLayer(layer => {
      if (
        layer instanceof L.Polyline || //Don't worry about Polygon and Rectangle they are included in Polyline
        layer instanceof L.Marker ||
        layer instanceof L.Circle ||
        layer instanceof L.CircleMarker
      ) {
        layers.push(layer);
      }
    });

    // filter out layers that don't have the leaflet-geoman instance
    layers = layers.filter(layer => !!layer.pm);

    // filter out everything that's leaflet-geoman specific temporary stuff
    layers = layers.filter(layer => !layer._pmTempLayer);

    return layers;
  }

Demo: https://jsfiddle.net/falkedesign/054go8j2/

@AnubhabMondal
Copy link
Author

AnubhabMondal commented Jun 10, 2020

@Falke-Design Thank You very much. Your replay is valuable and that works for me. Now I can export geojson value.
Can u plz give me an idea of how to import [Circlel also] those values into my map for next time? If u share something any code structure that would really very helpful for me.
Thanks.

@AnubhabMondal
Copy link
Author

Hi, @Falke-Design Can you plz share something ..?

@Falke-Design
Copy link
Collaborator

@AnubhabMondal I created a example for you: https://jsfiddle.net/falkedesign/4fycojbu/

This has nothing to do with geoman anymore #close

@AnubhabMondal
Copy link
Author

Thank You so much @Falke-Design for your help.

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

2 participants