From 15da339bbe1b2aaaf0c02c4c7037a146b98073f3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 8 Aug 2013 16:16:59 +0200 Subject: [PATCH 1/6] Localization Support for Zoom Control --- src/control/Control.Zoom.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index afb740d1..c5b0aba7 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -4,8 +4,12 @@ L.Control.Zoom = L.Control.extend({ options: { - position: 'topleft' - }, + position: 'topleft', + zoomInText: '+', + zoomInTooltip: 'Zoom in', + zoomOutText: '-', + zoomOutTooltip: 'Zoom out' + }, onAdd: function (map) { var zoomName = 'leaflet-control-zoom', @@ -14,9 +18,9 @@ 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.zoomInTooltip, zoomName + '-in', container, this._zoomIn, this); this._zoomOutButton = this._createButton( - '-', 'Zoom out', zoomName + '-out', container, this._zoomOut, this); + this.options.zoomOutText, this.options.zoomOutTooltip, zoomName + '-out', container, this._zoomOut, this); map.on('zoomend zoomlevelschange', this._updateDisabled, this); From 4f2f1edb04b02a2efef531a77e013da74b86a10f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 8 Aug 2013 17:11:34 +0200 Subject: [PATCH 2/6] Code style adjusted for travis. --- src/control/Control.Zoom.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index c5b0aba7..0ef9ec7e 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -9,7 +9,7 @@ L.Control.Zoom = L.Control.extend({ zoomInTooltip: 'Zoom in', zoomOutText: '-', zoomOutTooltip: 'Zoom out' - }, + }, onAdd: function (map) { var zoomName = 'leaflet-control-zoom', @@ -18,9 +18,11 @@ L.Control.Zoom = L.Control.extend({ this._map = map; this._zoomInButton = this._createButton( - this.options.zoomInText, this.options.zoomInTooltip, zoomName + '-in', container, this._zoomIn, this); + this.options.zoomInText, this.options.zoomInTooltip, + zoomName + '-in', container, this._zoomIn, this); this._zoomOutButton = this._createButton( - this.options.zoomOutText, this.options.zoomOutTooltip, zoomName + '-out', container, this._zoomOut, this); + this.options.zoomOutText, this.options.zoomOutTooltip, + zoomName + '-out', container, this._zoomOut, this); map.on('zoomend zoomlevelschange', this._updateDisabled, this); From 9630876ce36ae5eba33b10f85cf2a0790129f1a7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 8 Aug 2013 17:29:09 +0200 Subject: [PATCH 3/6] Again some whitespace removing. (Travis) --- src/control/Control.Zoom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index 0ef9ec7e..656f545e 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -18,10 +18,10 @@ L.Control.Zoom = L.Control.extend({ this._map = map; this._zoomInButton = this._createButton( - this.options.zoomInText, this.options.zoomInTooltip, + this.options.zoomInText, this.options.zoomInTooltip, zoomName + '-in', container, this._zoomIn, this); this._zoomOutButton = this._createButton( - this.options.zoomOutText, this.options.zoomOutTooltip, + this.options.zoomOutText, this.options.zoomOutTooltip, zoomName + '-out', container, this._zoomOut, this); map.on('zoomend zoomlevelschange', this._updateDisabled, this); From 037048a6d08190a160a002fc04ddbf3510bc67a9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Sep 2013 02:34:41 +0200 Subject: [PATCH 4/6] Renamed Tooltip to Title --- src/control/Control.Zoom.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/control/Control.Zoom.js b/src/control/Control.Zoom.js index 656f545e..43f2404d 100644 --- a/src/control/Control.Zoom.js +++ b/src/control/Control.Zoom.js @@ -6,9 +6,9 @@ L.Control.Zoom = L.Control.extend({ options: { position: 'topleft', zoomInText: '+', - zoomInTooltip: 'Zoom in', + zoomInTitle: 'Zoom in', zoomOutText: '-', - zoomOutTooltip: 'Zoom out' + zoomOutTitle: 'Zoom out' }, onAdd: function (map) { @@ -18,10 +18,10 @@ L.Control.Zoom = L.Control.extend({ this._map = map; this._zoomInButton = this._createButton( - this.options.zoomInText, this.options.zoomInTooltip, + this.options.zoomInText, this.options.zoomInTitle, zoomName + '-in', container, this._zoomIn, this); this._zoomOutButton = this._createButton( - this.options.zoomOutText, this.options.zoomOutTooltip, + this.options.zoomOutText, this.options.zoomOutTitle, zoomName + '-out', container, this._zoomOut, this); map.on('zoomend zoomlevelschange', this._updateDisabled, this); From d10cff3357c49ed68abd51606152f2a6a423a6e6 Mon Sep 17 00:00:00 2001 From: Alexander Parshin Date: Tue, 10 Sep 2013 10:47:52 +0400 Subject: [PATCH 5/6] Fixing wrong EPGS3395 transformation --- src/geo/crs/CRS.EPSG3395.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); }()) }); From df320c3b0619245d8ad0478e76d204c2ec1efbec Mon Sep 17 00:00:00 2001 From: Alexander Parshin Date: Tue, 10 Sep 2013 11:03:59 +0400 Subject: [PATCH 6/6] Add test specifications for CRS classes. --- spec/suites/SpecHelper.js | 18 +++++++++++- spec/suites/geo/CRSSpec.js | 47 +++++++++++++++++++++++++++++++ spec/suites/geo/ProjectionSpec.js | 8 ------ 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 spec/suites/geo/CRSSpec.js 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