From 6436bf9790799073be187f1ef00b7e0fa51087cf Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 29 Mar 2018 11:55:27 -0400 Subject: [PATCH] Only allow pointer events on children of active layers. This allows multiple active layers to work together. Before, the topmost active layer will receive all pointer events. This also fixes an issue in the sceneObject exit function (it should clear the parent, not delete the parent function). This, in turn, required a fix to the annotation test because the test map is destroyed between tests. --- src/main.styl | 3 ++- src/sceneObject.js | 2 +- tests/cases/annotation.js | 4 ++++ tests/cases/widget.js | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main.styl b/src/main.styl index 5699d95c71..c424fb567a 100644 --- a/src/main.styl +++ b/src/main.styl @@ -32,7 +32,8 @@ height 100% pointer-events none &.active - pointer-events auto + > * + pointer-events auto .geo-tile-layer transform-origin 0px 0px diff --git a/src/sceneObject.js b/src/sceneObject.js index b62562a71f..eb9c3f4160 100644 --- a/src/sceneObject.js +++ b/src/sceneObject.js @@ -179,7 +179,7 @@ var sceneObject = function (arg) { */ this._exit = function () { m_children = []; - delete m_this.parent; + m_parent = null; s_exit(); }; diff --git a/tests/cases/annotation.js b/tests/cases/annotation.js index 07896f31cf..0c0cb20d95 100644 --- a/tests/cases/annotation.js +++ b/tests/cases/annotation.js @@ -151,6 +151,10 @@ describe('geo.annotation', function () { expect(ann.layer()).toBe(layer); }); it('state', function () { + map = createMap(); + layer = map.createLayer('annotation', { + annotations: geo.listAnnotations() + }); var ann = geo.annotation.annotation('test', {layer: layer}); map.geoOn(geo.event.annotation.state, function (evt) { stateEvent += 1; diff --git a/tests/cases/widget.js b/tests/cases/widget.js index 60e105aeec..63bbc8e9f1 100644 --- a/tests/cases/widget.js +++ b/tests/cases/widget.js @@ -249,4 +249,26 @@ describe('widget api', function () { domWidget._exit(); expect($(o.uiLayer.canvas()).children().length).toBe(widgetCount - 1); }); + it('widgets on two layers should both be clickable', function () { + var o = makeMap(), + offset = o.map.node().offset(), + uiLayer2 = o.map.createLayer('ui'), + clickCount = 0, clickCount2 = 0, + widget = o.uiLayer.createWidget('dom', { + position: {top: 0, left: 0, width: '20px', height: '20px'} + }), + widget2 = uiLayer2.createWidget('dom', { + position: {top: 0, left: 30, width: '20px', height: '20px'} + }); + $(widget.canvas()).on('click', function () { + clickCount += 1; + }); + $(widget2.canvas()).on('click', function () { + clickCount2 += 1; + }); + document.elementFromPoint(offset.left + 10, offset.top + 10).click(); + document.elementFromPoint(offset.left + 40, offset.top + 10).click(); + expect(clickCount).toBe(1); + expect(clickCount2).toBe(1); + }); });