Raj
Raj

Reputation: 335

Editing a shapefile uploaded using leaflet.shapefile

I'm using Mapbox with Leaflet for drawing, editing and removing polygons etc. There might also be a case in which the user might have zipped shapefiles and want to use that directly, instead of drawing the polygons. So I'm using leaflet.shapefile to upload shapefiles and add them to the map.

But when I try to edit the shapefiles using the Leaflet Draw control, I get an error telling me that "i.editing is undefined". I tried converting the layer to GeoJSON before adding it to the featureGroup just in case (like in the code below), to see if that had any effect, but it didn't.

var layergeojson = layer.toGeoJSON();
featureGroup.addLayer(layergeojson);

This is a jsfiddle of what I have right now. I tried researching online to see any similar cases, but I'm not able to find any.

Is it possible to edit the uploaded shapefiles using the Leaflet Draw control?

Upvotes: 2

Views: 1804

Answers (1)

ghybs
ghybs

Reputation: 53205

When you do var layergeojson = layer.toGeoJSON(), the layergeojson now contains a plain GeoJSON object, not a Leaflet layer.

Therefore, featureGroup.addLayer(layergeojson) should throw an error (open your browser console). Instead, you should probably use the .addData() method: featureGroup.addData(layergeojson).

As for editing your resulting layers, it might be related to this: https://gis.stackexchange.com/questions/203540/how-to-edit-an-existing-layer-using-leaflet/203773#203773

Upvotes: 3

Related Questions