【问题标题】:Is there any way to edit existing geojson data on the leaflet-map有没有办法在传单地图上编辑现有的 geojson 数据
【发布时间】:2019-05-02 11:47:39
【问题描述】:

我想为传单地图上当前显示的 geojson 多边形图层提供编辑支持。按下编辑按钮时,它会给我

未捕获的类型错误:无法读取 null 的属性 'lat'

这是我的代码:

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);
});

我使用传单画

【问题讨论】:

标签: javascript reactjs leaflet react-leaflet leaflet.draw


【解决方案1】:

我 我终于找到了根本原因,因为我们在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 2014-03-01
    相关资源
    最近更新 更多