Merge pull request #11613 from elnabo/main

Allow mouse input if map is rendered in an other window
This commit is contained in:
Olivier Guyot
2020-10-02 10:59:50 +02:00
committed by GitHub
3 changed files with 20 additions and 18 deletions
+4 -11
View File
@@ -239,19 +239,15 @@ class MapBrowserEventHandler extends EventTarget {
this.down_ = pointerEvent; this.down_ = pointerEvent;
if (this.dragListenerKeys_.length === 0) { if (this.dragListenerKeys_.length === 0) {
const doc = this.map_.getOwnerDocument();
this.dragListenerKeys_.push( this.dragListenerKeys_.push(
listen( listen(
document, doc,
MapBrowserEventType.POINTERMOVE, MapBrowserEventType.POINTERMOVE,
this.handlePointerMove_, this.handlePointerMove_,
this this
), ),
listen( listen(doc, MapBrowserEventType.POINTERUP, this.handlePointerUp_, this),
document,
MapBrowserEventType.POINTERUP,
this.handlePointerUp_,
this
),
/* Note that the listener for `pointercancel is set up on /* Note that the listener for `pointercancel is set up on
* `pointerEventHandler_` and not `documentPointerEventHandler_` like * `pointerEventHandler_` and not `documentPointerEventHandler_` like
* the `pointerup` and `pointermove` listeners. * the `pointerup` and `pointermove` listeners.
@@ -272,10 +268,7 @@ class MapBrowserEventHandler extends EventTarget {
this this
) )
); );
if ( if (this.element_.getRootNode && this.element_.getRootNode() !== doc) {
this.element_.getRootNode &&
this.element_.getRootNode() !== document
) {
this.dragListenerKeys_.push( this.dragListenerKeys_.push(
listen( listen(
this.element_.getRootNode(), this.element_.getRootNode(),
+13 -5
View File
@@ -130,7 +130,7 @@ import {removeNode} from './dom.js';
* @property {HTMLElement|string} [target] The container for the map, either the * @property {HTMLElement|string} [target] The container for the map, either the
* element itself or the `id` of the element. If not specified at construction * element itself or the `id` of the element. If not specified at construction
* time, {@link module:ol/Map~Map#setTarget} must be called for the map to be * time, {@link module:ol/Map~Map#setTarget} must be called for the map to be
* rendered. * rendered. If passed by element, the container can be in a secondary document.
* @property {View} [view] The map's view. No layer sources will be * @property {View} [view] The map's view. No layer sources will be
* fetched unless this is specified at construction time or through * fetched unless this is specified at construction time or through
* {@link module:ol/Map~Map#setView}. * {@link module:ol/Map~Map#setView}.
@@ -953,6 +953,15 @@ class PluggableMap extends BaseObject {
return this.overlayContainerStopEvent_; return this.overlayContainerStopEvent_;
} }
/**
* @return {!Document} The document where the map is displayed.
*/
getOwnerDocument() {
return this.getTargetElement()
? this.getTargetElement().ownerDocument
: document;
}
/** /**
* @param {import("./Tile.js").default} tile Tile. * @param {import("./Tile.js").default} tile Tile.
* @param {string} tileSourceKey Tile source key. * @param {string} tileSourceKey Tile source key.
@@ -996,9 +1005,10 @@ class PluggableMap extends BaseObject {
eventType === EventType.WHEEL || eventType === EventType.WHEEL ||
eventType === EventType.KEYDOWN eventType === EventType.KEYDOWN
) { ) {
const doc = this.getOwnerDocument();
const rootNode = this.viewport_.getRootNode const rootNode = this.viewport_.getRootNode
? this.viewport_.getRootNode() ? this.viewport_.getRootNode()
: document; : doc;
const target = const target =
'host' in rootNode // ShadowRoot 'host' in rootNode // ShadowRoot
? /** @type {ShadowRoot} */ (rootNode).elementFromPoint( ? /** @type {ShadowRoot} */ (rootNode).elementFromPoint(
@@ -1014,9 +1024,7 @@ class PluggableMap extends BaseObject {
// It's possible for the target to no longer be in the page if it has been removed in an // 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 that recreates it's content based on // event listener, this might happen in a Control that recreates it's content based on
// user interaction either manually or via a render in something like https://reactjs.org/ // user interaction either manually or via a render in something like https://reactjs.org/
!(rootNode === document ? document.documentElement : rootNode).contains( !(rootNode === doc ? doc.documentElement : rootNode).contains(target)
target
)
) { ) {
return; return;
} }
+3 -2
View File
@@ -250,9 +250,10 @@ class ZoomSlider extends Control {
if (this.dragListenerKeys_.length === 0) { if (this.dragListenerKeys_.length === 0) {
const drag = this.handleDraggerDrag_; const drag = this.handleDraggerDrag_;
const end = this.handleDraggerEnd_; const end = this.handleDraggerEnd_;
const doc = this.getMap().getOwnerDocument();
this.dragListenerKeys_.push( this.dragListenerKeys_.push(
listen(document, PointerEventType.POINTERMOVE, drag, this), listen(doc, PointerEventType.POINTERMOVE, drag, this),
listen(document, PointerEventType.POINTERUP, end, this) listen(doc, PointerEventType.POINTERUP, end, this)
); );
} }
} }