leaflet.pm 编辑模式获取形状内的新坐标

leaflet.pm edit mode get new coordinates within shape

我正在使用 leaflet js 构建带有一些图钉的地图 https://leafletjs.com/ and I'm also allowing drawing of shapes, e.g. polygons, circles etc. I also these to be edited using a plugin called leaflet.pm https://github.com/codeofsumit/leaflet.pm

此处有事件,但 none 事件在禁用编辑模式或拖动完成后返回新位置的坐标。这是我参与的活动;

map.on('pm:globaleditmodetoggled', function(e) {
    console.log(e);
});

这个活动在哪里给了我需要的东西;

map.on('pm:create', function(e) {
    let obj = {
        type: e.shape,
        coordinates: e.layer.editing.latlngs[0][0]
    };

    $('#cords').val(JSON.stringify(obj))
});

知道如何在编辑形状时获取更新坐标吗?

我是 Sumit,leaflet.pm

的维护者

您可以做的是:监听正在创建的事件并将编辑事件添加到新形状:

map.on('pm:create',(e) {
  e.layer.on('pm:edit', ({ layer }) => {
    // layer has been edited
    console.log(layer.toGeoJSON());
  })
});

当然,无论何时向地图添加图层,您也可以将 pm:edit 事件应用于其引用。 此外,当您创建图层或向地图添加图层时,您可以简单地存储参考。编辑完成后,您只需检查参考的坐标(就像您通常在传单中所做的那样)。如果您只需要知道编辑何时完成,请使用 pm:edit 事件来捕捉图层何时被编辑。

希望对您有所帮助