Edit Leaflet multipolygons

3.1k Views Asked by At

I'm using the Leaflet.draw library to allow in map editing of geojson shapes. On multipolygon types though, I get the error message TypeError: layer.options is undefined from the library.

This looks like the same issue referenced here. Is there a workaround for this that allows drawing, editing, and deleting multipolygon type geojson?

2

There are 2 best solutions below

0
On BEST ANSWER

My workaround is just splitting the MultiPolygon type geojson into several Polygons.

if (shape.type === "MultiPolygon") {
  shape.coordinates.forEach(function(shapeCoords, i) {
    var polygon = {type:"Polygon", coordinates: shapeCoords};
    L.geoJson(polygon, {
      onEachFeature: function (feature, layer) {
        featureGroup.addLayer(layer);
      }
    });
  });
}
0
On

Alternatively, you could also use Leaflet.PM, a drawing library for leaflet that is supporting MultiPolygons.

Add your geojson shapes via L.geoJson and leaflet.pm can handle it's editing, including holes.

Disclaimer: I'm the maintainer of leaflet.PM