From 321c65b02312dac62f1fc78a1f25b789dfd3217e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 5 Oct 2016 07:26:41 -0600 Subject: [PATCH 1/3] Keep transformed coordinates within valid y range --- src/ol/proj/epsg3857.js | 8 ++++++- test/spec/ol/proj/epsg3857.test.js | 35 +++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/ol/proj/epsg3857.js b/src/ol/proj/epsg3857.js index 16dfe11d98..189b770e64 100644 --- a/src/ol/proj/epsg3857.js +++ b/src/ol/proj/epsg3857.js @@ -118,8 +118,14 @@ ol.proj.EPSG3857.fromEPSG4326 = function(input, opt_output, opt_dimension) { 'modulus of output.length with dimension should be 0'); for (var i = 0; i < length; i += dimension) { output[i] = ol.proj.EPSG3857.RADIUS * Math.PI * input[i] / 180; - output[i + 1] = ol.proj.EPSG3857.RADIUS * + var y = ol.proj.EPSG3857.RADIUS * Math.log(Math.tan(Math.PI * (input[i + 1] + 90) / 360)); + if (y > ol.proj.EPSG3857.HALF_SIZE) { + y = ol.proj.EPSG3857.HALF_SIZE; + } else if (y < -ol.proj.EPSG3857.HALF_SIZE) { + y = -ol.proj.EPSG3857.HALF_SIZE; + } + output[i + 1] = y; } return output; }; diff --git a/test/spec/ol/proj/epsg3857.test.js b/test/spec/ol/proj/epsg3857.test.js index 9854d96c20..2402b2854e 100644 --- a/test/spec/ol/proj/epsg3857.test.js +++ b/test/spec/ol/proj/epsg3857.test.js @@ -2,6 +2,7 @@ goog.provide('ol.test.proj.EPSG3857'); goog.require('ol.proj'); goog.require('ol.proj.common'); + describe('ol.proj.EPSG3857', function() { afterEach(function() { @@ -9,6 +10,38 @@ describe('ol.proj.EPSG3857', function() { ol.proj.common.add(); }); + describe('fromEPSG4326()', function() { + + it('transforms from geographic to Web Mercator', function() { + var forward = ol.proj.EPSG3857.fromEPSG4326; + var edge = ol.proj.EPSG3857.HALF_SIZE; + + var tolerance = 1e-5; + + var cases = [{ + g: [0, 0], + m: [0, 0] + }, { + g: [-180, -90], + m: [-edge, -edge] + }, { + g: [180, 90], + m: [edge, edge] + }, { + g: [-111.0429, 45.6770], + m: [-12361239.084208, 5728738.469095] + }]; + + for (var i = 0, ii = cases.length; i < ii; ++i) { + var point = cases[i].g; + var transformed = forward(point); + expect(transformed[0]).to.roughlyEqual(cases[i].m[0], tolerance); + expect(transformed[1]).to.roughlyEqual(cases[i].m[1], tolerance); + } + }); + + }); + describe('getPointResolution', function() { it('returns the correct point scale at the equator', function() { @@ -37,7 +70,7 @@ describe('ol.proj.EPSG3857', function() { var epsg4326 = ol.proj.get('EPSG:4326'); var resolution = 19.11; var latitude; - for (latitude = 0; latitude < 90; ++latitude) { + for (latitude = 0; latitude <= 85; ++latitude) { var point = ol.proj.transform([0, latitude], epsg4326, epsg3857); expect(epsg3857.getPointResolution(resolution, point)). to.roughlyEqual(19.11 * Math.cos(Math.PI * latitude / 180), 1e-9); From 8ac6c85f0f7306bb2ffee0a48642293a04a3b25d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 5 Oct 2016 08:23:41 -0600 Subject: [PATCH 2/3] Reuse half size --- src/ol/proj/epsg3857.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ol/proj/epsg3857.js b/src/ol/proj/epsg3857.js index 189b770e64..09864be283 100644 --- a/src/ol/proj/epsg3857.js +++ b/src/ol/proj/epsg3857.js @@ -116,14 +116,15 @@ ol.proj.EPSG3857.fromEPSG4326 = function(input, opt_output, opt_dimension) { } ol.DEBUG && console.assert(output.length % dimension === 0, 'modulus of output.length with dimension should be 0'); + var halfSize = ol.proj.EPSG3857.HALF_SIZE; for (var i = 0; i < length; i += dimension) { - output[i] = ol.proj.EPSG3857.RADIUS * Math.PI * input[i] / 180; + output[i] = halfSize * input[i] / 180; var y = ol.proj.EPSG3857.RADIUS * Math.log(Math.tan(Math.PI * (input[i + 1] + 90) / 360)); - if (y > ol.proj.EPSG3857.HALF_SIZE) { - y = ol.proj.EPSG3857.HALF_SIZE; - } else if (y < -ol.proj.EPSG3857.HALF_SIZE) { - y = -ol.proj.EPSG3857.HALF_SIZE; + if (y > halfSize) { + y = halfSize; + } else if (y < -halfSize) { + y = -halfSize; } output[i + 1] = y; } @@ -154,7 +155,7 @@ ol.proj.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) { ol.DEBUG && console.assert(output.length % dimension === 0, 'modulus of output.length with dimension should be 0'); for (var i = 0; i < length; i += dimension) { - output[i] = 180 * input[i] / (ol.proj.EPSG3857.RADIUS * Math.PI); + output[i] = 180 * input[i] / ol.proj.EPSG3857.HALF_SIZE; output[i + 1] = 360 * Math.atan( Math.exp(input[i + 1] / ol.proj.EPSG3857.RADIUS)) / Math.PI - 90; } From 7cf1e74ae36d65f73677e29b2a1150763198165f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 6 Oct 2016 20:48:58 -0600 Subject: [PATCH 3/3] Integration test for rendering a world spanning polygon --- .../spec/ol/layer/expected/inverted-star.png | Bin 0 -> 1683 bytes test_rendering/spec/ol/layer/vector.test.js | 59 ++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test_rendering/spec/ol/layer/expected/inverted-star.png diff --git a/test_rendering/spec/ol/layer/expected/inverted-star.png b/test_rendering/spec/ol/layer/expected/inverted-star.png new file mode 100644 index 0000000000000000000000000000000000000000..07399ffcb4afc61779726dc0a99d9907d6e23f42 GIT binary patch literal 1683 zcmc(g>sM0;7RArKc@Tj>Qb05*a~!jqlN0^g5v~Vo}%9#3$ck6v%8@>EZ~v zZ`>hN&jA|jWV}2jTS98B8G zpot!k++{g6+tnt7h^SU)`fXtvR+o!=Y7ztAGOzDi(iAd9hR;k#Mj>PvcZF;F%&nz= zZX5KNMhOy@*pZePSn7J;OCbf3-&EZO%g%I8;!P4neP`M0FVe7$K%`;^n)m$nx0#O) z_?9~n7e;;FKoB!SOxk5m}zn@E_%eo_(7a+*qG8#&JU0d`QU=>)HP%(^e z1m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