Merge pull request #2433 from fredj/collection

Templatize ol.Collection
This commit is contained in:
Frédéric Junod
2014-08-02 09:47:34 +02:00
10 changed files with 57 additions and 56 deletions
+16 -16
View File
@@ -143,14 +143,14 @@ olx.GraticuleOptions.prototype.targetSize;
/** /**
* Object literal with config options for the map. * Object literal with config options for the map.
* @typedef {{controls: (ol.Collection|Array.<ol.control.Control>|undefined), * @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined),
* deviceOptions: (olx.DeviceOptions|undefined), * deviceOptions: (olx.DeviceOptions|undefined),
* pixelRatio: (number|undefined), * pixelRatio: (number|undefined),
* interactions: (ol.Collection|Array.<ol.interaction.Interaction>|undefined), * interactions: (ol.Collection.<ol.interaction.Interaction>|Array.<ol.interaction.Interaction>|undefined),
* keyboardEventTarget: (Element|Document|string|undefined), * keyboardEventTarget: (Element|Document|string|undefined),
* layers: (Array.<ol.layer.Base>|ol.Collection|undefined), * layers: (Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined),
* logo: (boolean|string|olx.LogoOptions|undefined), * logo: (boolean|string|olx.LogoOptions|undefined),
* overlays: (ol.Collection|Array.<ol.Overlay>|undefined), * overlays: (ol.Collection.<ol.Overlay>|Array.<ol.Overlay>|undefined),
* renderer: (ol.RendererType|Array.<ol.RendererType|string>|string|undefined), * renderer: (ol.RendererType|Array.<ol.RendererType|string>|string|undefined),
* target: (Element|string|undefined), * target: (Element|string|undefined),
* view: (ol.View|undefined)}} * view: (ol.View|undefined)}}
@@ -162,7 +162,7 @@ olx.MapOptions;
/** /**
* Controls initially added to the map. If not specified, * Controls initially added to the map. If not specified,
* {@link ol.control.defaults ol.control.defaults()} is used. * {@link ol.control.defaults ol.control.defaults()} is used.
* @type {ol.Collection|Array.<ol.control.Control>|undefined} * @type {ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined}
*/ */
olx.MapOptions.prototype.controls; olx.MapOptions.prototype.controls;
@@ -185,7 +185,7 @@ olx.MapOptions.prototype.pixelRatio;
/** /**
* Interactions that are initially added to the map. If not specified, * Interactions that are initially added to the map. If not specified,
* {@link ol.interaction.defaults ol.interaction.defaults()} is used. * {@link ol.interaction.defaults ol.interaction.defaults()} is used.
* @type {ol.Collection|Array.<ol.interaction.Interaction>|undefined} * @type {ol.Collection.<ol.interaction.Interaction>|Array.<ol.interaction.Interaction>|undefined}
*/ */
olx.MapOptions.prototype.interactions; olx.MapOptions.prototype.interactions;
@@ -205,7 +205,7 @@ olx.MapOptions.prototype.keyboardEventTarget;
/** /**
* Layers. If this is not defined, a map with no layers will be rendered. * Layers. If this is not defined, a map with no layers will be rendered.
* @type {Array.<ol.layer.Base>|ol.Collection|undefined} * @type {Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined}
*/ */
olx.MapOptions.prototype.layers; olx.MapOptions.prototype.layers;
@@ -223,7 +223,7 @@ olx.MapOptions.prototype.logo;
/** /**
* Overlays initially added to the map. By default, no overlays are added. * Overlays initially added to the map. By default, no overlays are added.
* @type {ol.Collection|Array.<ol.Overlay>|undefined} * @type {ol.Collection.<ol.Overlay>|Array.<ol.Overlay>|undefined}
*/ */
olx.MapOptions.prototype.overlays; olx.MapOptions.prototype.overlays;
@@ -1732,7 +1732,7 @@ olx.interaction.DragZoomOptions.prototype.style;
/** /**
* @typedef {{features: (ol.Collection|undefined), * @typedef {{features: (ol.Collection.<ol.Feature>|undefined),
* source: (ol.source.Vector|undefined), * source: (ol.source.Vector|undefined),
* snapTolerance: (number|undefined), * snapTolerance: (number|undefined),
* type: ol.geom.GeometryType, * type: ol.geom.GeometryType,
@@ -1747,7 +1747,7 @@ olx.interaction.DrawOptions;
/** /**
* Destination collection for the drawn features. * Destination collection for the drawn features.
* @type {ol.Collection|undefined} * @type {ol.Collection.<ol.Feature>|undefined}
*/ */
olx.interaction.DrawOptions.prototype.features; olx.interaction.DrawOptions.prototype.features;
@@ -1866,7 +1866,7 @@ olx.interaction.KeyboardZoomOptions.prototype.delta;
* @typedef {{deleteCondition: (ol.events.ConditionType|undefined), * @typedef {{deleteCondition: (ol.events.ConditionType|undefined),
* pixelTolerance: (number|undefined), * pixelTolerance: (number|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined), * style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
* features: ol.Collection}} * features: ol.Collection.<ol.Feature>}}
* @api * @api
*/ */
olx.interaction.ModifyOptions; olx.interaction.ModifyOptions;
@@ -1899,7 +1899,7 @@ olx.interaction.ModifyOptions.prototype.style;
/** /**
* The features the interaction works on. * The features the interaction works on.
* @type {ol.Collection} * @type {ol.Collection.<ol.Feature>}
*/ */
olx.interaction.ModifyOptions.prototype.features; olx.interaction.ModifyOptions.prototype.features;
@@ -2200,7 +2200,7 @@ olx.layer.LayerOptions.prototype.maxResolution;
* extent: (ol.Extent|undefined), * extent: (ol.Extent|undefined),
* minResolution: (number|undefined), * minResolution: (number|undefined),
* maxResolution: (number|undefined), * maxResolution: (number|undefined),
* layers: (Array.<ol.layer.Base>|ol.Collection|undefined)}} * layers: (Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined)}}
* @api * @api
*/ */
olx.layer.GroupOptions; olx.layer.GroupOptions;
@@ -2272,7 +2272,7 @@ olx.layer.GroupOptions.prototype.maxResolution;
/** /**
* Child layers. * Child layers.
* @type {Array.<ol.layer.Base>|ol.Collection|undefined} * @type {Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined}
*/ */
olx.layer.GroupOptions.prototype.layers; olx.layer.GroupOptions.prototype.layers;
@@ -2615,7 +2615,7 @@ olx.layer.VectorOptions.prototype.visible;
/** /**
* @typedef {{features: (Array.<ol.Feature>|ol.Collection|undefined), * @typedef {{features: (Array.<ol.Feature>|ol.Collection.<ol.Feature>|undefined),
* map: (ol.Map|undefined), * map: (ol.Map|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined)}} * style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined)}}
* @api * @api
@@ -2625,7 +2625,7 @@ olx.FeatureOverlayOptions;
/** /**
* Features. * Features.
* @type {Array.<ol.Feature>|ol.Collection|undefined} * @type {Array.<ol.Feature>|ol.Collection.<ol.Feature>|undefined}
*/ */
olx.FeatureOverlayOptions.prototype.features; olx.FeatureOverlayOptions.prototype.features;
+15 -14
View File
@@ -79,7 +79,8 @@ ol.CollectionProperty = {
* @constructor * @constructor
* @extends {ol.Object} * @extends {ol.Object}
* @fires ol.CollectionEvent * @fires ol.CollectionEvent
* @param {Array=} opt_array Array. * @param {Array.<T>=} opt_array Array.
* @template T
* @api stable * @api stable
*/ */
ol.Collection = function(opt_array) { ol.Collection = function(opt_array) {
@@ -88,7 +89,7 @@ ol.Collection = function(opt_array) {
/** /**
* @private * @private
* @type {Array.<*>} * @type {Array.<T>}
*/ */
this.array_ = opt_array || []; this.array_ = opt_array || [];
@@ -110,8 +111,8 @@ ol.Collection.prototype.clear = function() {
/** /**
* @param {Array} arr Array. * @param {Array.<T>} arr Array.
* @return {ol.Collection} This collection. * @return {ol.Collection.<T>} This collection.
* @api stable * @api stable
*/ */
ol.Collection.prototype.extend = function(arr) { ol.Collection.prototype.extend = function(arr) {
@@ -129,7 +130,7 @@ ol.Collection.prototype.extend = function(arr) {
* for every element. This function takes 3 arguments (the element, the * for every element. This function takes 3 arguments (the element, the
* index and the array). The return value is ignored. * index and the array). The return value is ignored.
* @param {S=} opt_this The object to use as `this` in `f`. * @param {S=} opt_this The object to use as `this` in `f`.
* @template T,S * @template S
* @api stable * @api stable
*/ */
ol.Collection.prototype.forEach = function(f, opt_this) { ol.Collection.prototype.forEach = function(f, opt_this) {
@@ -142,7 +143,7 @@ ol.Collection.prototype.forEach = function(f, opt_this) {
* is mutated, no events will be dispatched by the collection, and the * is mutated, no events will be dispatched by the collection, and the
* collection's "length" property won't be in sync with the actual length * collection's "length" property won't be in sync with the actual length
* of the array. * of the array.
* @return {Array} Array. * @return {Array.<T>} Array.
* @api stable * @api stable
*/ */
ol.Collection.prototype.getArray = function() { ol.Collection.prototype.getArray = function() {
@@ -153,7 +154,7 @@ ol.Collection.prototype.getArray = function() {
/** /**
* Get the element at the provided index. * Get the element at the provided index.
* @param {number} index Index. * @param {number} index Index.
* @return {*} Element. * @return {T} Element.
* @api stable * @api stable
*/ */
ol.Collection.prototype.item = function(index) { ol.Collection.prototype.item = function(index) {
@@ -175,7 +176,7 @@ ol.Collection.prototype.getLength = function() {
/** /**
* Insert an element at the provided index. * Insert an element at the provided index.
* @param {number} index Index. * @param {number} index Index.
* @param {*} elem Element. * @param {T} elem Element.
* @api stable * @api stable
*/ */
ol.Collection.prototype.insertAt = function(index, elem) { ol.Collection.prototype.insertAt = function(index, elem) {
@@ -188,7 +189,7 @@ ol.Collection.prototype.insertAt = function(index, elem) {
/** /**
* Remove the last element of the collection. * Remove the last element of the collection.
* @return {*} Element. * @return {T} Element.
* @api stable * @api stable
*/ */
ol.Collection.prototype.pop = function() { ol.Collection.prototype.pop = function() {
@@ -198,7 +199,7 @@ ol.Collection.prototype.pop = function() {
/** /**
* Insert the provided element at the end of the collection. * Insert the provided element at the end of the collection.
* @param {*} elem Element. * @param {T} elem Element.
* @return {number} Length. * @return {number} Length.
* @api stable * @api stable
*/ */
@@ -211,8 +212,8 @@ ol.Collection.prototype.push = function(elem) {
/** /**
* Removes the first occurence of elem from the collection. * Removes the first occurence of elem from the collection.
* @param {*} elem Element. * @param {T} elem Element.
* @return {*} The removed element or undefined if elem was not found. * @return {T|undefined} The removed element or undefined if elem was not found.
* @api stable * @api stable
*/ */
ol.Collection.prototype.remove = function(elem) { ol.Collection.prototype.remove = function(elem) {
@@ -230,7 +231,7 @@ ol.Collection.prototype.remove = function(elem) {
/** /**
* Remove the element at the provided index. * Remove the element at the provided index.
* @param {number} index Index. * @param {number} index Index.
* @return {*} Value. * @return {T} Value.
* @api stable * @api stable
*/ */
ol.Collection.prototype.removeAt = function(index) { ol.Collection.prototype.removeAt = function(index) {
@@ -246,7 +247,7 @@ ol.Collection.prototype.removeAt = function(index) {
/** /**
* Set the element at the provided index. * Set the element at the provided index.
* @param {number} index Index. * @param {number} index Index.
* @param {*} elem Element. * @param {T} elem Element.
* @api stable * @api stable
*/ */
ol.Collection.prototype.setAt = function(index, elem) { ol.Collection.prototype.setAt = function(index, elem) {
+1 -1
View File
@@ -15,7 +15,7 @@ goog.require('ol.control.Zoom');
* * {@link ol.control.Attribution} * * {@link ol.control.Attribution}
* *
* @param {olx.control.DefaultsOptions=} opt_options Defaults options. * @param {olx.control.DefaultsOptions=} opt_options Defaults options.
* @return {ol.Collection} Controls. * @return {ol.Collection.<ol.control.Control>} Controls.
* @api * @api
*/ */
ol.control.defaults = function(opt_options) { ol.control.defaults = function(opt_options) {
+3 -3
View File
@@ -33,7 +33,7 @@ ol.FeatureOverlay = function(opt_options) {
/** /**
* @private * @private
* @type {ol.Collection} * @type {ol.Collection.<ol.Feature>}
*/ */
this.features_ = null; this.features_ = null;
@@ -104,7 +104,7 @@ ol.FeatureOverlay.prototype.addFeature = function(feature) {
/** /**
* @return {ol.Collection} Features collection. * @return {ol.Collection.<ol.Feature>} Features collection.
* @api * @api
*/ */
ol.FeatureOverlay.prototype.getFeatures = function() { ol.FeatureOverlay.prototype.getFeatures = function() {
@@ -212,7 +212,7 @@ ol.FeatureOverlay.prototype.render_ = function() {
/** /**
* @param {ol.Collection} features Features collection. * @param {ol.Collection.<ol.Feature>} features Features collection.
* @api * @api
*/ */
ol.FeatureOverlay.prototype.setFeatures = function(features) { ol.FeatureOverlay.prototype.setFeatures = function(features) {
+1 -1
View File
@@ -95,7 +95,7 @@ ol.interaction.Draw = function(options) {
/** /**
* Target collection for drawn features. * Target collection for drawn features.
* @type {ol.Collection} * @type {ol.Collection.<ol.Feature>}
* @private * @private
*/ */
this.features_ = goog.isDef(options.features) ? options.features : null; this.features_ = goog.isDef(options.features) ? options.features : null;
+2 -2
View File
@@ -35,8 +35,8 @@ goog.require('ol.interaction.PinchZoom');
* should be excluded if you want a build with no vector support. * should be excluded if you want a build with no vector support.
* *
* @param {olx.interaction.DefaultsOptions=} opt_options Defaults options. * @param {olx.interaction.DefaultsOptions=} opt_options Defaults options.
* @return {ol.Collection} A collection of interactions to be used with * @return {ol.Collection.<ol.interaction.Interaction>} A collection of
* the ol.Map constructor's interactions option. * interactions to be used with the ol.Map constructor's interactions option.
* @api stable * @api stable
*/ */
ol.interaction.defaults = function(opt_options) { ol.interaction.defaults = function(opt_options) {
+1 -1
View File
@@ -133,7 +133,7 @@ ol.interaction.Modify = function(options) {
}; };
/** /**
* @type {ol.Collection} * @type {ol.Collection.<ol.Feature>}
* @private * @private
*/ */
this.features_ = options.features; this.features_ = options.features;
+1 -1
View File
@@ -106,7 +106,7 @@ goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
/** /**
* Get the selected features. * Get the selected features.
* @return {ol.Collection} Features collection. * @return {ol.Collection.<ol.Feature>} Features collection.
* @api stable * @api stable
*/ */
ol.interaction.Select.prototype.getFeatures = function() { ol.interaction.Select.prototype.getFeatures = function() {
+4 -4
View File
@@ -145,12 +145,12 @@ ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) {
/** /**
* @return {ol.Collection|undefined} Collection of {@link ol.layer.Layer layers} * @return {ol.Collection.<ol.layer.Base>|undefined} Collection of
* that are part of this group. * {@link ol.layer.Layer layers} that are part of this group.
* @observable * @observable
*/ */
ol.layer.Group.prototype.getLayers = function() { ol.layer.Group.prototype.getLayers = function() {
return /** @type {ol.Collection|undefined} */ (this.get( return /** @type {ol.Collection.<ol.layer.Base>|undefined} */ (this.get(
ol.layer.GroupProperty.LAYERS)); ol.layer.GroupProperty.LAYERS));
}; };
goog.exportProperty( goog.exportProperty(
@@ -160,7 +160,7 @@ goog.exportProperty(
/** /**
* @param {ol.Collection|undefined} layers Collection of * @param {ol.Collection.<ol.layer.Base>|undefined} layers Collection of
* {@link ol.layer.Layer layers} that are part of this group. * {@link ol.layer.Layer layers} that are part of this group.
* @observable * @observable
*/ */
+13 -13
View File
@@ -296,7 +296,7 @@ ol.Map = function(options) {
this.registerDisposable(mouseWheelHandler); this.registerDisposable(mouseWheelHandler);
/** /**
* @type {ol.Collection} * @type {ol.Collection.<ol.control.Control>}
* @private * @private
*/ */
this.controls_ = optionsInternal.controls; this.controls_ = optionsInternal.controls;
@@ -308,13 +308,13 @@ ol.Map = function(options) {
this.deviceOptions_ = optionsInternal.deviceOptions; this.deviceOptions_ = optionsInternal.deviceOptions;
/** /**
* @type {ol.Collection} * @type {ol.Collection.<ol.interaction.Interaction>}
* @private * @private
*/ */
this.interactions_ = optionsInternal.interactions; this.interactions_ = optionsInternal.interactions;
/** /**
* @type {ol.Collection} * @type {ol.Collection.<ol.Overlay>}
* @private * @private
*/ */
this.overlays_ = optionsInternal.overlays; this.overlays_ = optionsInternal.overlays;
@@ -653,7 +653,7 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
/** /**
* @return {ol.Collection} Controls. * @return {ol.Collection.<ol.control.Control>} Controls.
* @api stable * @api stable
*/ */
ol.Map.prototype.getControls = function() { ol.Map.prototype.getControls = function() {
@@ -662,7 +662,7 @@ ol.Map.prototype.getControls = function() {
/** /**
* @return {ol.Collection} Overlays. * @return {ol.Collection.<ol.Overlay>} Overlays.
* @api stable * @api stable
*/ */
ol.Map.prototype.getOverlays = function() { ol.Map.prototype.getOverlays = function() {
@@ -676,7 +676,7 @@ ol.Map.prototype.getOverlays = function() {
* associated with the map. * associated with the map.
* *
* Interactions are used for e.g. pan, zoom and rotate. * Interactions are used for e.g. pan, zoom and rotate.
* @return {ol.Collection} {@link ol.interaction.Interaction Interactions}. * @return {ol.Collection.<ol.interaction.Interaction>} Interactions.
* @api stable * @api stable
*/ */
ol.Map.prototype.getInteractions = function() { ol.Map.prototype.getInteractions = function() {
@@ -701,7 +701,7 @@ goog.exportProperty(
/** /**
* Get the collection of layers associated with this map. * Get the collection of layers associated with this map.
* @return {ol.Collection|undefined} Layers. * @return {ol.Collection.<ol.layer.Base>|undefined} Layers.
* @api stable * @api stable
*/ */
ol.Map.prototype.getLayers = function() { ol.Map.prototype.getLayers = function() {
@@ -856,8 +856,8 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
this.focus_ = mapBrowserEvent.coordinate; this.focus_ = mapBrowserEvent.coordinate;
mapBrowserEvent.frameState = this.frameState_; mapBrowserEvent.frameState = this.frameState_;
var interactions = this.getInteractions(); var interactions = this.getInteractions();
var interactionsArray = /** @type {Array.<ol.interaction.Interaction>} */ goog.asserts.assert(goog.isDef(interactions));
(interactions.getArray()); var interactionsArray = interactions.getArray();
var i; var i;
if (this.dispatchEvent(mapBrowserEvent) !== false) { if (this.dispatchEvent(mapBrowserEvent) !== false) {
for (i = interactionsArray.length - 1; i >= 0; i--) { for (i = interactionsArray.length - 1; i >= 0; i--) {
@@ -1146,7 +1146,7 @@ ol.Map.prototype.removeInteraction = function(interaction) {
ol.Map.prototype.removeLayer = function(layer) { ol.Map.prototype.removeLayer = function(layer) {
var layers = this.getLayerGroup().getLayers(); var layers = this.getLayerGroup().getLayers();
goog.asserts.assert(goog.isDef(layers)); goog.asserts.assert(goog.isDef(layers));
return /** @type {ol.layer.Base|undefined} */ (layers.remove(layer)); return layers.remove(layer);
}; };
@@ -1377,12 +1377,12 @@ ol.Map.prototype.unskipFeature = function(feature) {
/** /**
* @typedef {{controls: ol.Collection, * @typedef {{controls: ol.Collection.<ol.control.Control>,
* deviceOptions: olx.DeviceOptions, * deviceOptions: olx.DeviceOptions,
* interactions: ol.Collection, * interactions: ol.Collection.<ol.interaction.Interaction>,
* keyboardEventTarget: (Element|Document), * keyboardEventTarget: (Element|Document),
* logos: Object, * logos: Object,
* overlays: ol.Collection, * overlays: ol.Collection.<ol.Overlay>,
* rendererConstructor: * rendererConstructor:
* function(new: ol.renderer.Map, Element, ol.Map), * function(new: ol.renderer.Map, Element, ol.Map),
* values: Object.<string, *>}} * values: Object.<string, *>}}