Add dragging flag to MapBrowserEvent
This commit is contained in:
@@ -30,9 +30,11 @@ goog.require('ol.pointer.PointerEventHandler');
|
||||
* @param {string} type Event type.
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {goog.events.BrowserEvent} browserEvent Browser event.
|
||||
* @param {boolean=} opt_dragging Is the map currently being dragged?
|
||||
* @param {?olx.FrameState=} opt_frameState Frame state.
|
||||
*/
|
||||
ol.MapBrowserEvent = function(type, map, browserEvent, opt_frameState) {
|
||||
ol.MapBrowserEvent = function(type, map, browserEvent, opt_dragging,
|
||||
opt_frameState) {
|
||||
|
||||
goog.base(this, type, map, opt_frameState);
|
||||
|
||||
@@ -61,6 +63,12 @@ ol.MapBrowserEvent = function(type, map, browserEvent, opt_frameState) {
|
||||
*/
|
||||
this.coordinate = map.getCoordinateFromPixel(this.pixel);
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @api stable
|
||||
*/
|
||||
this.dragging = goog.isDef(opt_dragging) ? opt_dragging : false;
|
||||
|
||||
};
|
||||
goog.inherits(ol.MapBrowserEvent, ol.MapEvent);
|
||||
|
||||
@@ -96,11 +104,14 @@ ol.MapBrowserEvent.prototype.stopPropagation = function() {
|
||||
* @param {string} type Event type.
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
|
||||
* @param {boolean=} opt_dragging Is the map currently being dragged?
|
||||
* @param {?olx.FrameState=} opt_frameState Frame state.
|
||||
*/
|
||||
ol.MapBrowserPointerEvent = function(type, map, pointerEvent, opt_frameState) {
|
||||
ol.MapBrowserPointerEvent = function(type, map, pointerEvent, opt_dragging,
|
||||
opt_frameState) {
|
||||
|
||||
goog.base(this, type, map, pointerEvent.browserEvent, opt_frameState);
|
||||
goog.base(this, type, map, pointerEvent.browserEvent, opt_dragging,
|
||||
opt_frameState);
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -139,7 +150,7 @@ ol.MapBrowserEventHandler = function(map) {
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.dragged_ = false;
|
||||
this.dragging_ = false;
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
@@ -304,22 +315,24 @@ ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) {
|
||||
ol.MapBrowserEvent.EventType.POINTERUP, this.map_, pointerEvent);
|
||||
this.dispatchEvent(newEvent);
|
||||
|
||||
// We emulate click events on left mouse button click, touch contact, and pen
|
||||
// contact. isMouseActionButton returns true in these cases (evt.button is set
|
||||
// to 0).
|
||||
// See http://www.w3.org/TR/pointerevents/#button-states
|
||||
if (!this.dragging_ && this.isMouseActionButton_(pointerEvent)) {
|
||||
goog.asserts.assert(!goog.isNull(this.down_));
|
||||
this.emulateClick_(this.down_);
|
||||
}
|
||||
|
||||
goog.asserts.assert(this.activePointers_ >= 0);
|
||||
if (this.activePointers_ === 0) {
|
||||
goog.array.forEach(this.dragListenerKeys_, goog.events.unlistenByKey);
|
||||
this.dragListenerKeys_ = null;
|
||||
this.dragging_ = false;
|
||||
this.down_ = null;
|
||||
goog.dispose(this.documentPointerEventHandler_);
|
||||
this.documentPointerEventHandler_ = null;
|
||||
}
|
||||
|
||||
// We emulate click event on left mouse button click, touch contact, and pen
|
||||
// contact. isMouseActionButton returns true in these cases (evt.button is set
|
||||
// to 0).
|
||||
// See http://www.w3.org/TR/pointerevents/#button-states
|
||||
if (!this.dragged_ && this.isMouseActionButton_(pointerEvent)) {
|
||||
goog.asserts.assert(!goog.isNull(this.down_));
|
||||
this.emulateClick_(this.down_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -350,7 +363,6 @@ ol.MapBrowserEventHandler.prototype.handlePointerDown_ =
|
||||
this.dispatchEvent(newEvent);
|
||||
|
||||
this.down_ = pointerEvent;
|
||||
this.dragged_ = false;
|
||||
|
||||
if (goog.isNull(this.dragListenerKeys_)) {
|
||||
/* Set up a pointer event handler on the `document`,
|
||||
@@ -399,11 +411,11 @@ ol.MapBrowserEventHandler.prototype.handlePointerMove_ =
|
||||
// the exact same coordinates of the pointerdown event. To avoid a
|
||||
// 'false' touchmove event to be dispatched , we test if the pointer
|
||||
// effectively moved.
|
||||
if (pointerEvent.clientX != this.down_.clientX ||
|
||||
pointerEvent.clientY != this.down_.clientY) {
|
||||
this.dragged_ = true;
|
||||
if (this.isMoving_(pointerEvent)) {
|
||||
this.dragging_ = true;
|
||||
var newEvent = new ol.MapBrowserPointerEvent(
|
||||
ol.MapBrowserEvent.EventType.POINTERDRAG, this.map_, pointerEvent);
|
||||
ol.MapBrowserEvent.EventType.POINTERDRAG, this.map_, pointerEvent,
|
||||
this.dragging_);
|
||||
this.dispatchEvent(newEvent);
|
||||
}
|
||||
|
||||
@@ -422,8 +434,20 @@ ol.MapBrowserEventHandler.prototype.handlePointerMove_ =
|
||||
* @private
|
||||
*/
|
||||
ol.MapBrowserEventHandler.prototype.relayEvent_ = function(pointerEvent) {
|
||||
var dragging = !goog.isNull(this.down_) && this.isMoving_(pointerEvent);
|
||||
this.dispatchEvent(new ol.MapBrowserPointerEvent(
|
||||
pointerEvent.type, this.map_, pointerEvent));
|
||||
pointerEvent.type, this.map_, pointerEvent, dragging));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.pointer.PointerEvent} pointerEvent Pointer event.
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
ol.MapBrowserEventHandler.prototype.isMoving_ = function(pointerEvent) {
|
||||
return pointerEvent.clientX != this.down_.clientX ||
|
||||
pointerEvent.clientY != this.down_.clientY;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user