Merge pull request #10502 from walkermatt/stopevent-removed-target
Stop events that originate with a removed target
This commit is contained in:
@@ -932,13 +932,15 @@ class PluggableMap extends BaseObject {
|
|||||||
// coordinates so interactions cannot be used.
|
// coordinates so interactions cannot be used.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let target = /** @type {Node} */ (mapBrowserEvent.originalEvent.target);
|
const target = /** @type {Node} */ (mapBrowserEvent.originalEvent.target);
|
||||||
if (!mapBrowserEvent.dragging) {
|
if (!mapBrowserEvent.dragging) {
|
||||||
while (target && target !== this.viewport_) {
|
if (this.overlayContainerStopEvent_.contains(target) || !document.body.contains(target)) {
|
||||||
if (target.parentElement === this.overlayContainerStopEvent_) {
|
// Abort if the event target is a child of the container that doesn't allow
|
||||||
return;
|
// event propagation or is no longer in the page. It's possible for the target to no longer
|
||||||
}
|
// be in the page if it has been removed in an event listener, this might happen in a Control
|
||||||
target = target.parentElement;
|
// that recreates it's content based on user interaction either manually or via a render
|
||||||
|
// in something like https://reactjs.org/
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mapBrowserEvent.frameState = this.frameState_;
|
mapBrowserEvent.frameState = this.frameState_;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import Polygon from '../../../../src/ol/geom/Polygon.js';
|
|||||||
import Draw, {createRegularPolygon, createBox} from '../../../../src/ol/interaction/Draw.js';
|
import Draw, {createRegularPolygon, createBox} from '../../../../src/ol/interaction/Draw.js';
|
||||||
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
import Interaction from '../../../../src/ol/interaction/Interaction.js';
|
||||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||||
import Event from '../../../../src/ol/events/Event.js';
|
|
||||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||||
import {clearUserProjection, setUserProjection, transform} from '../../../../src/ol/proj.js';
|
import {clearUserProjection, setUserProjection, transform} from '../../../../src/ol/proj.js';
|
||||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||||
@@ -73,8 +72,9 @@ describe('ol.interaction.Draw', function() {
|
|||||||
// calculated in case body has top < 0 (test runner with small window)
|
// calculated in case body has top < 0 (test runner with small window)
|
||||||
const position = viewport.getBoundingClientRect();
|
const position = viewport.getBoundingClientRect();
|
||||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||||
const event = new Event();
|
const event = {};
|
||||||
event.type = type;
|
event.type = type;
|
||||||
|
event.target = viewport.firstChild;
|
||||||
event.clientX = position.left + x + width / 2;
|
event.clientX = position.left + x + width / 2;
|
||||||
event.clientY = position.top + y + height / 2;
|
event.clientY = position.top + y + height / 2;
|
||||||
event.shiftKey = shiftKey;
|
event.shiftKey = shiftKey;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js';
|
|||||||
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
|
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
|
||||||
import View from '../../../../src/ol/View.js';
|
import View from '../../../../src/ol/View.js';
|
||||||
import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
|
import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
|
||||||
import Event from '../../../../src/ol/events/Event.js';
|
|
||||||
|
|
||||||
describe('ol.interaction.Extent', function() {
|
describe('ol.interaction.Extent', function() {
|
||||||
let map, interaction;
|
let map, interaction;
|
||||||
@@ -50,8 +49,9 @@ describe('ol.interaction.Extent', function() {
|
|||||||
// calculated in case body has top < 0 (test runner with small window)
|
// calculated in case body has top < 0 (test runner with small window)
|
||||||
const position = viewport.getBoundingClientRect();
|
const position = viewport.getBoundingClientRect();
|
||||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||||
const pointerEvent = new Event();
|
const pointerEvent = {};
|
||||||
pointerEvent.type = type;
|
pointerEvent.type = type;
|
||||||
|
pointerEvent.target = viewport.firstChild;
|
||||||
pointerEvent.button = button;
|
pointerEvent.button = button;
|
||||||
pointerEvent.clientX = position.left + x + width / 2;
|
pointerEvent.clientX = position.left + x + width / 2;
|
||||||
pointerEvent.clientY = position.top - y + height / 2;
|
pointerEvent.clientY = position.top - y + height / 2;
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ describe('ol.interaction.Modify', function() {
|
|||||||
const position = viewport.getBoundingClientRect();
|
const position = viewport.getBoundingClientRect();
|
||||||
const pointerEvent = new Event();
|
const pointerEvent = new Event();
|
||||||
pointerEvent.type = type;
|
pointerEvent.type = type;
|
||||||
|
pointerEvent.target = viewport.firstChild;
|
||||||
pointerEvent.clientX = position.left + x + width / 2;
|
pointerEvent.clientX = position.left + x + width / 2;
|
||||||
pointerEvent.clientY = position.top + y + height / 2;
|
pointerEvent.clientY = position.top + y + height / 2;
|
||||||
pointerEvent.shiftKey = modifiers.shift || false;
|
pointerEvent.shiftKey = modifiers.shift || false;
|
||||||
|
|||||||
@@ -91,11 +91,13 @@ describe('ol.interaction.Select', function() {
|
|||||||
// calculated in case body has top < 0 (test runner with small window)
|
// calculated in case body has top < 0 (test runner with small window)
|
||||||
const position = viewport.getBoundingClientRect();
|
const position = viewport.getBoundingClientRect();
|
||||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||||
const event = new PointerEvent(type, {
|
const event = {
|
||||||
|
type: type,
|
||||||
|
target: viewport.firstChild,
|
||||||
clientX: position.left + x + width / 2,
|
clientX: position.left + x + width / 2,
|
||||||
clientY: position.top + y + height / 2,
|
clientY: position.top + y + height / 2,
|
||||||
shiftKey: shiftKey
|
shiftKey: shiftKey
|
||||||
});
|
};
|
||||||
map.handleMapBrowserEvent(new MapBrowserPointerEvent(type, map, event));
|
map.handleMapBrowserEvent(new MapBrowserPointerEvent(type, map, event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,13 +65,15 @@ describe('ol.interaction.Translate', function() {
|
|||||||
// calculated in case body has top < 0 (test runner with small window)
|
// calculated in case body has top < 0 (test runner with small window)
|
||||||
const position = viewport.getBoundingClientRect();
|
const position = viewport.getBoundingClientRect();
|
||||||
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
const shiftKey = opt_shiftKey !== undefined ? opt_shiftKey : false;
|
||||||
const event = new MapBrowserPointerEvent(type, map,
|
const event = new MapBrowserPointerEvent(type, map, {
|
||||||
new PointerEvent(type, {
|
type: type,
|
||||||
clientX: position.left + x + width / 2,
|
target: viewport.firstChild,
|
||||||
clientY: position.top + y + height / 2,
|
pointerId: 0,
|
||||||
shiftKey: shiftKey,
|
clientX: position.left + x + width / 2,
|
||||||
preventDefault: function() {}
|
clientY: position.top + y + height / 2,
|
||||||
}));
|
shiftKey: shiftKey,
|
||||||
|
preventDefault: function() {}
|
||||||
|
});
|
||||||
map.handleMapBrowserEvent(event);
|
map.handleMapBrowserEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user