Skip to content

Commit

Permalink
Only allow pointer events on children of active layers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
manthey committed Mar 29, 2018
1 parent 893ea91 commit 6436bf9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main.styl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
height 100%
pointer-events none
&.active
pointer-events auto
> *
pointer-events auto

.geo-tile-layer
transform-origin 0px 0px
Expand Down
2 changes: 1 addition & 1 deletion src/sceneObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var sceneObject = function (arg) {
*/
this._exit = function () {
m_children = [];
delete m_this.parent;
m_parent = null;
s_exit();
};

Expand Down
4 changes: 4 additions & 0 deletions tests/cases/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions tests/cases/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 6436bf9

Please sign in to comment.