Shared module for map browser event type enum

This commit is contained in:
Tim Schaub
2016-12-27 13:48:50 -07:00
parent 5b937f02ae
commit c6c105b62f
12 changed files with 105 additions and 102 deletions

View File

@@ -34,7 +34,7 @@ Events are documented using `@fires` and `@event` annotations:
* Constants for event names.
* @enum {string}
*/
ol.MapBrowserEvent.EventType = {
ol.MapBrowserEventType = {
/**
* A true single click with no dragging and no double click. Note that this
* event is delayed by 250 ms to ensure that it is not a double click.

View File

@@ -1,6 +1,6 @@
goog.provide('ol.events.condition');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.asserts');
goog.require('ol.functions');
goog.require('ol.has');
@@ -59,7 +59,7 @@ ol.events.condition.always = ol.functions.TRUE;
* @api stable
*/
ol.events.condition.click = function(mapBrowserEvent) {
return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.CLICK;
return mapBrowserEvent.type == ol.MapBrowserEventType.CLICK;
};
@@ -111,7 +111,7 @@ ol.events.condition.pointerMove = function(mapBrowserEvent) {
* @api stable
*/
ol.events.condition.singleClick = function(mapBrowserEvent) {
return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.SINGLECLICK;
return mapBrowserEvent.type == ol.MapBrowserEventType.SINGLECLICK;
};
@@ -123,7 +123,7 @@ ol.events.condition.singleClick = function(mapBrowserEvent) {
* @api stable
*/
ol.events.condition.doubleClick = function(mapBrowserEvent) {
return mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK;
return mapBrowserEvent.type == ol.MapBrowserEventType.DBLCLICK;
};

View File

@@ -1,7 +1,7 @@
goog.provide('ol.interaction.DoubleClickZoom');
goog.require('ol');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.interaction.Interaction');
@@ -49,7 +49,7 @@ ol.inherits(ol.interaction.DoubleClickZoom, ol.interaction.Interaction);
ol.interaction.DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
var browserEvent = mapBrowserEvent.originalEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.DBLCLICK) {
var map = mapBrowserEvent.map;
var anchor = mapBrowserEvent.coordinate;
var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;

View File

@@ -2,7 +2,7 @@ goog.provide('ol.interaction.Draw');
goog.require('ol');
goog.require('ol.Feature');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.Object');
goog.require('ol.coordinate');
goog.require('ol.events');
@@ -304,13 +304,13 @@ ol.interaction.Draw.handleEvent = function(event) {
this.freehand_ = this.mode_ !== ol.interaction.Draw.Mode_.POINT && this.freehandCondition_(event);
var pass = !this.freehand_;
if (this.freehand_ &&
event.type === ol.MapBrowserEvent.EventType.POINTERDRAG && this.sketchFeature_ !== null) {
event.type === ol.MapBrowserEventType.POINTERDRAG && this.sketchFeature_ !== null) {
this.addToDrawing_(event);
pass = false;
} else if (event.type ===
ol.MapBrowserEvent.EventType.POINTERMOVE) {
ol.MapBrowserEventType.POINTERMOVE) {
pass = this.handlePointerMove_(event);
} else if (event.type === ol.MapBrowserEvent.EventType.DBLCLICK) {
} else if (event.type === ol.MapBrowserEventType.DBLCLICK) {
pass = false;
}
return ol.interaction.Pointer.handleEvent.call(this, event) && pass;

View File

@@ -2,7 +2,7 @@ goog.provide('ol.interaction.Extent');
goog.require('ol');
goog.require('ol.Feature');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.coordinate');
goog.require('ol.events.Event');
@@ -132,7 +132,7 @@ ol.interaction.Extent.handleEvent_ = function(mapBrowserEvent) {
return true;
}
//display pointer (if not dragging)
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE && !this.handlingDownUpSequence) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE && !this.handlingDownUpSequence) {
this.handlePointerMove_(mapBrowserEvent);
}
//call pointer to determine up/down/drag

View File

@@ -3,7 +3,7 @@ goog.provide('ol.interaction.Modify');
goog.require('ol');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.ViewHint');
goog.require('ol.array');
@@ -656,12 +656,12 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
var handled;
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE &&
mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE &&
!this.handlingDownUpSequence) {
this.handlePointerMove_(mapBrowserEvent);
}
if (this.vertexFeature_ && this.deleteCondition_(mapBrowserEvent)) {
if (mapBrowserEvent.type != ol.MapBrowserEvent.EventType.SINGLECLICK ||
if (mapBrowserEvent.type != ol.MapBrowserEventType.SINGLECLICK ||
!this.ignoreNextSingleClick_) {
handled = this.removePoint();
} else {
@@ -669,7 +669,7 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
}
}
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.SINGLECLICK) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.SINGLECLICK) {
this.ignoreNextSingleClick_ = false;
}
@@ -823,7 +823,7 @@ ol.interaction.Modify.prototype.insertVertex_ = function(segmentData, vertex) {
* @api
*/
ol.interaction.Modify.prototype.removePoint = function() {
if (this.lastPointerEvent_ && this.lastPointerEvent_.type != ol.MapBrowserEvent.EventType.POINTERDRAG) {
if (this.lastPointerEvent_ && this.lastPointerEvent_.type != ol.MapBrowserEventType.POINTERDRAG) {
var evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt);
this.removeVertex_();

View File

@@ -2,7 +2,7 @@ goog.provide('ol.interaction.Pointer');
goog.require('ol');
goog.require('ol.functions');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.interaction.Interaction');
goog.require('ol.obj');
@@ -109,9 +109,9 @@ ol.interaction.Pointer.centroid = function(pointerEvents) {
ol.interaction.Pointer.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent) {
var type = mapBrowserEvent.type;
return (
type === ol.MapBrowserEvent.EventType.POINTERDOWN ||
type === ol.MapBrowserEvent.EventType.POINTERDRAG ||
type === ol.MapBrowserEvent.EventType.POINTERUP);
type === ol.MapBrowserEventType.POINTERDOWN ||
type === ol.MapBrowserEventType.POINTERDRAG ||
type === ol.MapBrowserEventType.POINTERUP);
};
@@ -123,10 +123,10 @@ ol.interaction.Pointer.prototype.updateTrackedPointers_ = function(mapBrowserEve
if (this.isPointerDraggingEvent_(mapBrowserEvent)) {
var event = mapBrowserEvent.pointerEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERUP) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERUP) {
delete this.trackedPointers_[event.pointerId];
} else if (mapBrowserEvent.type ==
ol.MapBrowserEvent.EventType.POINTERDOWN) {
ol.MapBrowserEventType.POINTERDOWN) {
this.trackedPointers_[event.pointerId] = event;
} else if (event.pointerId in this.trackedPointers_) {
// update only when there was a pointerdown event for this pointer
@@ -184,17 +184,17 @@ ol.interaction.Pointer.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
this.updateTrackedPointers_(mapBrowserEvent);
if (this.handlingDownUpSequence) {
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERDRAG) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERDRAG) {
this.handleDragEvent_(mapBrowserEvent);
} else if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERUP) {
} else if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERUP) {
this.handlingDownUpSequence = this.handleUpEvent_(mapBrowserEvent);
}
}
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERDOWN) {
if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERDOWN) {
var handled = this.handleDownEvent_(mapBrowserEvent);
this.handlingDownUpSequence = handled;
stopEvent = this.shouldStopEvent(handled);
} else if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
} else if (mapBrowserEvent.type == ol.MapBrowserEventType.POINTERMOVE) {
this.handleMoveEvent_(mapBrowserEvent);
}
return !stopEvent;

