toGeoJSON of L.Circle doesn't have the radius of the circle
See original GitHub issuecircle.toGeoJSON() print something like
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [30.5,50.5]
}
}
There is no Radius in the geometry so if I save the geometry I can’t show the circle in my map again just with the geometry. 😢
Issue Analytics
- State:
- Created 8 years ago
- Reactions:11
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How To Handle Circles in GeoJSON - Medium
You can extract the radius of the circle layer and store it inside the custom properties of a GeoJSON. Using Leaflet, it could...
Read more >geojson circles, supported or not? - Stack Overflow
When I look up the specs of GeoJson I see that circles are supported. They aren't. Seems you managed to find some fake...
Read more >L.Circle - WRLD3D
Instantiates a circle object given a geographical point, and an options object which contains the circle radius. L.circle(<LatLng> latlng, <Number> radius, ...
Read more >How to get the exact Circle that user has drawn using Leaflet ...
map.on(L. ... Draw.Event.CREATED, function (event) { var layer = event.layer; console.log(layer.toGeoJSON()); drawnItems.addLayer(layer); });.
Read more >L.Circle
setRadius ( <Number> radius ), this, Sets the radius of a circle. Units are in meters. toGeoJSON(), Object, Returns a GeoJSON representation of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this issue is open already for almost 2.5 years. It is ridiculous to not solve the issue because of some minor technical difficulties. Just returning a GeoJson-point for L.Circle.toGeoJSON definitely is a bug and a huge loss of information. A practical solution which is closer to the desired result would be to return a polygon in GeoJson instead. A polygon also would allow for point in area calculation, merging of geometry area,… without requiring the developers to add extra cases for L.Circle everywhere. Whatever you do, the current behavior is about as bad of a solution as it can get.
I know this is somewhat of an outdated topic… but I ran into the same problem. Sounds like I had the same problem as @jbcoder. Leaflet is storing feature type as a “point” and not a “circle” when it comes to GeoJSON. From the thread here, it would seem that this is correct, though the only difference is that circles contain a radius property.
I can easily get this to work with single features, but it posed a problem with feature collections.
So what you can do is implement the first code block that @MarkAPhillips suggests in a couple posts up. That is to capture the radius property and add it to the feature inside the draw event. Ideally you could save this back to your DB, along with a “radius” property. Individual point markers should NOT have a radius property.
Then modify the actual leaflet.js to allow the handling of circle drawing when calling on L.geoJson (and passing a feature collection rather than just a single feature…). In the switch clause for the point, you can check if the radius property exists. If so, instead of returning a pointToLayer for the point, return a L.Circle, passing the radius. Seems to work fine for me.
Until this is resolved I can’t actually use the CDN to pull in this library, and have to use my own version locally.