From 780bb1b30dbf3f163780af9461c75c83f9d3e7d2 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 13:03:58 -0800 Subject: [PATCH 01/10] Dedicated module for ol.extent.Corner enum --- src/ol/extent/corner.js | 12 ++++++++++++ src/ol/{extent.js => extent/index.js} | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 src/ol/extent/corner.js rename src/ol/{extent.js => extent/index.js} (99%) diff --git a/src/ol/extent/corner.js b/src/ol/extent/corner.js new file mode 100644 index 0000000000..6c808c47a6 --- /dev/null +++ b/src/ol/extent/corner.js @@ -0,0 +1,12 @@ +goog.provide('ol.extent.Corner'); + +/** + * Extent corner. + * @enum {string} + */ +ol.extent.Corner = { + BOTTOM_LEFT: 'bottom-left', + BOTTOM_RIGHT: 'bottom-right', + TOP_LEFT: 'top-left', + TOP_RIGHT: 'top-right' +}; diff --git a/src/ol/extent.js b/src/ol/extent/index.js similarity index 99% rename from src/ol/extent.js rename to src/ol/extent/index.js index 2f118d5001..451f27d8d2 100644 --- a/src/ol/extent.js +++ b/src/ol/extent/index.js @@ -1,21 +1,9 @@ goog.provide('ol.extent'); -goog.provide('ol.extent.Corner'); goog.provide('ol.extent.Relationship'); goog.require('ol'); goog.require('ol.asserts'); - - -/** - * Extent corner. - * @enum {string} - */ -ol.extent.Corner = { - BOTTOM_LEFT: 'bottom-left', - BOTTOM_RIGHT: 'bottom-right', - TOP_LEFT: 'top-left', - TOP_RIGHT: 'top-right' -}; +goog.require('ol.extent.Corner'); /** From c0fe3f1e4f7db95ec1683aee1fa4223691fe23bb Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:06:30 -0700 Subject: [PATCH 02/10] Dedicated module for ol.extent.Relationship enum --- src/ol/extent/index.js | 16 +--------------- src/ol/extent/relationship.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 src/ol/extent/relationship.js diff --git a/src/ol/extent/index.js b/src/ol/extent/index.js index 451f27d8d2..70e0a2d55c 100644 --- a/src/ol/extent/index.js +++ b/src/ol/extent/index.js @@ -1,23 +1,9 @@ goog.provide('ol.extent'); -goog.provide('ol.extent.Relationship'); goog.require('ol'); goog.require('ol.asserts'); goog.require('ol.extent.Corner'); - - -/** - * Relationship to an extent. - * @enum {number} - */ -ol.extent.Relationship = { - UNKNOWN: 0, - INTERSECTING: 1, - ABOVE: 2, - RIGHT: 4, - BELOW: 8, - LEFT: 16 -}; +goog.require('ol.extent.Relationship'); /** diff --git a/src/ol/extent/relationship.js b/src/ol/extent/relationship.js new file mode 100644 index 0000000000..ac359b3661 --- /dev/null +++ b/src/ol/extent/relationship.js @@ -0,0 +1,15 @@ +goog.provide('ol.extent.Relationship'); + + +/** + * Relationship to an extent. + * @enum {number} + */ +ol.extent.Relationship = { + UNKNOWN: 0, + INTERSECTING: 1, + ABOVE: 2, + RIGHT: 4, + BELOW: 8, + LEFT: 16 +}; From 3d2f677f2ad1cb9a30d79b918383eaa4ed095432 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:15:00 -0700 Subject: [PATCH 03/10] Add OperationType enum to ol.source.Raster --- externs/olx.js | 4 ++-- src/ol/source/raster.js | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 41eada26e2..5d9bd288f5 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -5257,7 +5257,7 @@ olx.source.ImageVectorOptions.prototype.style; * operation: (ol.RasterOperation|undefined), * lib: (Object|undefined), * threads: (number|undefined), - * operationType: (ol.RasterOperationType|undefined)}} + * operationType: (ol.source.Raster.OperationType|undefined)}} * @api */ olx.source.RasterOptions; @@ -5305,7 +5305,7 @@ olx.source.RasterOptions.prototype.threads; * `'pixel'` operations are assumed, and operations will be called with an * array of pixels from input sources. If set to `'image'`, operations will * be called with an array of ImageData objects from input sources. - * @type {ol.RasterOperationType|undefined} + * @type {ol.source.Raster.OperationType|undefined} * @api */ olx.source.RasterOptions.prototype.operationType; diff --git a/src/ol/source/raster.js b/src/ol/source/raster.js index 8ed70b96e6..ae085fa1cc 100644 --- a/src/ol/source/raster.js +++ b/src/ol/source/raster.js @@ -1,5 +1,4 @@ goog.provide('ol.source.Raster'); -goog.provide('ol.RasterOperationType'); goog.require('ol'); goog.require('ol.transform'); @@ -21,16 +20,6 @@ goog.require('ol.source.State'); goog.require('ol.source.Tile'); -/** - * Raster operation type. Supported values are `'pixel'` and `'image'`. - * @enum {string} - */ -ol.RasterOperationType = { - PIXEL: 'pixel', - IMAGE: 'image' -}; - - /** * @classdesc * A source that transforms data from any number of input sources using an array @@ -53,10 +42,10 @@ ol.source.Raster = function(options) { /** * @private - * @type {ol.RasterOperationType} + * @type {ol.source.Raster.OperationType} */ this.operationType_ = options.operationType !== undefined ? - options.operationType : ol.RasterOperationType.PIXEL; + options.operationType : ol.source.Raster.OperationType.PIXEL; /** * @private @@ -160,7 +149,7 @@ ol.inherits(ol.source.Raster, ol.source.Image); ol.source.Raster.prototype.setOperation = function(operation, opt_lib) { this.worker_ = new ol.ext.pixelworks.Processor({ operation: operation, - imageOps: this.operationType_ === ol.RasterOperationType.IMAGE, + imageOps: this.operationType_ === ol.source.Raster.OperationType.IMAGE, queue: 1, lib: opt_lib, threads: this.threads_ @@ -512,3 +501,13 @@ ol.source.Raster.EventType = { */ AFTEROPERATIONS: 'afteroperations' }; + + +/** + * Raster operation type. Supported values are `'pixel'` and `'image'`. + * @enum {string} + */ +ol.source.Raster.OperationType = { + PIXEL: 'pixel', + IMAGE: 'image' +}; From daba1fbcb6855db2f5633a11cecb4dc932286d92 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:20:57 -0700 Subject: [PATCH 04/10] Add EventType enum to ol.Object --- src/ol/control/overviewmap.js | 3 +-- src/ol/layer/group.js | 5 ++--- src/ol/map.js | 5 ++--- src/ol/object.js | 29 ++++++++++++++--------------- src/ol/source/vector.js | 4 ++-- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/ol/control/overviewmap.js b/src/ol/control/overviewmap.js index cd099bf3c9..791a358264 100644 --- a/src/ol/control/overviewmap.js +++ b/src/ol/control/overviewmap.js @@ -5,7 +5,6 @@ goog.require('ol.Collection'); goog.require('ol.Map'); goog.require('ol.MapEvent'); goog.require('ol.Object'); -goog.require('ol.ObjectEventType'); goog.require('ol.Overlay'); goog.require('ol.View'); goog.require('ol.control.Control'); @@ -166,7 +165,7 @@ ol.control.OverviewMap.prototype.setMap = function(map) { if (map) { this.listenerKeys.push(ol.events.listen( - map, ol.ObjectEventType.PROPERTYCHANGE, + map, ol.Object.EventType.PROPERTYCHANGE, this.handleMapPropertyChange_, this)); // TODO: to really support map switching, this would need to be reworked diff --git a/src/ol/layer/group.js b/src/ol/layer/group.js index cd1f892aa8..c42e4ca4b4 100644 --- a/src/ol/layer/group.js +++ b/src/ol/layer/group.js @@ -4,7 +4,6 @@ goog.require('ol'); goog.require('ol.asserts'); goog.require('ol.Collection'); goog.require('ol.Object'); -goog.require('ol.ObjectEventType'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -104,7 +103,7 @@ ol.layer.Group.prototype.handleLayersChanged_ = function(event) { for (i = 0, ii = layersArray.length; i < ii; i++) { layer = layersArray[i]; this.listenerKeys_[ol.getUid(layer).toString()] = [ - ol.events.listen(layer, ol.ObjectEventType.PROPERTYCHANGE, + ol.events.listen(layer, ol.Object.EventType.PROPERTYCHANGE, this.handleLayerChange_, this), ol.events.listen(layer, ol.events.EventType.CHANGE, this.handleLayerChange_, this) @@ -125,7 +124,7 @@ ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) { ol.DEBUG && console.assert(!(key in this.listenerKeys_), 'listeners already registered'); this.listenerKeys_[key] = [ - ol.events.listen(layer, ol.ObjectEventType.PROPERTYCHANGE, + ol.events.listen(layer, ol.Object.EventType.PROPERTYCHANGE, this.handleLayerChange_, this), ol.events.listen(layer, ol.events.EventType.CHANGE, this.handleLayerChange_, this) diff --git a/src/ol/map.js b/src/ol/map.js index 8f33081a23..8acbe9a76a 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -10,7 +10,6 @@ goog.require('ol.MapBrowserEvent'); goog.require('ol.MapBrowserEventHandler'); goog.require('ol.MapEvent'); goog.require('ol.Object'); -goog.require('ol.ObjectEventType'); goog.require('ol.TileQueue'); goog.require('ol.View'); goog.require('ol.asserts'); @@ -1104,7 +1103,7 @@ ol.Map.prototype.handleViewChanged_ = function() { var view = this.getView(); if (view) { this.viewPropertyListenerKey_ = ol.events.listen( - view, ol.ObjectEventType.PROPERTYCHANGE, + view, ol.Object.EventType.PROPERTYCHANGE, this.handleViewPropertyChanged_, this); this.viewChangeListenerKey_ = ol.events.listen( view, ol.events.EventType.CHANGE, @@ -1126,7 +1125,7 @@ ol.Map.prototype.handleLayerGroupChanged_ = function() { if (layerGroup) { this.layerGroupPropertyListenerKeys_ = [ ol.events.listen( - layerGroup, ol.ObjectEventType.PROPERTYCHANGE, + layerGroup, ol.Object.EventType.PROPERTYCHANGE, this.render, this), ol.events.listen( layerGroup, ol.events.EventType.CHANGE, diff --git a/src/ol/object.js b/src/ol/object.js index e3d3a5dedf..fb1d63e260 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -1,6 +1,5 @@ goog.provide('ol.Object'); goog.provide('ol.ObjectEvent'); -goog.provide('ol.ObjectEventType'); goog.require('ol'); goog.require('ol.Observable'); @@ -8,19 +7,6 @@ goog.require('ol.events.Event'); goog.require('ol.obj'); -/** - * @enum {string} - */ -ol.ObjectEventType = { - /** - * Triggered when a property is changed. - * @event ol.ObjectEvent#propertychange - * @api stable - */ - PROPERTYCHANGE: 'propertychange' -}; - - /** * @classdesc * Events emitted by {@link ol.Object} instances are instances of this type. @@ -182,7 +168,7 @@ ol.Object.prototype.notify = function(key, oldValue) { var eventType; eventType = ol.Object.getChangeEventType(key); this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue)); - eventType = ol.ObjectEventType.PROPERTYCHANGE; + eventType = ol.Object.EventType.PROPERTYCHANGE; this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue)); }; @@ -237,3 +223,16 @@ ol.Object.prototype.unset = function(key, opt_silent) { } } }; + + +/** + * @enum {string} + */ +ol.Object.EventType = { + /** + * Triggered when a property is changed. + * @event ol.ObjectEvent#propertychange + * @api stable + */ + PROPERTYCHANGE: 'propertychange' +}; diff --git a/src/ol/source/vector.js b/src/ol/source/vector.js index b7cd916f69..d13336d7cc 100644 --- a/src/ol/source/vector.js +++ b/src/ol/source/vector.js @@ -5,7 +5,7 @@ goog.provide('ol.source.Vector'); goog.require('ol'); goog.require('ol.Collection'); -goog.require('ol.ObjectEventType'); +goog.require('ol.Object'); goog.require('ol.array'); goog.require('ol.asserts'); goog.require('ol.events'); @@ -205,7 +205,7 @@ ol.source.Vector.prototype.setupChangeEvents_ = function(featureKey, feature) { this.featureChangeKeys_[featureKey] = [ ol.events.listen(feature, ol.events.EventType.CHANGE, this.handleFeatureChange_, this), - ol.events.listen(feature, ol.ObjectEventType.PROPERTYCHANGE, + ol.events.listen(feature, ol.Object.EventType.PROPERTYCHANGE, this.handleFeatureChange_, this) ]; }; From c00906cde9f263bd6bd4051d82412089ff465279 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:30:40 -0700 Subject: [PATCH 05/10] Add Event to ol.Object --- config/jsdoc/api/index.md | 2 +- config/jsdoc/api/plugins/observable.js | 2 +- .../jsdoc/api/template/tmpl/observables.tmpl | 2 +- externs/oli.js | 12 ++- src/ol/control/overviewmap.js | 2 +- src/ol/object.js | 75 +++++++++---------- 6 files changed, 50 insertions(+), 45 deletions(-) diff --git a/config/jsdoc/api/index.md b/config/jsdoc/api/index.md index 78f996ec6b..4fbb628855 100644 --- a/config/jsdoc/api/index.md +++ b/config/jsdoc/api/index.md @@ -34,7 +34,7 @@ Interactions for [vector features](ol.Feature.html) ProjectionsObservable objectsOther components

All coordinates and extents need to be provided in view projection (default: EPSG:3857). To transform, use [ol.proj.transform()](ol.proj.html#.transform) and [ol.proj.transformExtent()](ol.proj.html#.transformExtent).

[ol.proj](ol.proj.html) -

Changes to all [ol.Objects](ol.Object.html) can observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.ObjectEvent](ol.ObjectEvent.html) with information on the changed property and old value.

+

Changes to all [ol.Objects](ol.Object.html) can observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.Object.Event](ol.Object.Event.html) with information on the changed property and old value.

[ol.DeviceOrientation](ol.DeviceOrientation.html)
[ol.Geolocation](ol.Geolocation.html)
[ol.Overlay](ol.Overlay.html)
diff --git a/config/jsdoc/api/plugins/observable.js b/config/jsdoc/api/plugins/observable.js index b3bc7f3925..e662d81626 100644 --- a/config/jsdoc/api/plugins/observable.js +++ b/config/jsdoc/api/plugins/observable.js @@ -47,7 +47,7 @@ exports.handlers = { if (!cls.fires) { cls.fires = []; } - event = 'ol.ObjectEvent#event:change:' + name; + event = 'ol.Object.Event#event:change:' + name; if (cls.fires.indexOf(event) == -1) { cls.fires.push(event); } diff --git a/config/jsdoc/api/template/tmpl/observables.tmpl b/config/jsdoc/api/template/tmpl/observables.tmpl index 38e257270b..e6859aad70 100644 --- a/config/jsdoc/api/template/tmpl/observables.tmpl +++ b/config/jsdoc/api/template/tmpl/observables.tmpl @@ -8,7 +8,7 @@ Name Type Settable - ol.ObjectEvent type + ol.Object.Event type Description diff --git a/externs/oli.js b/externs/oli.js index eadebe516a..c45c80b969 100644 --- a/externs/oli.js +++ b/externs/oli.js @@ -109,22 +109,28 @@ oli.ModifyEvent.prototype.features; oli.ModifyEvent.prototype.mapBrowserEvent; +/** + * @type {Object} + */ +oli.Object; + + /** * @interface */ -oli.ObjectEvent = function() {}; +oli.Object.Event = function() {}; /** * @type {string} */ -oli.ObjectEvent.prototype.key; +oli.Object.Event.prototype.key; /** * @type {*} */ -oli.ObjectEvent.prototype.oldValue; +oli.Object.Event.prototype.oldValue; /** diff --git a/src/ol/control/overviewmap.js b/src/ol/control/overviewmap.js index 791a358264..681d6eddc9 100644 --- a/src/ol/control/overviewmap.js +++ b/src/ol/control/overviewmap.js @@ -187,7 +187,7 @@ ol.control.OverviewMap.prototype.setMap = function(map) { /** * Handle map property changes. This only deals with changes to the map's view. - * @param {ol.ObjectEvent} event The propertychange event. + * @param {ol.Object.Event} event The propertychange event. * @private */ ol.control.OverviewMap.prototype.handleMapPropertyChange_ = function(event) { diff --git a/src/ol/object.js b/src/ol/object.js index fb1d63e260..2e1f27bd46 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -1,5 +1,4 @@ goog.provide('ol.Object'); -goog.provide('ol.ObjectEvent'); goog.require('ol'); goog.require('ol.Observable'); @@ -7,39 +6,6 @@ goog.require('ol.events.Event'); goog.require('ol.obj'); -/** - * @classdesc - * Events emitted by {@link ol.Object} instances are instances of this type. - * - * @param {string} type The event type. - * @param {string} key The property name. - * @param {*} oldValue The old value for `key`. - * @extends {ol.events.Event} - * @implements {oli.ObjectEvent} - * @constructor - */ -ol.ObjectEvent = function(type, key, oldValue) { - ol.events.Event.call(this, type); - - /** - * The name of the property whose value is changing. - * @type {string} - * @api stable - */ - this.key = key; - - /** - * The old value. To get the new value use `e.target.get(e.key)` where - * `e` is the event object. - * @type {*} - * @api stable - */ - this.oldValue = oldValue; - -}; -ol.inherits(ol.ObjectEvent, ol.events.Event); - - /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -82,7 +48,7 @@ ol.inherits(ol.ObjectEvent, ol.events.Event); * @constructor * @extends {ol.Observable} * @param {Object.=} opt_values An object with key-value pairs. - * @fires ol.ObjectEvent + * @fires ol.Object.Event * @api */ ol.Object = function(opt_values) { @@ -167,9 +133,9 @@ ol.Object.prototype.getProperties = function() { ol.Object.prototype.notify = function(key, oldValue) { var eventType; eventType = ol.Object.getChangeEventType(key); - this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue)); + this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue)); eventType = ol.Object.EventType.PROPERTYCHANGE; - this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue)); + this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue)); }; @@ -231,8 +197,41 @@ ol.Object.prototype.unset = function(key, opt_silent) { ol.Object.EventType = { /** * Triggered when a property is changed. - * @event ol.ObjectEvent#propertychange + * @event ol.Object.Event#propertychange * @api stable */ PROPERTYCHANGE: 'propertychange' }; + + +/** + * @classdesc + * Events emitted by {@link ol.Object} instances are instances of this type. + * + * @param {string} type The event type. + * @param {string} key The property name. + * @param {*} oldValue The old value for `key`. + * @extends {ol.events.Event} + * @implements {oli.Object.Event} + * @constructor + */ +ol.Object.Event = function(type, key, oldValue) { + ol.events.Event.call(this, type); + + /** + * The name of the property whose value is changing. + * @type {string} + * @api stable + */ + this.key = key; + + /** + * The old value. To get the new value use `e.target.get(e.key)` where + * `e` is the event object. + * @type {*} + * @api stable + */ + this.oldValue = oldValue; + +}; +ol.inherits(ol.Object.Event, ol.events.Event); From 7858b68fc0df7f926faaf789061ec5a339b2a517 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:35:10 -0700 Subject: [PATCH 06/10] Dedicated module for GeometryType enum --- src/ol/geom/geometry.js | 22 +--------------------- src/ol/geom/geometrytype.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 src/ol/geom/geometrytype.js diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index 8352a839cd..437144c031 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -1,34 +1,14 @@ goog.provide('ol.geom.Geometry'); goog.provide('ol.geom.GeometryLayout'); -goog.provide('ol.geom.GeometryType'); goog.require('ol'); -goog.require('ol.functions'); goog.require('ol.Object'); goog.require('ol.extent'); +goog.require('ol.functions'); goog.require('ol.proj'); goog.require('ol.proj.Units'); -/** - * The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`, - * `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`, - * `'GeometryCollection'`, `'Circle'`. - * @enum {string} - */ -ol.geom.GeometryType = { - POINT: 'Point', - LINE_STRING: 'LineString', - LINEAR_RING: 'LinearRing', - POLYGON: 'Polygon', - MULTI_POINT: 'MultiPoint', - MULTI_LINE_STRING: 'MultiLineString', - MULTI_POLYGON: 'MultiPolygon', - GEOMETRY_COLLECTION: 'GeometryCollection', - CIRCLE: 'Circle' -}; - - /** * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z') * or measure ('M') coordinate is available. Supported values are `'XY'`, diff --git a/src/ol/geom/geometrytype.js b/src/ol/geom/geometrytype.js new file mode 100644 index 0000000000..9b1fde2c0d --- /dev/null +++ b/src/ol/geom/geometrytype.js @@ -0,0 +1,20 @@ +goog.provide('ol.geom.GeometryType'); + + +/** + * The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`, + * `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`, + * `'GeometryCollection'`, `'Circle'`. + * @enum {string} + */ +ol.geom.GeometryType = { + POINT: 'Point', + LINE_STRING: 'LineString', + LINEAR_RING: 'LinearRing', + POLYGON: 'Polygon', + MULTI_POINT: 'MultiPoint', + MULTI_LINE_STRING: 'MultiLineString', + MULTI_POLYGON: 'MultiPolygon', + GEOMETRY_COLLECTION: 'GeometryCollection', + CIRCLE: 'Circle' +}; From 66dc2582efc2edeb107797de576af7a48593bbef Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:36:24 -0700 Subject: [PATCH 07/10] Dedicated module for GeometryLayout --- src/ol/geom/geometry.js | 15 --------------- src/ol/geom/geometrylayout.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 src/ol/geom/geometrylayout.js diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index 437144c031..fd158cde3b 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -1,5 +1,4 @@ goog.provide('ol.geom.Geometry'); -goog.provide('ol.geom.GeometryLayout'); goog.require('ol'); goog.require('ol.Object'); @@ -9,20 +8,6 @@ goog.require('ol.proj'); goog.require('ol.proj.Units'); -/** - * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z') - * or measure ('M') coordinate is available. Supported values are `'XY'`, - * `'XYZ'`, `'XYM'`, `'XYZM'`. - * @enum {string} - */ -ol.geom.GeometryLayout = { - XY: 'XY', - XYZ: 'XYZ', - XYM: 'XYM', - XYZM: 'XYZM' -}; - - /** * @classdesc * Abstract base class; normally only used for creating subclasses and not diff --git a/src/ol/geom/geometrylayout.js b/src/ol/geom/geometrylayout.js new file mode 100644 index 0000000000..3578e1ffe3 --- /dev/null +++ b/src/ol/geom/geometrylayout.js @@ -0,0 +1,15 @@ +goog.provide('ol.geom.GeometryLayout'); + + +/** + * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z') + * or measure ('M') coordinate is available. Supported values are `'XY'`, + * `'XYZ'`, `'XYM'`, `'XYZM'`. + * @enum {string} + */ +ol.geom.GeometryLayout = { + XY: 'XY', + XYZ: 'XYZ', + XYM: 'XYM', + XYZM: 'XYZM' +}; From 57e3e7273e9889f93d2e460e290b181f76204b2a Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 14:41:32 -0700 Subject: [PATCH 08/10] Add Property enum to ol.layer.Base --- src/ol/layer/base.js | 63 +++++++++++++++++++++---------------------- src/ol/layer/layer.js | 7 +++-- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/ol/layer/base.js b/src/ol/layer/base.js index c2e0827927..3b6a0c5ec5 100644 --- a/src/ol/layer/base.js +++ b/src/ol/layer/base.js @@ -1,5 +1,4 @@ goog.provide('ol.layer.Base'); -goog.provide('ol.layer.LayerProperty'); goog.require('ol'); goog.require('ol.Object'); @@ -7,20 +6,6 @@ goog.require('ol.math'); goog.require('ol.obj'); -/** - * @enum {string} - */ -ol.layer.LayerProperty = { - OPACITY: 'opacity', - VISIBLE: 'visible', - EXTENT: 'extent', - Z_INDEX: 'zIndex', - MAX_RESOLUTION: 'maxResolution', - MIN_RESOLUTION: 'minResolution', - SOURCE: 'source' -}; - - /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -42,15 +27,15 @@ ol.layer.Base = function(options) { * @type {Object.} */ var properties = ol.obj.assign({}, options); - properties[ol.layer.LayerProperty.OPACITY] = + properties[ol.layer.Base.Property.OPACITY] = options.opacity !== undefined ? options.opacity : 1; - properties[ol.layer.LayerProperty.VISIBLE] = + properties[ol.layer.Base.Property.VISIBLE] = options.visible !== undefined ? options.visible : true; - properties[ol.layer.LayerProperty.Z_INDEX] = + properties[ol.layer.Base.Property.Z_INDEX] = options.zIndex !== undefined ? options.zIndex : 0; - properties[ol.layer.LayerProperty.MAX_RESOLUTION] = + properties[ol.layer.Base.Property.MAX_RESOLUTION] = options.maxResolution !== undefined ? options.maxResolution : Infinity; - properties[ol.layer.LayerProperty.MIN_RESOLUTION] = + properties[ol.layer.Base.Property.MIN_RESOLUTION] = options.minResolution !== undefined ? options.minResolution : 0; this.setProperties(properties); @@ -111,7 +96,7 @@ ol.layer.Base.prototype.getLayerStatesArray = function(opt_states) {}; */ ol.layer.Base.prototype.getExtent = function() { return /** @type {ol.Extent|undefined} */ ( - this.get(ol.layer.LayerProperty.EXTENT)); + this.get(ol.layer.Base.Property.EXTENT)); }; @@ -123,7 +108,7 @@ ol.layer.Base.prototype.getExtent = function() { */ ol.layer.Base.prototype.getMaxResolution = function() { return /** @type {number} */ ( - this.get(ol.layer.LayerProperty.MAX_RESOLUTION)); + this.get(ol.layer.Base.Property.MAX_RESOLUTION)); }; @@ -135,7 +120,7 @@ ol.layer.Base.prototype.getMaxResolution = function() { */ ol.layer.Base.prototype.getMinResolution = function() { return /** @type {number} */ ( - this.get(ol.layer.LayerProperty.MIN_RESOLUTION)); + this.get(ol.layer.Base.Property.MIN_RESOLUTION)); }; @@ -146,7 +131,7 @@ ol.layer.Base.prototype.getMinResolution = function() { * @api stable */ ol.layer.Base.prototype.getOpacity = function() { - return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY)); + return /** @type {number} */ (this.get(ol.layer.Base.Property.OPACITY)); }; @@ -164,7 +149,7 @@ ol.layer.Base.prototype.getSourceState = function() {}; * @api stable */ ol.layer.Base.prototype.getVisible = function() { - return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE)); + return /** @type {boolean} */ (this.get(ol.layer.Base.Property.VISIBLE)); }; @@ -176,7 +161,7 @@ ol.layer.Base.prototype.getVisible = function() { * @api */ ol.layer.Base.prototype.getZIndex = function() { - return /** @type {number} */ (this.get(ol.layer.LayerProperty.Z_INDEX)); + return /** @type {number} */ (this.get(ol.layer.Base.Property.Z_INDEX)); }; @@ -188,7 +173,7 @@ ol.layer.Base.prototype.getZIndex = function() { * @api stable */ ol.layer.Base.prototype.setExtent = function(extent) { - this.set(ol.layer.LayerProperty.EXTENT, extent); + this.set(ol.layer.Base.Property.EXTENT, extent); }; @@ -199,7 +184,7 @@ ol.layer.Base.prototype.setExtent = function(extent) { * @api stable */ ol.layer.Base.prototype.setMaxResolution = function(maxResolution) { - this.set(ol.layer.LayerProperty.MAX_RESOLUTION, maxResolution); + this.set(ol.layer.Base.Property.MAX_RESOLUTION, maxResolution); }; @@ -210,7 +195,7 @@ ol.layer.Base.prototype.setMaxResolution = function(maxResolution) { * @api stable */ ol.layer.Base.prototype.setMinResolution = function(minResolution) { - this.set(ol.layer.LayerProperty.MIN_RESOLUTION, minResolution); + this.set(ol.layer.Base.Property.MIN_RESOLUTION, minResolution); }; @@ -221,7 +206,7 @@ ol.layer.Base.prototype.setMinResolution = function(minResolution) { * @api stable */ ol.layer.Base.prototype.setOpacity = function(opacity) { - this.set(ol.layer.LayerProperty.OPACITY, opacity); + this.set(ol.layer.Base.Property.OPACITY, opacity); }; @@ -232,7 +217,7 @@ ol.layer.Base.prototype.setOpacity = function(opacity) { * @api stable */ ol.layer.Base.prototype.setVisible = function(visible) { - this.set(ol.layer.LayerProperty.VISIBLE, visible); + this.set(ol.layer.Base.Property.VISIBLE, visible); }; @@ -244,5 +229,19 @@ ol.layer.Base.prototype.setVisible = function(visible) { * @api */ ol.layer.Base.prototype.setZIndex = function(zindex) { - this.set(ol.layer.LayerProperty.Z_INDEX, zindex); + this.set(ol.layer.Base.Property.Z_INDEX, zindex); +}; + + +/** + * @enum {string} + */ +ol.layer.Base.Property = { + OPACITY: 'opacity', + VISIBLE: 'visible', + EXTENT: 'extent', + Z_INDEX: 'zIndex', + MAX_RESOLUTION: 'maxResolution', + MIN_RESOLUTION: 'minResolution', + SOURCE: 'source' }; diff --git a/src/ol/layer/layer.js b/src/ol/layer/layer.js index c735a7b442..9d16774a4f 100644 --- a/src/ol/layer/layer.js +++ b/src/ol/layer/layer.js @@ -5,7 +5,6 @@ goog.require('ol.events.EventType'); goog.require('ol'); goog.require('ol.Object'); goog.require('ol.layer.Base'); -goog.require('ol.layer.LayerProperty'); goog.require('ol.obj'); goog.require('ol.render.Event'); goog.require('ol.source.State'); @@ -62,7 +61,7 @@ ol.layer.Layer = function(options) { } ol.events.listen(this, - ol.Object.getChangeEventType(ol.layer.LayerProperty.SOURCE), + ol.Object.getChangeEventType(ol.layer.Base.Property.SOURCE), this.handleSourcePropertyChange_, this); var source = options.source ? options.source : null; @@ -112,7 +111,7 @@ ol.layer.Layer.prototype.getLayerStatesArray = function(opt_states) { * @api stable */ ol.layer.Layer.prototype.getSource = function() { - var source = this.get(ol.layer.LayerProperty.SOURCE); + var source = this.get(ol.layer.Base.Property.SOURCE); return /** @type {ol.source.Source} */ (source) || null; }; @@ -198,5 +197,5 @@ ol.layer.Layer.prototype.setMap = function(map) { * @api stable */ ol.layer.Layer.prototype.setSource = function(source) { - this.set(ol.layer.LayerProperty.SOURCE, source); + this.set(ol.layer.Base.Property.SOURCE, source); }; From 041766d53c238c236ebab8b3c0b5ce5e1b0ed37c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 15:00:15 -0700 Subject: [PATCH 09/10] Reworked mapbrowser* things --- src/ol/mapbrowserevent.js | 340 ------------------------------- src/ol/mapbrowsereventhandler.js | 317 ++++++++++++++++++++++++++++ src/ol/mapbrowserpointerevent.js | 29 +++ 3 files changed, 346 insertions(+), 340 deletions(-) create mode 100644 src/ol/mapbrowsereventhandler.js create mode 100644 src/ol/mapbrowserpointerevent.js diff --git a/src/ol/mapbrowserevent.js b/src/ol/mapbrowserevent.js index 1ed49ab7b5..49e9100e74 100644 --- a/src/ol/mapbrowserevent.js +++ b/src/ol/mapbrowserevent.js @@ -1,15 +1,8 @@ goog.provide('ol.MapBrowserEvent'); -goog.provide('ol.MapBrowserEvent.EventType'); -goog.provide('ol.MapBrowserEventHandler'); -goog.provide('ol.MapBrowserPointerEvent'); goog.require('ol'); goog.require('ol.MapEvent'); -goog.require('ol.events'); -goog.require('ol.events.EventTarget'); goog.require('ol.events.EventType'); -goog.require('ol.pointer.EventType'); -goog.require('ol.pointer.PointerEventHandler'); /** @@ -90,339 +83,6 @@ ol.MapBrowserEvent.prototype.stopPropagation = function() { }; -/** - * @constructor - * @extends {ol.MapBrowserEvent} - * @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_dragging, - opt_frameState) { - - ol.MapBrowserEvent.call(this, type, map, pointerEvent.originalEvent, opt_dragging, - opt_frameState); - - /** - * @const - * @type {ol.pointer.PointerEvent} - */ - this.pointerEvent = pointerEvent; - -}; -ol.inherits(ol.MapBrowserPointerEvent, ol.MapBrowserEvent); - - -/** - * @param {ol.Map} map The map with the viewport to listen to events on. - * @constructor - * @extends {ol.events.EventTarget} - */ -ol.MapBrowserEventHandler = function(map) { - - ol.events.EventTarget.call(this); - - /** - * This is the element that we will listen to the real events on. - * @type {ol.Map} - * @private - */ - this.map_ = map; - - /** - * @type {number} - * @private - */ - this.clickTimeoutId_ = 0; - - /** - * @type {boolean} - * @private - */ - this.dragging_ = false; - - /** - * @type {!Array.} - * @private - */ - this.dragListenerKeys_ = []; - - /** - * The most recent "down" type event (or null if none have occurred). - * Set on pointerdown. - * @type {ol.pointer.PointerEvent} - * @private - */ - this.down_ = null; - - var element = this.map_.getViewport(); - - /** - * @type {number} - * @private - */ - this.activePointers_ = 0; - - /** - * @type {!Object.} - * @private - */ - this.trackedTouches_ = {}; - - /** - * Event handler which generates pointer events for - * the viewport element. - * - * @type {ol.pointer.PointerEventHandler} - * @private - */ - this.pointerEventHandler_ = new ol.pointer.PointerEventHandler(element); - - /** - * Event handler which generates pointer events for - * the document (used when dragging). - * - * @type {ol.pointer.PointerEventHandler} - * @private - */ - this.documentPointerEventHandler_ = null; - - /** - * @type {?ol.EventsKey} - * @private - */ - this.pointerdownListenerKey_ = ol.events.listen(this.pointerEventHandler_, - ol.pointer.EventType.POINTERDOWN, - this.handlePointerDown_, this); - - /** - * @type {?ol.EventsKey} - * @private - */ - this.relayedListenerKey_ = ol.events.listen(this.pointerEventHandler_, - ol.pointer.EventType.POINTERMOVE, - this.relayEvent_, this); - -}; -ol.inherits(ol.MapBrowserEventHandler, ol.events.EventTarget); - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) { - var newEvent = new ol.MapBrowserPointerEvent( - ol.MapBrowserEvent.EventType.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); - this.dispatchEvent(newEvent); - } else { - // click - this.clickTimeoutId_ = setTimeout(function() { - this.clickTimeoutId_ = 0; - var newEvent = new ol.MapBrowserPointerEvent( - ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent); - this.dispatchEvent(newEvent); - }.bind(this), 250); - } -}; - - -/** - * Keeps track on how many pointers are currently active. - * - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.updateActivePointers_ = function(pointerEvent) { - var event = pointerEvent; - - if (event.type == ol.MapBrowserEvent.EventType.POINTERUP || - event.type == ol.MapBrowserEvent.EventType.POINTERCANCEL) { - delete this.trackedTouches_[event.pointerId]; - } else if (event.type == ol.MapBrowserEvent.EventType.POINTERDOWN) { - this.trackedTouches_[event.pointerId] = true; - } - this.activePointers_ = Object.keys(this.trackedTouches_).length; -}; - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) { - this.updateActivePointers_(pointerEvent); - var newEvent = new ol.MapBrowserPointerEvent( - 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)) { - ol.DEBUG && console.assert(this.down_, 'this.down_ must be truthy'); - this.emulateClick_(this.down_); - } - - ol.DEBUG && console.assert(this.activePointers_ >= 0, - 'this.activePointers_ should be equal to or larger than 0'); - if (this.activePointers_ === 0) { - this.dragListenerKeys_.forEach(ol.events.unlistenByKey); - this.dragListenerKeys_.length = 0; - this.dragging_ = false; - this.down_ = null; - this.documentPointerEventHandler_.dispose(); - this.documentPointerEventHandler_ = null; - } -}; - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @return {boolean} If the left mouse button was pressed. - * @private - */ -ol.MapBrowserEventHandler.prototype.isMouseActionButton_ = function(pointerEvent) { - return pointerEvent.button === 0; -}; - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent) { - this.updateActivePointers_(pointerEvent); - var newEvent = new ol.MapBrowserPointerEvent( - ol.MapBrowserEvent.EventType.POINTERDOWN, this.map_, pointerEvent); - this.dispatchEvent(newEvent); - - this.down_ = pointerEvent; - - if (this.dragListenerKeys_.length === 0) { - /* Set up a pointer event handler on the `document`, - * which is required when the pointer is moved outside - * the viewport when dragging. - */ - this.documentPointerEventHandler_ = - new ol.pointer.PointerEventHandler(document); - - this.dragListenerKeys_.push( - ol.events.listen(this.documentPointerEventHandler_, - ol.MapBrowserEvent.EventType.POINTERMOVE, - this.handlePointerMove_, this), - ol.events.listen(this.documentPointerEventHandler_, - ol.MapBrowserEvent.EventType.POINTERUP, - this.handlePointerUp_, this), - /* Note that the listener for `pointercancel is set up on - * `pointerEventHandler_` and not `documentPointerEventHandler_` like - * the `pointerup` and `pointermove` listeners. - * - * The reason for this is the following: `TouchSource.vacuumTouches_()` - * issues `pointercancel` events, when there was no `touchend` for a - * `touchstart`. Now, let's say a first `touchstart` is registered on - * `pointerEventHandler_`. The `documentPointerEventHandler_` is set up. - * But `documentPointerEventHandler_` doesn't know about the first - * `touchstart`. If there is no `touchend` for the `touchstart`, we can - * only receive a `touchcancel` from `pointerEventHandler_`, because it is - * only registered there. - */ - ol.events.listen(this.pointerEventHandler_, - ol.MapBrowserEvent.EventType.POINTERCANCEL, - this.handlePointerUp_, this) - ); - } -}; - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.handlePointerMove_ = function(pointerEvent) { - // Fix IE10 on windows Surface : When you tap the tablet, it triggers - // multiple pointermove events between pointerdown and pointerup with - // 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 (this.isMoving_(pointerEvent)) { - this.dragging_ = true; - var newEvent = new ol.MapBrowserPointerEvent( - ol.MapBrowserEvent.EventType.POINTERDRAG, this.map_, pointerEvent, - this.dragging_); - this.dispatchEvent(newEvent); - } - - // Some native android browser triggers mousemove events during small period - // of time. See: https://code.google.com/p/android/issues/detail?id=5491 or - // https://code.google.com/p/android/issues/detail?id=19827 - // ex: Galaxy Tab P3110 + Android 4.1.1 - pointerEvent.preventDefault(); -}; - - -/** - * Wrap and relay a pointer event. Note that this requires that the type - * string for the MapBrowserPointerEvent matches the PointerEvent type. - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @private - */ -ol.MapBrowserEventHandler.prototype.relayEvent_ = function(pointerEvent) { - var dragging = !!(this.down_ && this.isMoving_(pointerEvent)); - this.dispatchEvent(new ol.MapBrowserPointerEvent( - pointerEvent.type, this.map_, pointerEvent, dragging)); -}; - - -/** - * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. - * @return {boolean} Is moving. - * @private - */ -ol.MapBrowserEventHandler.prototype.isMoving_ = function(pointerEvent) { - return pointerEvent.clientX != this.down_.clientX || - pointerEvent.clientY != this.down_.clientY; -}; - - -/** - * @inheritDoc - */ -ol.MapBrowserEventHandler.prototype.disposeInternal = function() { - if (this.relayedListenerKey_) { - ol.events.unlistenByKey(this.relayedListenerKey_); - this.relayedListenerKey_ = null; - } - if (this.pointerdownListenerKey_) { - ol.events.unlistenByKey(this.pointerdownListenerKey_); - this.pointerdownListenerKey_ = null; - } - - this.dragListenerKeys_.forEach(ol.events.unlistenByKey); - this.dragListenerKeys_.length = 0; - - if (this.documentPointerEventHandler_) { - this.documentPointerEventHandler_.dispose(); - this.documentPointerEventHandler_ = null; - } - if (this.pointerEventHandler_) { - this.pointerEventHandler_.dispose(); - this.pointerEventHandler_ = null; - } - ol.events.EventTarget.prototype.disposeInternal.call(this); -}; - - /** * Constants for event names. * @enum {string} diff --git a/src/ol/mapbrowsereventhandler.js b/src/ol/mapbrowsereventhandler.js new file mode 100644 index 0000000000..d3b34f9b67 --- /dev/null +++ b/src/ol/mapbrowsereventhandler.js @@ -0,0 +1,317 @@ +goog.provide('ol.MapBrowserEventHandler'); + +goog.require('ol'); +goog.require('ol.MapBrowserEvent'); +goog.require('ol.MapBrowserPointerEvent'); +goog.require('ol.events'); +goog.require('ol.events.EventTarget'); +goog.require('ol.pointer.EventType'); +goog.require('ol.pointer.PointerEventHandler'); + + +/** + * @param {ol.Map} map The map with the viewport to listen to events on. + * @constructor + * @extends {ol.events.EventTarget} + */ +ol.MapBrowserEventHandler = function(map) { + + ol.events.EventTarget.call(this); + + /** + * This is the element that we will listen to the real events on. + * @type {ol.Map} + * @private + */ + this.map_ = map; + + /** + * @type {number} + * @private + */ + this.clickTimeoutId_ = 0; + + /** + * @type {boolean} + * @private + */ + this.dragging_ = false; + + /** + * @type {!Array.} + * @private + */ + this.dragListenerKeys_ = []; + + /** + * The most recent "down" type event (or null if none have occurred). + * Set on pointerdown. + * @type {ol.pointer.PointerEvent} + * @private + */ + this.down_ = null; + + var element = this.map_.getViewport(); + + /** + * @type {number} + * @private + */ + this.activePointers_ = 0; + + /** + * @type {!Object.} + * @private + */ + this.trackedTouches_ = {}; + + /** + * Event handler which generates pointer events for + * the viewport element. + * + * @type {ol.pointer.PointerEventHandler} + * @private + */ + this.pointerEventHandler_ = new ol.pointer.PointerEventHandler(element); + + /** + * Event handler which generates pointer events for + * the document (used when dragging). + * + * @type {ol.pointer.PointerEventHandler} + * @private + */ + this.documentPointerEventHandler_ = null; + + /** + * @type {?ol.EventsKey} + * @private + */ + this.pointerdownListenerKey_ = ol.events.listen(this.pointerEventHandler_, + ol.pointer.EventType.POINTERDOWN, + this.handlePointerDown_, this); + + /** + * @type {?ol.EventsKey} + * @private + */ + this.relayedListenerKey_ = ol.events.listen(this.pointerEventHandler_, + ol.pointer.EventType.POINTERMOVE, + this.relayEvent_, this); + +}; +ol.inherits(ol.MapBrowserEventHandler, ol.events.EventTarget); + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) { + var newEvent = new ol.MapBrowserPointerEvent( + ol.MapBrowserEvent.EventType.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); + this.dispatchEvent(newEvent); + } else { + // click + this.clickTimeoutId_ = setTimeout(function() { + this.clickTimeoutId_ = 0; + var newEvent = new ol.MapBrowserPointerEvent( + ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent); + this.dispatchEvent(newEvent); + }.bind(this), 250); + } +}; + + +/** + * Keeps track on how many pointers are currently active. + * + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.updateActivePointers_ = function(pointerEvent) { + var event = pointerEvent; + + if (event.type == ol.MapBrowserEvent.EventType.POINTERUP || + event.type == ol.MapBrowserEvent.EventType.POINTERCANCEL) { + delete this.trackedTouches_[event.pointerId]; + } else if (event.type == ol.MapBrowserEvent.EventType.POINTERDOWN) { + this.trackedTouches_[event.pointerId] = true; + } + this.activePointers_ = Object.keys(this.trackedTouches_).length; +}; + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) { + this.updateActivePointers_(pointerEvent); + var newEvent = new ol.MapBrowserPointerEvent( + 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)) { + ol.DEBUG && console.assert(this.down_, 'this.down_ must be truthy'); + this.emulateClick_(this.down_); + } + + ol.DEBUG && console.assert(this.activePointers_ >= 0, + 'this.activePointers_ should be equal to or larger than 0'); + if (this.activePointers_ === 0) { + this.dragListenerKeys_.forEach(ol.events.unlistenByKey); + this.dragListenerKeys_.length = 0; + this.dragging_ = false; + this.down_ = null; + this.documentPointerEventHandler_.dispose(); + this.documentPointerEventHandler_ = null; + } +}; + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @return {boolean} If the left mouse button was pressed. + * @private + */ +ol.MapBrowserEventHandler.prototype.isMouseActionButton_ = function(pointerEvent) { + return pointerEvent.button === 0; +}; + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.handlePointerDown_ = function(pointerEvent) { + this.updateActivePointers_(pointerEvent); + var newEvent = new ol.MapBrowserPointerEvent( + ol.MapBrowserEvent.EventType.POINTERDOWN, this.map_, pointerEvent); + this.dispatchEvent(newEvent); + + this.down_ = pointerEvent; + + if (this.dragListenerKeys_.length === 0) { + /* Set up a pointer event handler on the `document`, + * which is required when the pointer is moved outside + * the viewport when dragging. + */ + this.documentPointerEventHandler_ = + new ol.pointer.PointerEventHandler(document); + + this.dragListenerKeys_.push( + ol.events.listen(this.documentPointerEventHandler_, + ol.MapBrowserEvent.EventType.POINTERMOVE, + this.handlePointerMove_, this), + ol.events.listen(this.documentPointerEventHandler_, + ol.MapBrowserEvent.EventType.POINTERUP, + this.handlePointerUp_, this), + /* Note that the listener for `pointercancel is set up on + * `pointerEventHandler_` and not `documentPointerEventHandler_` like + * the `pointerup` and `pointermove` listeners. + * + * The reason for this is the following: `TouchSource.vacuumTouches_()` + * issues `pointercancel` events, when there was no `touchend` for a + * `touchstart`. Now, let's say a first `touchstart` is registered on + * `pointerEventHandler_`. The `documentPointerEventHandler_` is set up. + * But `documentPointerEventHandler_` doesn't know about the first + * `touchstart`. If there is no `touchend` for the `touchstart`, we can + * only receive a `touchcancel` from `pointerEventHandler_`, because it is + * only registered there. + */ + ol.events.listen(this.pointerEventHandler_, + ol.MapBrowserEvent.EventType.POINTERCANCEL, + this.handlePointerUp_, this) + ); + } +}; + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.handlePointerMove_ = function(pointerEvent) { + // Fix IE10 on windows Surface : When you tap the tablet, it triggers + // multiple pointermove events between pointerdown and pointerup with + // 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 (this.isMoving_(pointerEvent)) { + this.dragging_ = true; + var newEvent = new ol.MapBrowserPointerEvent( + ol.MapBrowserEvent.EventType.POINTERDRAG, this.map_, pointerEvent, + this.dragging_); + this.dispatchEvent(newEvent); + } + + // Some native android browser triggers mousemove events during small period + // of time. See: https://code.google.com/p/android/issues/detail?id=5491 or + // https://code.google.com/p/android/issues/detail?id=19827 + // ex: Galaxy Tab P3110 + Android 4.1.1 + pointerEvent.preventDefault(); +}; + + +/** + * Wrap and relay a pointer event. Note that this requires that the type + * string for the MapBrowserPointerEvent matches the PointerEvent type. + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @private + */ +ol.MapBrowserEventHandler.prototype.relayEvent_ = function(pointerEvent) { + var dragging = !!(this.down_ && this.isMoving_(pointerEvent)); + this.dispatchEvent(new ol.MapBrowserPointerEvent( + pointerEvent.type, this.map_, pointerEvent, dragging)); +}; + + +/** + * @param {ol.pointer.PointerEvent} pointerEvent Pointer event. + * @return {boolean} Is moving. + * @private + */ +ol.MapBrowserEventHandler.prototype.isMoving_ = function(pointerEvent) { + return pointerEvent.clientX != this.down_.clientX || + pointerEvent.clientY != this.down_.clientY; +}; + + +/** + * @inheritDoc + */ +ol.MapBrowserEventHandler.prototype.disposeInternal = function() { + if (this.relayedListenerKey_) { + ol.events.unlistenByKey(this.relayedListenerKey_); + this.relayedListenerKey_ = null; + } + if (this.pointerdownListenerKey_) { + ol.events.unlistenByKey(this.pointerdownListenerKey_); + this.pointerdownListenerKey_ = null; + } + + this.dragListenerKeys_.forEach(ol.events.unlistenByKey); + this.dragListenerKeys_.length = 0; + + if (this.documentPointerEventHandler_) { + this.documentPointerEventHandler_.dispose(); + this.documentPointerEventHandler_ = null; + } + if (this.pointerEventHandler_) { + this.pointerEventHandler_.dispose(); + this.pointerEventHandler_ = null; + } + ol.events.EventTarget.prototype.disposeInternal.call(this); +}; diff --git a/src/ol/mapbrowserpointerevent.js b/src/ol/mapbrowserpointerevent.js new file mode 100644 index 0000000000..83b73fe8f7 --- /dev/null +++ b/src/ol/mapbrowserpointerevent.js @@ -0,0 +1,29 @@ +goog.provide('ol.MapBrowserPointerEvent'); + +goog.require('ol'); +goog.require('ol.MapBrowserEvent'); + + +/** + * @constructor + * @extends {ol.MapBrowserEvent} + * @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_dragging, + opt_frameState) { + + ol.MapBrowserEvent.call(this, type, map, pointerEvent.originalEvent, opt_dragging, + opt_frameState); + + /** + * @const + * @type {ol.pointer.PointerEvent} + */ + this.pointerEvent = pointerEvent; + +}; +ol.inherits(ol.MapBrowserPointerEvent, ol.MapBrowserEvent); From 63e952a91a9d62ce82628e4c6425a13ba031b80d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Dec 2016 15:30:19 -0700 Subject: [PATCH 10/10] Treat one-provide violations as errors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f044a4c1d9..e335af25da 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "openlayers-internal/no-duplicate-requires": 2, "openlayers-internal/no-missing-requires": 1, "openlayers-internal/no-unused-requires": 2, - "openlayers-internal/one-provide": 1, + "openlayers-internal/one-provide": 2, "openlayers-internal/requires-first": 2, "openlayers-internal/valid-provide": 2, "openlayers-internal/valid-requires": 2