2

leaflet use FeatureGroup() for edit. and I want to save data use toGeoJSON.but circle,marker... have point info only.

{"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]}}]}

I need save more info.how?

fe263
  • 107
  • 8
  • See https://stackoverflow.com/questions/35760126/leaflet-draw-not-taking-properties-when-converting-featuregroup-to-geojson/35819611#35819611 – ghybs Nov 24 '16 at 11:30

1 Answers1

1

Strictly speaking saving this kind of data "to GeoJSON" is not possible because simply GeoJSON does not support circles.

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

The old 2008 GeoJSON spec says nothing about circles http://geojson.org/geojson-spec.html and neither the new one (august 2016) https://www.rfc-editor.org/rfc/rfc7946

If you want to save a point and its radius to represent a circle you need to make a format of your own, but this of course will not work out-of-the-box with leaflet's geojson layergroup.

Edit: seems some people went down that road already so you may wanna check this out: https://github.com/Leaflet/Leaflet.draw/issues/390

They saving the radius in the properties of GeoJSON and extended the GeoJSON layergroup to work with that. A bit hacky, geojson spec goes down the drain, but it seems to accomplish what you want.

Another possibility is to convert your circles to polygons with an acceptable amount of nodes, then saving that polygon in GeoJSON.

Community
  • 1
  • 1
Sharky
  • 6,154
  • 3
  • 39
  • 72