Add a keyboardEventTarget option to the map
This option allows specifying the element to listen to keyboard events on.
This commit is contained in:
@@ -30,6 +30,12 @@
|
|||||||
* then it gets set by using `window.devicePixelRatio`.
|
* then it gets set by using `window.devicePixelRatio`.
|
||||||
* @property {ol.Collection|Array.<ol.interaction.Interaction>|undefined} interactions
|
* @property {ol.Collection|Array.<ol.interaction.Interaction>|undefined} interactions
|
||||||
* Interactions that are initially added to the map.
|
* Interactions that are initially added to the map.
|
||||||
|
* @property {Element|Document|undefined} keyboardEventTarget The element to listen to keyboard events on.
|
||||||
|
* This determines when the `KeyboardPan` and `KeyboardZoom` interactions trigger. For example, if
|
||||||
|
* this option is set to `document` the keyboard interactions will always trigger. If this option
|
||||||
|
* is not specified, the element the library listens to keyboard events on is the map target (i.e.
|
||||||
|
* the user-provided div for the map). In that case the target element needs to be focused for key
|
||||||
|
* events to be emitted, requiring that the target element has a `tabindex` attribute.
|
||||||
* @property {Array.<ol.layer.Base>|ol.Collection|undefined} layers Layers.
|
* @property {Array.<ol.layer.Base>|ol.Collection|undefined} layers Layers.
|
||||||
* @property {boolean|undefined} ol3Logo Show ol3 logo. Default is `true`.
|
* @property {boolean|undefined} ol3Logo Show ol3 logo. Default is `true`.
|
||||||
* @property {ol.Collection|Array.<ol.Overlay>|undefined} overlays
|
* @property {ol.Collection|Array.<ol.Overlay>|undefined} overlays
|
||||||
|
|||||||
+17
-4
@@ -284,6 +284,12 @@ ol.Map = function(options) {
|
|||||||
this.handleMapBrowserEvent, false, this);
|
this.handleMapBrowserEvent, false, this);
|
||||||
this.registerDisposable(mapBrowserEventHandler);
|
this.registerDisposable(mapBrowserEventHandler);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Element|Document}
|
||||||
|
*/
|
||||||
|
this.keyboardEventTarget_ = optionsInternal.keyboardEventTarget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {goog.events.KeyHandler}
|
* @type {goog.events.KeyHandler}
|
||||||
@@ -876,10 +882,9 @@ ol.Map.prototype.handleTargetChanged_ = function() {
|
|||||||
} else {
|
} else {
|
||||||
goog.dom.appendChild(targetElement, this.viewport_);
|
goog.dom.appendChild(targetElement, this.viewport_);
|
||||||
|
|
||||||
// The key handler is attached to the user-provided target. So the key
|
var keyboardEventTarget = goog.isNull(this.keyboardEventTarget_) ?
|
||||||
// handler will only trigger events when the target element is focused
|
targetElement : this.keyboardEventTarget_;
|
||||||
// (requiring that the target element has a tabindex attribute).
|
this.keyHandler_.attach(keyboardEventTarget);
|
||||||
this.keyHandler_.attach(targetElement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
@@ -1312,6 +1317,7 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_this) {
|
|||||||
/**
|
/**
|
||||||
* @typedef {{controls: ol.Collection,
|
* @typedef {{controls: ol.Collection,
|
||||||
* interactions: ol.Collection,
|
* interactions: ol.Collection,
|
||||||
|
* keyboardEventTarget: (Element|Document),
|
||||||
* ol3Logo: boolean,
|
* ol3Logo: boolean,
|
||||||
* overlays: ol.Collection,
|
* overlays: ol.Collection,
|
||||||
* rendererConstructor:
|
* rendererConstructor:
|
||||||
@@ -1327,6 +1333,12 @@ ol.MapOptionsInternal;
|
|||||||
*/
|
*/
|
||||||
ol.Map.createOptionsInternal = function(options) {
|
ol.Map.createOptionsInternal = function(options) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Element|Document}
|
||||||
|
*/
|
||||||
|
var keyboardEventTarget = goog.isDef(options.keyboardEventTarget) ?
|
||||||
|
options.keyboardEventTarget : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, *>}
|
* @type {Object.<string, *>}
|
||||||
*/
|
*/
|
||||||
@@ -1421,6 +1433,7 @@ ol.Map.createOptionsInternal = function(options) {
|
|||||||
return {
|
return {
|
||||||
controls: controls,
|
controls: controls,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
|
keyboardEventTarget: keyboardEventTarget,
|
||||||
ol3Logo: ol3Logo,
|
ol3Logo: ol3Logo,
|
||||||
overlays: overlays,
|
overlays: overlays,
|
||||||
rendererConstructor: rendererConstructor,
|
rendererConstructor: rendererConstructor,
|
||||||
|
|||||||
Reference in New Issue
Block a user