Merge pull request #6205 from tschaub/no-extra-provides

Rework remaining modules with multiple provides
This commit is contained in:
Tim Schaub
2016-12-06 17:46:44 -07:00
committed by GitHub
23 changed files with 531 additions and 526 deletions

View File

@@ -34,7 +34,7 @@ Interactions for [vector features](ol.Feature.html)
<tr><th>Projections</th><th>Observable objects</th><th>Other components</th></tr>
<tr><td><p>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).</p>
[ol.proj](ol.proj.html)</td>
<td><p>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.</p>
<td><p>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.</p>
<td>[ol.DeviceOrientation](ol.DeviceOrientation.html)<br>
[ol.Geolocation](ol.Geolocation.html)<br>
[ol.Overlay](ol.Overlay.html)<br></td>

View File

@@ -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);
}

View File

@@ -8,7 +8,7 @@
<th>Name</th>
<th>Type</th>
<th>Settable</th>
<th><a href="ol.ObjectEvent.html">ol.ObjectEvent</a> type</th>
<th><a href="ol.Object.Event.html">ol.Object.Event</a> type</th>
<th class="last">Description</th>
</tr>
</thead>

View File

@@ -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;
/**

View File

@@ -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;

View File

@@ -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

View File

@@ -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
@@ -188,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) {

12
src/ol/extent/corner.js Normal file
View File

@@ -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'
};

View File

@@ -1,35 +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'
};
/**
* 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.Corner');
goog.require('ol.extent.Relationship');
/**

View File

@@ -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
};

View File

@@ -1,48 +1,13 @@
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'`,
* `'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

View File

@@ -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'
};

View File

@@ -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'
};

View File

@@ -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.<string, *>}
*/
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'
};

View File

@@ -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)

View File

@@ -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);
};

View File

@@ -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,

View File

@@ -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.<ol.EventsKey>}
* @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.<number, boolean>}
* @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}

View File

@@ -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.<ol.EventsKey>}
* @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.<number, boolean>}
* @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);
};

View File

@@ -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);

View File

@@ -1,6 +1,4 @@
goog.provide('ol.Object');
goog.provide('ol.ObjectEvent');
goog.provide('ol.ObjectEventType');
goog.require('ol');
goog.require('ol.Observable');
@@ -8,52 +6,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.
*
* @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
@@ -96,7 +48,7 @@ ol.inherits(ol.ObjectEvent, ol.events.Event);
* @constructor
* @extends {ol.Observable}
* @param {Object.<string, *>=} opt_values An object with key-value pairs.
* @fires ol.ObjectEvent
* @fires ol.Object.Event
* @api
*/
ol.Object = function(opt_values) {
@@ -181,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));
eventType = ol.ObjectEventType.PROPERTYCHANGE;
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.Object.Event(eventType, key, oldValue));
};
@@ -237,3 +189,49 @@ ol.Object.prototype.unset = function(key, opt_silent) {
}
}
};
/**
* @enum {string}
*/
ol.Object.EventType = {
/**
* Triggered when a property is changed.
* @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);

View File

@@ -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'
};

View File

@@ -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)
];
};