[GIS] Get geometry of polygon in leaflet

geojsongeometryleafletpolygon

In a leaflet map, user could add a shapefile or kml and is, drawened over base map layer using L. Shapefile and L. Kml plugins. After that, user selects some options in a leftside menu with dropdowns, etc. When finish, it click over a button and application needs to get geometry of 'imported' feature.

How could I get this geometry and conert it to geoJson?

Best Answer

I got it by my self:

    map.eachLayer(function(layer) {
        if( layer instanceof L.Shapefile ){         
            if (layer._layers) {
              for (var f in layer._layers) {
                var feature = layer._layers[f];
              }
              userPolygon = feature.toGeoJSON();
            }
        }
    });
Related Question