diff --git a/spec/suites/SpecHelper.js b/spec/suites/SpecHelper.js index 353359fc..cd867912 100644 --- a/spec/suites/SpecHelper.js +++ b/spec/suites/SpecHelper.js @@ -23,4 +23,20 @@ if (!Array.prototype.map) { return res; }; -} \ No newline at end of file +} + +expect.Assertion.prototype.near = function(expected, delta) { + delta = delta || 1; + expect(this.obj.x).to + .be.within(expected.x - delta, expected.x + delta); + expect(this.obj.y).to + .be.within(expected.y - delta, expected.y + delta); +}; + +expect.Assertion.prototype.nearLatLng = function(expected, delta) { + delta = delta || 1e-4; + expect(this.obj.lat).to + .be.within(expected.lat - delta, expected.lat + delta); + expect(this.obj.lng).to + .be.within(expected.lng - delta, expected.lng + delta); +}; \ No newline at end of file diff --git a/spec/suites/geo/CRSSpec.js b/spec/suites/geo/CRSSpec.js new file mode 100644 index 00000000..f4ef0d48 --- /dev/null +++ b/spec/suites/geo/CRSSpec.js @@ -0,0 +1,47 @@ +describe("CRS.EPSG3395", function() { + var crs = L.CRS.EPSG3395; + + describe("#latLngToPoint", function() { + it("projects a center point", function() { + expect(crs.latLngToPoint(L.latLng(0, 0), 0)).near(new L.Point(128, 128), 0.01); + }) + + it("projects the northeast corner of the world", function() { + expect(crs.latLngToPoint(L.latLng(85.0840591556, 180), 0)).near(new L.Point(256, 0)); + }); + }); + + describe("#pointToLatLng", function() { + it("reprojects a center point", function() { + expect(crs.pointToLatLng(new L.Point(128, 128), 0)).nearLatLng(L.latLng(0, 0), 0.01); + }) + + it("reprojects the northeast corner of the world", function() { + expect(crs.pointToLatLng(new L.Point(256, 0), 0)).nearLatLng(L.latLng(85.0840591556, 180)); + }); + }); +}); + +describe("CRS.EPSG3857", function() { + var crs = L.CRS.EPSG3857; + + describe("#latLngToPoint", function() { + it("projects a center point", function() { + expect(crs.latLngToPoint(L.latLng(0, 0), 0)).near(new L.Point(128, 128), 0.01); + }) + + it("projects the northeast corner of the world", function() { + expect(crs.latLngToPoint(L.latLng(85.0511287798, 180), 0)).near(new L.Point(256, 0)); + }); + }); + + describe("#pointToLatLng", function() { + it("reprojects a center point", function() { + expect(crs.pointToLatLng(new L.Point(128, 128), 0)).nearLatLng(L.latLng(0, 0), 0.01); + }) + + it("reprojects the northeast corner of the world", function() { + expect(crs.pointToLatLng(new L.Point(256, 0), 0)).nearLatLng(L.latLng(85.0511287798, 180)); + }); + }); +}); \ No newline at end of file diff --git a/spec/suites/geo/ProjectionSpec.js b/spec/suites/geo/ProjectionSpec.js index 2414bfa5..e2ff5474 100644 --- a/spec/suites/geo/ProjectionSpec.js +++ b/spec/suites/geo/ProjectionSpec.js @@ -1,14 +1,6 @@ describe("Projection.Mercator", function() { var p = L.Projection.Mercator; - expect.Assertion.prototype.near = function(expected, delta) { - delta = delta || 1; - expect(this.obj.x).to - .be.within(expected.x - delta, expected.x + delta); - expect(this.obj.y).to - .be.within(expected.y - delta, expected.y + delta); - }; - describe("#project", function() { it("projects a center point", function() { //edge cases diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index afb740d1..43f2404d 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -4,7 +4,11 @@ L.Control.Zoom = L.Control.extend({ options: { - position: 'topleft' + position: 'topleft', + zoomInText: '+', + zoomInTitle: 'Zoom in', + zoomOutText: '-', + zoomOutTitle: 'Zoom out' }, onAdd: function (map) { @@ -14,9 +18,11 @@ L.Control.Zoom = L.Control.extend({ this._map = map; this._zoomInButton = this._createButton( - '+', 'Zoom in', zoomName + '-in', container, this._zoomIn, this); + this.options.zoomInText, this.options.zoomInTitle, + zoomName + '-in', container, this._zoomIn, this); this._zoomOutButton = this._createButton( - '-', 'Zoom out', zoomName + '-out', container, this._zoomOut, this); + this.options.zoomOutText, this.options.zoomOutTitle, + zoomName + '-out', container, this._zoomOut, this); map.on('zoomend zoomlevelschange', this._updateDisabled, this); diff --git a/src/geo/crs/CRS.EPSG3395.js b/src/geo/crs/CRS.EPSG3395.js index ed03562b..786dec91 100644 --- a/src/geo/crs/CRS.EPSG3395.js +++ b/src/geo/crs/CRS.EPSG3395.js @@ -7,8 +7,8 @@ L.CRS.EPSG3395 = L.extend({}, L.CRS, { transformation: (function () { var m = L.Projection.Mercator, r = m.R_MAJOR, - r2 = m.R_MINOR; + scale = 0.5 / (Math.PI * r); - return new L.Transformation(0.5 / (Math.PI * r), 0.5, -0.5 / (Math.PI * r2), 0.5); + return new L.Transformation(scale, 0.5, -scale, 0.5); }()) });