Add a keyboardEventTarget option to the map
This option allows specifying the element to listen to keyboard events on.
This commit is contained in:
+17
-4
@@ -284,6 +284,12 @@ ol.Map = function(options) {
|
||||
this.handleMapBrowserEvent, false, this);
|
||||
this.registerDisposable(mapBrowserEventHandler);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Element|Document}
|
||||
*/
|
||||
this.keyboardEventTarget_ = optionsInternal.keyboardEventTarget;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.events.KeyHandler}
|
||||
@@ -876,10 +882,9 @@ ol.Map.prototype.handleTargetChanged_ = function() {
|
||||
} else {
|
||||
goog.dom.appendChild(targetElement, this.viewport_);
|
||||
|
||||
// The key handler is attached to the user-provided target. So the key
|
||||
// handler will only trigger events when the target element is focused
|
||||
// (requiring that the target element has a tabindex attribute).
|
||||
this.keyHandler_.attach(targetElement);
|
||||
var keyboardEventTarget = goog.isNull(this.keyboardEventTarget_) ?
|
||||
targetElement : this.keyboardEventTarget_;
|
||||
this.keyHandler_.attach(keyboardEventTarget);
|
||||
}
|
||||
|
||||
this.updateSize();
|
||||
@@ -1312,6 +1317,7 @@ ol.Map.prototype.withFrozenRendering = function(f, opt_this) {
|
||||
/**
|
||||
* @typedef {{controls: ol.Collection,
|
||||
* interactions: ol.Collection,
|
||||
* keyboardEventTarget: (Element|Document),
|
||||
* ol3Logo: boolean,
|
||||
* overlays: ol.Collection,
|
||||
* rendererConstructor:
|
||||
@@ -1327,6 +1333,12 @@ ol.MapOptionsInternal;
|
||||
*/
|
||||
ol.Map.createOptionsInternal = function(options) {
|
||||
|
||||
/**
|
||||
* @type {Element|Document}
|
||||
*/
|
||||
var keyboardEventTarget = goog.isDef(options.keyboardEventTarget) ?
|
||||
options.keyboardEventTarget : null;
|
||||
|
||||
/**
|
||||
* @type {Object.<string, *>}
|
||||
*/
|
||||
@@ -1421,6 +1433,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
return {
|
||||
controls: controls,
|
||||
interactions: interactions,
|
||||
keyboardEventTarget: keyboardEventTarget,
|
||||
ol3Logo: ol3Logo,
|
||||
overlays: overlays,
|
||||
rendererConstructor: rendererConstructor,
|
||||
|
||||
Reference in New Issue
Block a user