-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add precision parameter to all toGeoJSON functions #5444
Add precision parameter to all toGeoJSON functions #5444
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi and thanks a lot for looking into this!
I have three points I'd like to see addressed before merging this:
- As it is now, the coordinates output by
toGeoJSON
will be strings, not numbers; for example["-87.359296", "35.00118"]
rather than the expected[-87.359296, 35.00118]
- this looks wrong and might possibly trip up some receivers that care about data types; it is also against the RFC 7947 which says: "A position is an array of numbers" - The GeoJSON spec gives the precision as number of decimals, while this PR gives the precision as number of significant digits; as it is now, it is not possible to give a number that adheres to the GeoJSON spec's recommendation of six decimals
- Not necessarily important, but I think it might also be a good idea to default to the GeoJSON specs recommendation, so that we use six decimals unless something else is specified.
Hmm, looks like |
I think you could use L.Util.formatNum |
Changed Util.formaNum default to 6 decimails. Solved 0 decimals bug. Added tests. Can be useful for PR Leaflet#5444
Sorry for the delay, @perliedman! Those changes you requested are in. |
src/layer/GeoJSON.js
Outdated
// Reverse of [`coordsToLatLng`](#geojson-coordstolatlng) | ||
export function latLngToCoords(latlng) { | ||
export function latLngToCoords(latlng, precision) { | ||
precision = precision || 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way you cannot round to 0 decimals. When (if) my pr #5492 lands, you can skip this line of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch, I'll update that. I'm going to leave the default of 6
for now, though, because I don't know when/if your PR will come through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for finishing this!
* Util.formatNum default to 6 Changed Util.formaNum default to 6 decimails. Solved 0 decimals bug. Added tests. Can be useful for PR #5444 * Changed documentation Changed documentation to 6 instead of 5
As recommended in PR #5237. Example usage: