我想为传单 map 上当前显示的 geojson 多边形图层提供编辑支持。当按下编辑按钮时,它会给我
Uncaught TypeError: Cannot read property 'lat' of null
这是我的代码:
const leafletGeoJSON = new L.GeoJSON(arr, {
style(feature: any) {
const temp = getColor(feature.properties.id);
return {
color: temp,
fillColor: temp
};
},
onEachFeature(feature, layer) {
layer.bindTooltip(feature.properties.description);
}
});
leafletGeoJSON.eachLayer(layer => {
reactRef.leafletElement.addLayer(layer);
});
我用的是leaflet-draw
最佳答案
我 我终于找到了根本原因,因为我们在 DB 上使用 Multipolyon 我只是按原样渲染但实际上传单绘制不支持 MultiPolygon 我将数据结构更改为 Polygon 然后现在一切正常。
这里的关键是 featureGroup 选项。这告诉插件哪个 FeatureGroup 包含应该可编辑的图层。 featureGroup 可以包含 0 个或多个几何类型为 Point、LineString 和 Polygon 的要素。 Leaflet.draw 不适用于多几何特征,例如 MultiPoint、MultiLineString、MultiPolygon 或 GeometryCollection。如果您需要向绘图插件添加多几何特征,请将它们转换为非多几何特征(点、线串或多边形)的 FeatureCollection。
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw-feature
关于javascript - 有没有办法在传单 map 上编辑现有的geojson数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55951793/