Repository navigation
Add precision parameter to all toGeoJSON functions - #5444
Conversation
perliedman
left a comment
There was a problem hiding this comment.
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
toGeoJSONwill 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. |
| // Reverse of [`coordsToLatLng`](#geojson-coordstolatlng) | ||
| export function latLngToCoords(latlng) { | ||
| export function latLngToCoords(latlng, precision) { | ||
| precision = precision || 6; |
There was a problem hiding this comment.
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.
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.
perliedman
left a comment
There was a problem hiding this comment.
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: