Allow interactions to deal directly with browser events
The relayEvent_ method wraps goog's browser events in our MapBrowserEvent. This allows interactions to deal with real browser events in addition to our emulated events.
This commit is contained in:
@@ -160,6 +160,15 @@ ol.MapBrowserEventHandler = function(map) {
|
|||||||
|
|
||||||
var element = this.map_.getViewport();
|
var element = this.map_.getViewport();
|
||||||
|
|
||||||
|
this.relayedListenerKeys_ = [
|
||||||
|
goog.events.listen(element,
|
||||||
|
goog.events.EventType.MOUSEMOVE,
|
||||||
|
this.relayEvent_, false, this),
|
||||||
|
goog.events.listen(element,
|
||||||
|
goog.events.EventType.CLICK,
|
||||||
|
this.relayEvent_, false, this)
|
||||||
|
];
|
||||||
|
|
||||||
this.mousedownListenerKey_ = goog.events.listen(element,
|
this.mousedownListenerKey_ = goog.events.listen(element,
|
||||||
goog.events.EventType.MOUSEDOWN,
|
goog.events.EventType.MOUSEDOWN,
|
||||||
this.handleMouseDown_, false, this);
|
this.handleMouseDown_, false, this);
|
||||||
@@ -402,6 +411,10 @@ ol.MapBrowserEventHandler.prototype.handleTouchEnd_ = function(browserEvent) {
|
|||||||
* FIXME empty description for jsdoc
|
* FIXME empty description for jsdoc
|
||||||
*/
|
*/
|
||||||
ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
|
ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
|
||||||
|
if (!goog.isNull(this.relayedListenerKeys_)) {
|
||||||
|
goog.array.forEach(this.relayedListenerKeys_, goog.events.unlistenByKey);
|
||||||
|
this.relayedListenerKeys_ = null;
|
||||||
|
}
|
||||||
if (!goog.isNull(this.mousedownListenerKey_)) {
|
if (!goog.isNull(this.mousedownListenerKey_)) {
|
||||||
goog.events.unlistenByKey(this.mousedownListenerKey_);
|
goog.events.unlistenByKey(this.mousedownListenerKey_);
|
||||||
this.mousedownListenerKey_ = null;
|
this.mousedownListenerKey_ = null;
|
||||||
@@ -422,12 +435,26 @@ ol.MapBrowserEventHandler.prototype.disposeInternal = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap and relay a browser event. Note that this requires that the type
|
||||||
|
* string for the MapBrowserEvent matches the BrowserEvent type.
|
||||||
|
* @param {goog.events.BrowserEvent} browserEvent Browser event.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.MapBrowserEventHandler.prototype.relayEvent_ = function(browserEvent) {
|
||||||
|
this.dispatchEvent(new ol.MapBrowserEvent(
|
||||||
|
browserEvent.type, this.map_, browserEvent));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for event names.
|
* Constants for event names.
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
ol.MapBrowserEvent.EventType = {
|
ol.MapBrowserEvent.EventType = {
|
||||||
|
CLICK: goog.events.EventType.CLICK,
|
||||||
DBLCLICK: goog.events.EventType.DBLCLICK,
|
DBLCLICK: goog.events.EventType.DBLCLICK,
|
||||||
|
MOUSEMOVE: goog.events.EventType.MOUSEMOVE,
|
||||||
DOWN: 'down',
|
DOWN: 'down',
|
||||||
DRAGSTART: 'dragstart',
|
DRAGSTART: 'dragstart',
|
||||||
DRAG: 'drag',
|
DRAG: 'drag',
|
||||||
|
|||||||
Reference in New Issue
Block a user