From fd08bdb58d61118f5cc84a524592bbd5b535919d Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 28 Mar 2023 14:15:53 -0400 Subject: [PATCH] fix: When binding an array of events, don't duplicate When we bind events from a feature to a parent layer, we were calling the geoOn or geoOff event on both the feature and layer. For arrays of events, this ended calling the layer with both the array of events and each event. --- src/pixelmapLayer.js | 4 +++- tests/gl-cases/pixelmapLayer.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pixelmapLayer.js b/src/pixelmapLayer.js index cb4c17c823..230e23d41d 100644 --- a/src/pixelmapLayer.js +++ b/src/pixelmapLayer.js @@ -120,7 +120,9 @@ var pixelmapLayer = function (arg) { ['modified', 'geoOn', 'geoOff', 'geoOnce'].forEach((funcName) => { const superFunc = m_this[funcName]; m_this[funcName] = function () { - m_pixelmapFeature[funcName].apply(this, arguments); + if (!Array.isArray(arguments[0])) { + m_pixelmapFeature[funcName].apply(this, arguments); + } return superFunc.apply(this, arguments); }; }); diff --git a/tests/gl-cases/pixelmapLayer.js b/tests/gl-cases/pixelmapLayer.js index ed17d8d9ad..0d3cd42d94 100644 --- a/tests/gl-cases/pixelmapLayer.js +++ b/tests/gl-cases/pixelmapLayer.js @@ -89,6 +89,25 @@ describe('webglPixelmapLayer', function () { done(); }); }); + it('geoOn and geoOff from array', function (done) { + createPixelmap(); + var click = 0; + layer.geoOn([geo.event.feature.mouseclick], () => { + click += 1; + }); + // wait for the tiles to be available + map.onIdle(() => { + expect(click).toEqual(0); + map.interactor().simulateEvent('mousedown', {map: {x: 390, y: 200}}); + map.interactor().simulateEvent('mouseup', {map: {x: 390, y: 200}}); + expect(click).toEqual(1); + layer.geoOff([geo.event.feature.mouseclick]); + map.interactor().simulateEvent('mousedown', {map: {x: 390, y: 200}}); + map.interactor().simulateEvent('mouseup', {map: {x: 390, y: 200}}); + expect(click).toEqual(1); + done(); + }); + }); it('geospatial', function (done) { map = geo.map({node: '#map'}); layer = map.createLayer('pixelmap', {