Skip to content

Commit

Permalink
fix: When binding an array of events, don't duplicate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
manthey committed Mar 28, 2023
1 parent 3447174 commit fd08bdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pixelmapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
});
Expand Down
19 changes: 19 additions & 0 deletions tests/gl-cases/pixelmapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit fd08bdb

Please sign in to comment.