From c15aa414bd8d1b3068cc69e42a40eb4af03dce21 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 6 Sep 2017 07:33:07 +0200 Subject: [PATCH 1/3] Fix hit detection for image layers --- src/ol/renderer/canvas/imagelayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/renderer/canvas/imagelayer.js b/src/ol/renderer/canvas/imagelayer.js index 43b0b015c3..878846926c 100644 --- a/src/ol/renderer/canvas/imagelayer.js +++ b/src/ol/renderer/canvas/imagelayer.js @@ -136,7 +136,7 @@ ol.renderer.canvas.ImageLayer.prototype.prepareFrame = function(frameState, laye this.updateAttributions(frameState.attributions, image.getAttributions()); this.updateLogos(frameState, imageSource); - this.renderedResolution = viewResolution * pixelRatio / imagePixelRatio; + this.renderedResolution = imageResolution * pixelRatio / imagePixelRatio; } return !!this.image_; From e1783fc7880986894618afd59e42fa28c6eaf2e4 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 6 Sep 2017 10:02:15 +0200 Subject: [PATCH 2/3] Fix travis build --- test/spec/ol/interaction/snap.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/spec/ol/interaction/snap.test.js b/test/spec/ol/interaction/snap.test.js index 4d663b8b2d..d87c319ec0 100644 --- a/test/spec/ol/interaction/snap.test.js +++ b/test/spec/ol/interaction/snap.test.js @@ -125,10 +125,8 @@ describe('ol.interaction.Snap', function() { }; ol.interaction.Snap.handleEvent_.call(snapInteraction, event); - expect(event.coordinate).to.eql([ - Math.sin(Math.PI / 4) * 10, - Math.sin(Math.PI / 4) * 10 - ]); + expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); + expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); }); it('handle feature without geometry', function() { From 531115b67ba583a82949a3672788d811f53355af Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 6 Sep 2017 18:25:31 +0200 Subject: [PATCH 3/3] Add regression test --- test/spec/ol/data/dot.png | Bin 0 -> 478 bytes .../ol/renderer/canvas/imagelayer.test.js | 65 ++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/spec/ol/data/dot.png create mode 100644 test/spec/ol/renderer/canvas/imagelayer.test.js diff --git a/test/spec/ol/data/dot.png b/test/spec/ol/data/dot.png new file mode 100644 index 0000000000000000000000000000000000000000..d5337830174e23fbc5bf61084fb75aebff7a7caa GIT binary patch literal 478 zcmV<40U`d0P)ZB7*1QC%0 z8-QQwdl9$>9)OK8MpyH;}|bBj$>?^ zCR%G_S(XAkrPx)})iRefj$^FrI%oL+aGO#!N-0%U6~-7oDq~C@ zn#%UdK&6y=v&==;|BX`__^Gy%9U&w#Ty0VD&xh=_9z@BN2i-g}&Ld3!t{**4#R zm53On6sy&WqA1?Ytm`^hLznZ-Fp04X?+ZN~C971>o+HC4iKMr4hzP{wZ{?{+yHxTAM U=CW(blmGw#07*qoM6N<$f=cV!Qvd(} literal 0 HcmV?d00001 diff --git a/test/spec/ol/renderer/canvas/imagelayer.test.js b/test/spec/ol/renderer/canvas/imagelayer.test.js new file mode 100644 index 0000000000..943fe7f609 --- /dev/null +++ b/test/spec/ol/renderer/canvas/imagelayer.test.js @@ -0,0 +1,65 @@ +goog.require('ol.Map'); +goog.require('ol.View'); +goog.require('ol.layer.Image'); +goog.require('ol.proj.Projection'); +goog.require('ol.source.ImageStatic'); + + +describe('ol.renderer.canvas.ImageLayer', function() { + + describe('#forEachLayerAtCoordinate', function() { + + var map, target, source; + beforeEach(function(done) { + var projection = new ol.proj.Projection({ + code: 'custom-image', + units: 'pixels', + extent: [0, 0, 200, 200] + }); + target = document.createElement('div'); + target.style.width = '100px'; + target.style.height = '100px'; + document.body.appendChild(target); + source = new ol.source.ImageStatic({ + url: 'spec/ol/data/dot.png', + projection: projection, + imageExtent: [0, 0, 20, 20] + }); + map = new ol.Map({ + pixelRatio: 1, + target: target, + layers: [new ol.layer.Image({ + source: source + })], + view: new ol.View({ + projection: projection, + center: [10, 10], + zoom: 2, + maxZoom: 8 + }) + }); + source.on('imageloadend', function() { + done(); + }); + }); + + afterEach(function() { + map.setTarget(null); + document.body.removeChild(target); + }); + + it('properly detects pixels', function() { + map.renderSync(); + var has = false; + function hasLayer() { + has = true; + } + map.forEachLayerAtPixel([20, 80], hasLayer); + expect(has).to.be(true); + has = false; + map.forEachLayerAtPixel([10, 90], hasLayer); + expect(has).to.be(false); + }); + }); + +});