使用Leaflet-draw使多边形可编辑

4

如何使从数据库加载到地图上的多边形可编辑?

目前,当多边形加载时,它们保持不可编辑状态。只有在创建新多边形时才启用编辑选项。

从数据库加载的多边形标记为蓝色,新创建的多边形标记为红色。(编辑图标出现了问题!)

进入图像描述区域


我发现以下链接很有帮助 - http://gis.stackexchange.com/questions/203540/how-to-edit-an-existing-layer-using-leaflet 和 https://github.com/Leaflet/Leaflet/issues/4461 - codejunkie
请问您能否发布一些代码,展示您是如何将数据库项目转换为leaflet项目的?这是我几年前的答案https://dev59.com/8YXca4cB1Zd3GeqPEi_L#26965160。 - pk.
我之前在stackoverflow上发布了另一个问题。那个问题的答案也解决了这个问题。这是链接 --> https://dev59.com/jZzha4cB1Zd3GeqPAiQb?noredirect=1#comment68009098_40376176 - codejunkie
1个回答

0
let map = L.map("map").setView([41.31, 69.27], 12);
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png").addTo(map);

let drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);

// 工具栏
var drawControl = new L.Control.Draw({
  draw: {. . .},
  edit: {
    featureGroup: drawnItems,
    poly: {
      allowIntersection: false
    }
  }
});
map.addControl(drawControl);

map.on("draw:edited", function(e) {
  let layers = e.layers;
  layers.eachLayer(function(layer) {
    console.log(layer);
  });
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接