Checks before calling handleEvent on interactions
This commit is contained in:
@@ -1026,7 +1026,11 @@ class PluggableMap extends BaseObject {
|
|||||||
const interactionsArray = this.getInteractions().getArray().slice();
|
const interactionsArray = this.getInteractions().getArray().slice();
|
||||||
for (let i = interactionsArray.length - 1; i >= 0; i--) {
|
for (let i = interactionsArray.length - 1; i >= 0; i--) {
|
||||||
const interaction = interactionsArray[i];
|
const interaction = interactionsArray[i];
|
||||||
if (!interaction.getActive()) {
|
if (
|
||||||
|
interaction.getMap() !== this ||
|
||||||
|
!interaction.getActive() ||
|
||||||
|
!this.getTargetElement()
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const cont = interaction.handleEvent(mapBrowserEvent);
|
const cont = interaction.handleEvent(mapBrowserEvent);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import ImageState from '../../../src/ol/ImageState.js';
|
|||||||
import ImageStatic from '../../../src/ol/source/ImageStatic.js';
|
import ImageStatic from '../../../src/ol/source/ImageStatic.js';
|
||||||
import Interaction from '../../../src/ol/interaction/Interaction.js';
|
import Interaction from '../../../src/ol/interaction/Interaction.js';
|
||||||
import Map from '../../../src/ol/Map.js';
|
import Map from '../../../src/ol/Map.js';
|
||||||
|
import MapBrowserEvent from '../../../src/ol/MapBrowserEvent.js';
|
||||||
import MapEvent from '../../../src/ol/MapEvent.js';
|
import MapEvent from '../../../src/ol/MapEvent.js';
|
||||||
import MouseWheelZoom from '../../../src/ol/interaction/MouseWheelZoom.js';
|
import MouseWheelZoom from '../../../src/ol/interaction/MouseWheelZoom.js';
|
||||||
import Overlay from '../../../src/ol/Overlay.js';
|
import Overlay from '../../../src/ol/Overlay.js';
|
||||||
@@ -1023,4 +1024,74 @@ describe('ol.Map', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#handleMapBrowserEvent()', function () {
|
||||||
|
let map, target, dragpan;
|
||||||
|
beforeEach(function () {
|
||||||
|
target = document.createElement('div');
|
||||||
|
target.style.width = '100px';
|
||||||
|
target.style.height = '100px';
|
||||||
|
document.body.appendChild(target);
|
||||||
|
dragpan = new DragPan();
|
||||||
|
map = new Map({
|
||||||
|
target: target,
|
||||||
|
interactions: [dragpan],
|
||||||
|
layers: [
|
||||||
|
new TileLayer({
|
||||||
|
source: new XYZ({
|
||||||
|
url: 'spec/ol/data/osm-{z}-{x}-{y}.png',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
view: new View({
|
||||||
|
zoom: 0,
|
||||||
|
center: [0, 0],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
map.renderSync();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
map.setTarget(null);
|
||||||
|
document.body.removeChild(target);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls handleEvent on interaction', function () {
|
||||||
|
const spy = sinon.spy(dragpan, 'handleEvent');
|
||||||
|
map.handleMapBrowserEvent(
|
||||||
|
new MapBrowserEvent('pointermove', map, new PointerEvent('pointermove'))
|
||||||
|
);
|
||||||
|
expect(spy.callCount).to.be(1);
|
||||||
|
spy.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not call handleEvent on interaction when map has no target', function () {
|
||||||
|
map.setTarget(null);
|
||||||
|
const spy = sinon.spy(dragpan, 'handleEvent');
|
||||||
|
map.handleMapBrowserEvent(
|
||||||
|
new MapBrowserEvent('pointermove', map, new PointerEvent('pointermove'))
|
||||||
|
);
|
||||||
|
expect(spy.callCount).to.be(0);
|
||||||
|
spy.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not call handleEvent on interaction that has been removed', function () {
|
||||||
|
const spy = sinon.spy(dragpan, 'handleEvent');
|
||||||
|
let callCount = 0;
|
||||||
|
const interaction = new Interaction({
|
||||||
|
handleEvent: function () {
|
||||||
|
++callCount;
|
||||||
|
map.removeInteraction(dragpan);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
map.addInteraction(interaction);
|
||||||
|
map.handleMapBrowserEvent(
|
||||||
|
new MapBrowserEvent('pointermove', map, new PointerEvent('pointermove'))
|
||||||
|
);
|
||||||
|
expect(callCount).to.be(1);
|
||||||
|
expect(spy.callCount).to.be(0);
|
||||||
|
spy.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user