用传单 geoman 在多边形上切孔

Cut holes in polygon with leaflet geoman

我正在使用神奇的 "leaflet geoman" 来绘制和编辑几何图形,但无法理解切割工具的工作原理。如何获取已切割图层的几何形状?

这是我的代码:

mymap.on('pm:create', function(e) {        
                e.poly;
                var type = e.layerType,
                    layer = e.layer;
                $(document).ready(function() {
                        layer.on('pm:cut', ({ layer }) => {
                             console.log(layer.toGeoJSON());
                        });
                    var jsnPolygon = e.layer.toGeoJSON().geometry;
                    jsnPolygon = {
                        type: "MultiPolygon",
                        coordinates: [jsnPolygon.coordinates]
                    };
                    console.log(layer.toGeoJSON());
                })
            });

console.log切割前后的结果是一样的,即矩形坐标。

----更新---

按照建议添加 console.log(JSON.stringify(e)); returns 此错误:

Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'e'
    |     property 'pm' -> object with constructor 'e'
    --- property '_layer' closes the circle

完成剪切后的行为是它仍然启用了 drawing/cutting-tool,尽管我不能 "finish"。

尝试:

map.on("pm:cut",function(e){
   console.log(e.layer.getLayers()[0].getLatLngs()); //or loop through with e.layer.eachLayer(func)
});

您需要使用正确的事件。 Geoman Docs

// This fires when cutting event is completed
mymap.on('pm:cut', e => {
  // This is the full event object
  console.log(e)

  // This holds the new geometry
  console.log(e.layer.toGeoJSON())
})