[英]Is there any way to edit existing geojson data on the leaflet-map
我想為傳單地圖上當前顯示的 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); });
我使用傳單抽獎
我終於找到了根本原因,因為我們在 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.