I'm finding it strange that I have to reverse the lat/long on my polygons for it to render in the correct location (I've included comments in the JavaScript on what's correct).
Reproducible on all Safari, Chrome, FF using Leaflet 0.7.2.
GeoJSON spec dictates long, lat, while Leaflet uses lat, long. You'll have to deal with it.
GeoJsonLayer handles this. No need to reverse it.
Just make sure you're providing coordinates as [long,lat] in accordance with GeoJSON spec as @mourner was trying to say it.
Maybe an inverse option could be added to do this. In my use case, I extract features from GeoJsonLayer and work with them individually and I have to deal with it.
@ajshukury dealing with special cases like that is outside the scope of Leaflet.
Have you looked at the toGeoJSON methods in Leaflet? This should give you the expected coordinate order.
If you have deal with flipping the axis yourself, you could use an external library to help you deal with it. For example, Turf.js has the function flip, which will handle flipping coordinate order for you.
@perliedman yeah. I use the flip function and was wondering if it is something useful and widely used by others too then maybe adding to leaflet worth but other than that not necessary. Thanks
Just a quick comment because it gave me so many headaches. I was trying to add geojson into Leaflet and I thought I had to use a loop to swap the coordinates and put them into L.polygons. But the only real problem was that I was using L.geoJSON(geojson).addTo(map) instead of L.geoJson(geojson).addTo(map) to bring the shape into the map. This is because the syntax is different between the two versions.
Most helpful comment
@ajshukury dealing with special cases like that is outside the scope of Leaflet.
Have you looked at the
toGeoJSONmethods in Leaflet? This should give you the expected coordinate order.If you have deal with flipping the axis yourself, you could use an external library to help you deal with it. For example, Turf.js has the function
flip, which will handle flipping coordinate order for you.