View File

@@ -8,6 +8,7 @@ goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserEventHandler');
goog.require('ol.MapEvent');
goog.require('ol.MapProperty');
@@ -262,7 +263,7 @@ ol.Map = function(options) {
ol.events.EventType.MOUSEDOWN,
ol.events.EventType.TOUCHSTART,
ol.events.EventType.MSPOINTERDOWN,
ol.MapBrowserEvent.EventType.POINTERDOWN,
ol.MapBrowserEventType.POINTERDOWN,
ol.events.EventType.MOUSEWHEEL,
ol.events.EventType.WHEEL
];
@@ -277,8 +278,8 @@ ol.Map = function(options) {
* @type {ol.MapBrowserEventHandler}
*/
this.mapBrowserEventHandler_ = new ol.MapBrowserEventHandler(this);
for (var key in ol.MapBrowserEvent.EventType) {
ol.events.listen(this.mapBrowserEventHandler_, ol.MapBrowserEvent.EventType[key],
for (var key in ol.MapBrowserEventType) {
ol.events.listen(this.mapBrowserEventHandler_, ol.MapBrowserEventType[key],
this.handleMapBrowserEvent, this);
}

View File

@@ -2,7 +2,6 @@ goog.provide('ol.MapBrowserEvent');
goog.require('ol');
goog.require('ol.MapEvent');
goog.require('ol.events.EventType');
/**
@@ -81,56 +80,3 @@ ol.MapBrowserEvent.prototype.stopPropagation = function() {
ol.MapEvent.prototype.stopPropagation.call(this);
this.originalEvent.stopPropagation();
};
/**
* Constants for event names.
* @enum {string}
*/
ol.MapBrowserEvent.EventType = {
/**
* A true single click with no dragging and no double click. Note that this
* event is delayed by 250 ms to ensure that it is not a double click.
* @event ol.MapBrowserEvent#singleclick
* @api stable
*/
SINGLECLICK: 'singleclick',
/**
* A click with no dragging. A double click will fire two of this.
* @event ol.MapBrowserEvent#click
* @api stable
*/
CLICK: ol.events.EventType.CLICK,
/**
* A true double click, with no dragging.
* @event ol.MapBrowserEvent#dblclick
* @api stable
*/
DBLCLICK: ol.events.EventType.DBLCLICK,
/**
* Triggered when a pointer is dragged.
* @event ol.MapBrowserEvent#pointerdrag
* @api
*/
POINTERDRAG: 'pointerdrag',
/**
* Triggered when a pointer is moved. Note that on touch devices this is
* triggered when the map is panned, so is not the same as mousemove.
* @event ol.MapBrowserEvent#pointermove
* @api stable
*/
POINTERMOVE: 'pointermove',
POINTERDOWN: 'pointerdown',
POINTERUP: 'pointerup',
POINTEROVER: 'pointerover',
POINTEROUT: 'pointerout',
POINTERENTER: 'pointerenter',
POINTERLEAVE: 'pointerleave',
POINTERCANCEL: 'pointercancel'
};

View File

@@ -1,7 +1,7 @@
goog.provide('ol.MapBrowserEventHandler');
goog.require('ol');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.events');
goog.require('ol.events.EventTarget');
@@ -109,21 +109,21 @@ ol.inherits(ol.MapBrowserEventHandler, ol.events.EventTarget);
*/
ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.CLICK, this.map_, pointerEvent);
ol.MapBrowserEventType.CLICK, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
if (this.clickTimeoutId_ !== 0) {
// double-click
clearTimeout(this.clickTimeoutId_);
this.clickTimeoutId_ = 0;
newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, pointerEvent);
ol.MapBrowserEventType.DBLCLICK, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
} else {
// click
this.clickTimeoutId_ = setTimeout(function() {
this.clickTimeoutId_ = 0;
var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent);
ol.MapBrowserEventType.SINGLECLICK, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
}.bind(this), 250);
}
@@ -139,10 +139,10 @@ ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
ol.MapBrowserEventHandler.prototype.updateActivePointers_ = function(pointerEvent) {
var event = pointerEvent;
if (event.type == ol.MapBrowserEvent.EventType.POINTERUP ||
event.type == ol.MapBrowserEvent.EventType.POINTERCANCEL) {
if (event.type == ol.MapBrowserEventType.POINTERUP ||
event.type == ol.MapBrowserEventType.POINTERCANCEL) {
delete this.trackedTouches_[event.pointerId];
} else if (event.type == ol.MapBrowserEvent.EventType.POINTERDOWN) {
} else if (event.type == ol.MapBrowserEventType.POINTERDOWN) {
this.trackedTouches_[event.pointerId] = true;
}
this.activePointers_ = Object.keys(this.trackedTouches_).length;
@@ -156,7 +156,7 @@ ol.MapBrowserEventHandler.prototype.updateActivePointers_ = function(pointerEven
ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) {
this.updateActivePointers_(pointerEvent);
var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.POINTERUP, this.map_, pointerEvent);
ol.MapBrowserEventType.POINTERUP, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
// We emulate click events on left mouse button click, touch contact, and pen
@@ -198,7 +198,7 @@ ol.MapBrowserEventHandler.prototype.isMouseActionButton_ = function(pointerEvent
ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent) {
this.updateActivePointers_(pointerEvent);
var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.POINTERDOWN, this.map_, pointerEvent);
ol.MapBrowserEventType.POINTERDOWN, this.map_, pointerEvent);
this.dispatchEvent(newEvent);
this.down_ = pointerEvent;
@@ -213,10 +213,10 @@ ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent)
this.dragListenerKeys_.push(
ol.events.listen(this.documentPointerEventHandler_,
ol.MapBrowserEvent.EventType.POINTERMOVE,
ol.MapBrowserEventType.POINTERMOVE,
this.handlePointerMove_, this),
ol.events.listen(this.documentPointerEventHandler_,
ol.MapBrowserEvent.EventType.POINTERUP,
ol.MapBrowserEventType.POINTERUP,
this.handlePointerUp_, this),
/* Note that the listener for `pointercancel is set up on
* `pointerEventHandler_` and not `documentPointerEventHandler_` like
@@ -232,7 +232,7 @@ ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent)
* only registered there.
*/
ol.events.listen(this.pointerEventHandler_,
ol.MapBrowserEvent.EventType.POINTERCANCEL,
ol.MapBrowserEventType.POINTERCANCEL,
this.handlePointerUp_, this)
);
}
@@ -252,7 +252,7 @@ ol.MapBrowserEventHandler.prototype.handlePointerMove_ = function(pointerEvent)
if (this.isMoving_(pointerEvent)) {
this.dragging_ = true;
var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.POINTERDRAG, this.map_, pointerEvent,
ol.MapBrowserEventType.POINTERDRAG, this.map_, pointerEvent,
this.dragging_);
this.dispatchEvent(newEvent);
}

