diff --git a/config/jsdoc/api/readme.md b/config/jsdoc/api/readme.md index 3e9fc21b09..d69aa394f5 100644 --- a/config/jsdoc/api/readme.md +++ b/config/jsdoc/api/readme.md @@ -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. diff --git a/src/ol/events/condition.js b/src/ol/events/condition.js index 6227f88c33..fec29c2968 100644 --- a/src/ol/events/condition.js +++ b/src/ol/events/condition.js @@ -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; }; diff --git a/src/ol/interaction/doubleclickzoom.js b/src/ol/interaction/doubleclickzoom.js index afaa39bc41..de4f6d95b4 100644 --- a/src/ol/interaction/doubleclickzoom.js +++ b/src/ol/interaction/doubleclickzoom.js @@ -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_; diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index f2e94e2e11..cbd0c97997 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -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; diff --git a/src/ol/interaction/extent.js b/src/ol/interaction/extent.js index 43ef25cd23..d827a2c287 100644 --- a/src/ol/interaction/extent.js +++ b/src/ol/interaction/extent.js @@ -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 diff --git a/src/ol/interaction/modify.js b/src/ol/interaction/modify.js index 294acfaeae..ee40eb3f4d 100644 --- a/src/ol/interaction/modify.js +++ b/src/ol/interaction/modify.js @@ -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_(); diff --git a/src/ol/interaction/pointer.js b/src/ol/interaction/pointer.js index 14d81c4683..e9c0375afe 100644 --- a/src/ol/interaction/pointer.js +++ b/src/ol/interaction/pointer.js @@ -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; diff --git a/src/ol/map.js b/src/ol/map.js index 312294ea69..3d9730e852 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -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); } diff --git a/src/ol/mapbrowserevent.js b/src/ol/mapbrowserevent.js index 49e9100e74..5e7b7c4d25 100644 --- a/src/ol/mapbrowserevent.js +++ b/src/ol/mapbrowserevent.js @@ -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' -}; diff --git a/src/ol/mapbrowsereventhandler.js b/src/ol/mapbrowsereventhandler.js index d3b34f9b67..608e5631e0 100644 --- a/src/ol/mapbrowsereventhandler.js +++ b/src/ol/mapbrowsereventhandler.js @@ -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); } diff --git a/src/ol/mapbrowsereventtype.js b/src/ol/mapbrowsereventtype.js new file mode 100644 index 0000000000..213052e8c8 --- /dev/null +++ b/src/ol/mapbrowsereventtype.js @@ -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' +}; diff --git a/test/spec/ol/interaction/select.test.js b/test/spec/ol/interaction/select.test.js index 71a9c71d0a..608f256eb1 100644 --- a/test/spec/ol/interaction/select.test.js +++ b/test/spec/ol/interaction/select.test.js @@ -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);