fix True Mercator projection calculations, close #1578

This commit is contained in:
Vladimir Agafonkin 2013-06-24 10:42:15 -04:00
parent 35a5fdb0e5
commit 54befc9203
2 changed files with 16 additions and 7 deletions

View File

@ -16,15 +16,19 @@ describe("Projection.Mercator", function() {
});
it("projects the northeast corner of the world", function() {
expect(p.project(new L.LatLng(90, 180))).near(new L.Point(20037508.342789244, 19970326.50745906));
expect(p.project(new L.LatLng(90, 180))).near(new L.Point(20037508, 20037508));
});
it("projects the southwest corner of the world", function() {
expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-20037508, -19970326));
expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-20037508, -20037508));
});
it("projects 50, 30", function() {
expect(p.project(new L.LatLng(50, 30))).near(new L.Point(3339584, 6392021));
it("projects other points", function() {
expect(p.project(new L.LatLng(50, 30))).near(new L.Point(3339584, 6413524));
// from https://github.com/Leaflet/Leaflet/issues/1578
expect(p.project(new L.LatLng(51.9371170300465, 80.11230468750001)))
.near(new L.Point(8918060.964088084, 6755099.410887127));
});
});
@ -37,11 +41,16 @@ describe("Projection.Mercator", function() {
expect(pr(new L.Point(0, 0))).near(new L.Point(0, 0));
});
it("pi points", function() {
it("unprojects pi points", function() {
expect(pr(new L.Point(-Math.PI, Math.PI))).near(new L.Point(-Math.PI, Math.PI));
expect(pr(new L.Point(-Math.PI, -Math.PI))).near(new L.Point(-Math.PI, -Math.PI));
expect(pr(new L.Point(0.523598775598, 1.010683188683))).near(new L.Point(0.523598775598, 1.010683188683));
});
it('unprojects other points', function () {
// from https://github.com/Leaflet/Leaflet/issues/1578
expect(pr(new L.Point(8918060.964088084, 6755099.410887127)));
});
});
});

View File

@ -6,7 +6,7 @@
L.Projection.Mercator = {
MAX_LATITUDE: 85.0840591556,
R_MINOR: 6356752.3142,
R_MINOR: 6356752.314245179,
R_MAJOR: 6378137,
project: function (latlng) { // (LatLng) -> Point
@ -24,7 +24,7 @@ L.Projection.Mercator = {
con = Math.pow((1 - con) / (1 + con), eccent * 0.5);
var ts = Math.tan(0.5 * ((Math.PI * 0.5) - y)) / con;
y = -r2 * Math.log(ts);
y = -r * Math.log(ts);
return new L.Point(x, y);
},