From 39334fa95daad52b9e7a921d8aff191d4a28d435 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:24:03 +0100 Subject: [PATCH 1/5] check projection can wrap before getting width --- src/ol/coordinate.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ol/coordinate.js b/src/ol/coordinate.js index 85b31f325c..d34e8cecf9 100644 --- a/src/ol/coordinate.js +++ b/src/ol/coordinate.js @@ -410,10 +410,12 @@ export function toStringXY(coordinate, opt_fractionDigits) { * @return {Coordinate} The coordinate within the real world extent. */ export function wrapX(coordinate, projection) { - const worldWidth = getWidth(projection.getExtent()); - const worldsAway = getWorldsAway(coordinate, projection, worldWidth); - if (worldsAway) { - coordinate[0] -= worldsAway * worldWidth; + if (projection.canWrapX()) { + const worldWidth = getWidth(projection.getExtent()); + const worldsAway = getWorldsAway(coordinate, projection, worldWidth); + if (worldsAway) { + coordinate[0] -= worldsAway * worldWidth; + } } return coordinate; } From dcdaf6ddc5bf637db2510d485834a5bc9c06c13d Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 30 Jul 2020 14:15:17 +0100 Subject: [PATCH 2/5] add non-global projection wrapX text --- test/spec/ol/coordinate.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index 3cfd27d901..0b07c41956 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -1,4 +1,5 @@ import Circle from '../../../src/ol/geom/Circle.js'; +import Projection from '../../../src/ol/proj/Projection.js'; import { add as addCoordinate, closestOnCircle, @@ -271,5 +272,14 @@ describe('ol.coordinate', function () { it('moves far off right coordinate to real world', function () { expect(wrapX([1096, 48], projection)).to.eql([16, 48]); }); + + const swiss = new Projection({ + code: 'EPSG:21781', + units: 'm', + }); + + it('leaves non-global projection coordinates untouched', function () { + expect(wrapX([1096, 48], swiss)).to.eql([1096, 48]); + }); }); }); From eee7e2523c1051ebb880a32925bffa08e1b22536 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 30 Jul 2020 14:18:58 +0100 Subject: [PATCH 3/5] fix prettier --- test/spec/ol/coordinate.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index 0b07c41956..e7b2d80bd6 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -273,10 +273,7 @@ describe('ol.coordinate', function () { expect(wrapX([1096, 48], projection)).to.eql([16, 48]); }); - const swiss = new Projection({ - code: 'EPSG:21781', - units: 'm', - }); + const swiss = new Projection({code: 'EPSG:21781', units: 'm'}); it('leaves non-global projection coordinates untouched', function () { expect(wrapX([1096, 48], swiss)).to.eql([1096, 48]); From e6592c95ea81f76ad3ad3f89f3e906703fc379eb Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Thu, 30 Jul 2020 14:23:51 +0100 Subject: [PATCH 4/5] remove whitespace --- test/spec/ol/coordinate.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index e7b2d80bd6..1998097f8e 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -272,9 +272,9 @@ describe('ol.coordinate', function () { it('moves far off right coordinate to real world', function () { expect(wrapX([1096, 48], projection)).to.eql([16, 48]); }); - + const swiss = new Projection({code: 'EPSG:21781', units: 'm'}); - + it('leaves non-global projection coordinates untouched', function () { expect(wrapX([1096, 48], swiss)).to.eql([1096, 48]); }); From f9792f69a41c8d50d2096b66747a9087554cdfb5 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 30 Jul 2020 17:00:26 +0200 Subject: [PATCH 5/5] Add more tests --- test/spec/ol/renderer/map.test.js | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/spec/ol/renderer/map.test.js b/test/spec/ol/renderer/map.test.js index 4850903753..37e60a8393 100644 --- a/test/spec/ol/renderer/map.test.js +++ b/test/spec/ol/renderer/map.test.js @@ -1,6 +1,12 @@ import Disposable from '../../../../src/ol/Disposable.js'; +import Feature from '../../../../src/ol/Feature.js'; import Map from '../../../../src/ol/Map.js'; import MapRenderer from '../../../../src/ol/renderer/Map.js'; +import VectorLayer from '../../../../src/ol/layer/Vector.js'; +import VectorSource from '../../../../src/ol/source/Vector.js'; +import View from '../../../../src/ol/View.js'; +import {Point} from '../../../../src/ol/geom.js'; +import {Projection} from '../../../../src/ol/proj.js'; describe('ol.renderer.Map', function () { describe('constructor', function () { @@ -13,4 +19,46 @@ describe('ol.renderer.Map', function () { map.dispose(); }); }); + + describe('#forEachFeatureAtCoordinate', function () { + let map; + beforeEach(function () { + const target = document.createElement('div'); + target.style.width = '100px'; + target.style.height = '100px'; + document.body.appendChild(target); + const projection = new Projection({ + code: 'EPSG:21781', + units: 'm', + }); + map = new Map({ + target: target, + layers: [ + new VectorLayer({ + source: new VectorSource({ + projection: projection, + features: [new Feature(new Point([660000, 190000]))], + }), + }), + ], + view: new View({ + projection: projection, + center: [660000, 190000], + zoom: 9, + }), + }); + map.renderSync(); + }); + + afterEach(function () { + const target = map.getTargetElement(); + map.setTarget(null); + document.body.removeChild(target); + }); + + it('works with custom projection', function () { + const features = map.getFeaturesAtPixel([50, 50]); + expect(features.length).to.be(1); + }); + }); });