如何将 leaflet draw 的数据自定义保存到 GeoJSON?

how save leaflet draw 's data custom toGeoJSON?

传单使用 FeatureGroup() 进行编辑。我想保存数据使用 toGeoJSON.but 圆圈、标记...只有点信息。

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[118.49561691284181,31.87595414652557]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[118.5268591952,31.848500597]}}]}

我需要存更多钱info.how?

严格来说,将这种数据“保存到 GeoJSON”是 不可能 因为 GeoJSON 支持圆圈。

GeoJSON supports the following geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

旧的 2008 GeoJSON 规范没有提及圆 http://geojson.org/geojson-spec.html 也不是新的(2016 年 8 月)https://www.rfc-editor.org/rfc/rfc7946

如果你想保存一个点及其半径来表示一个圆,你需要自己制作一个格式,但这当然不能与传单的 geojson layergroup 开箱即用。

编辑:似乎有些人已经走上了这条路所以你可能想看看这个: https://github.com/Leaflet/Leaflet.draw/issues/390

他们将半径保存在 GeoJSON 的 properties 中,并扩展了 GeoJSON 图层组以使用它。有点 hacky,geojson 规范落空了,但它似乎完成了你想要的。

另一种可能性是将您的圆圈转换为具有可接受数量节点的多边形,然后将该多边形保存在 GeoJSON 中。