Monday 3 February 2020

leaflet - Why doesn't LeafletJS complete the conversion when re-projecting to Spherical Mercator?


When I use the Mapbox Leaflet pre-packaged Projection class SphericalMercator to project a lat/long coordinate into EPSG:3857 I have to multiply the result Leaflet provides by the earth's radius.


var latlng = L.latLng(45, -120);
var sphericalMercator = L.Projection.SphericalMercator.project(latlng);

The following is what Leaflet returns:


sperhicalMercator.x => -2.0943951023931953
sphericalMercator.y => 0.8813735870195429

But the actual answer is (-13358338.8952, 5621521.48619), which I got by multiplying the results returned by Leaflet by 6,378,137 (earth's radius in meters).



var actualAnswerX = sphericalMercator.x * 6378137;
var actualAnswerY = sphericalMercator.y * 6378137;

Am I missing something?



Answer



This has been fixed in Leaflet after the 0.7.2 release.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...