View File

@@ -0,0 +1,56 @@
goog.provide('ol.MapBrowserEventType');
goog.require('ol.events.EventType');
/**
* Constants for event names.
* @enum {string}
*/
ol.MapBrowserEventType = {
/**
* A true single click with no dragging and no double click. Note that this
* event is delayed by 250 ms to ensure that it is not a double click.
* @event ol.MapBrowserEvent#singleclick
* @api stable
*/
SINGLECLICK: 'singleclick',
/**
* A click with no dragging. A double click will fire two of this.
* @event ol.MapBrowserEvent#click
* @api stable
*/
CLICK: ol.events.EventType.CLICK,
/**
* A true double click, with no dragging.
* @event ol.MapBrowserEvent#dblclick
* @api stable
*/
DBLCLICK: ol.events.EventType.DBLCLICK,
/**
* Triggered when a pointer is dragged.
* @event ol.MapBrowserEvent#pointerdrag
* @api
*/
POINTERDRAG: 'pointerdrag',
/**
* Triggered when a pointer is moved. Note that on touch devices this is
* triggered when the map is panned, so is not the same as mousemove.
* @event ol.MapBrowserEvent#pointermove
* @api stable
*/
POINTERMOVE: 'pointermove',
POINTERDOWN: 'pointerdown',
POINTERUP: 'pointerup',
POINTEROVER: 'pointerover',
POINTEROUT: 'pointerout',
POINTERENTER: 'pointerenter',
POINTERLEAVE: 'pointerleave',
POINTERCANCEL: 'pointercancel'
};

View File

@@ -3,7 +3,7 @@ goog.provide('ol.test.interaction.Select');
goog.require('ol.Collection');
goog.require('ol.Feature');
goog.require('ol.Map');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventType');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.View');
goog.require('ol.geom.Polygon');
@@ -150,7 +150,7 @@ describe('ol.interaction.Select', function() {
});
select.on('select', listenerSpy);
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, -10, -10);
simulateEvent(ol.MapBrowserEventType.SINGLECLICK, -10, -10);
expect(listenerSpy.callCount).to.be(0);
@@ -164,8 +164,8 @@ describe('ol.interaction.Select', function() {
});
select.on('select', listenerSpy);
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20);
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 9, -21);
simulateEvent(ol.MapBrowserEventType.SINGLECLICK, 10, -20);
simulateEvent(ol.MapBrowserEventType.SINGLECLICK, 9, -21);
expect(listenerSpy.callCount).to.be(1);