Single provide from ol/collection.js

This commit is contained in:
Tim Schaub
2016-08-06 10:21:19 -06:00
parent 4261523720
commit ffe3565166
10 changed files with 103 additions and 106 deletions

View File

@@ -4,58 +4,11 @@
*/
goog.provide('ol.Collection');
goog.provide('ol.CollectionEvent');
goog.provide('ol.CollectionEventType');
goog.require('ol.events.Event');
goog.require('ol.Object');
/**
* @enum {string}
*/
ol.CollectionEventType = {
/**
* Triggered when an item is added to the collection.
* @event ol.CollectionEvent#add
* @api stable
*/
ADD: 'add',
/**
* Triggered when an item is removed from the collection.
* @event ol.CollectionEvent#remove
* @api stable
*/
REMOVE: 'remove'
};
/**
* @classdesc
* Events emitted by {@link ol.Collection} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.CollectionEvent}
* @param {ol.CollectionEventType} type Type.
* @param {*=} opt_element Element.
*/
ol.CollectionEvent = function(type, opt_element) {
ol.events.Event.call(this, type);
/**
* The element that is added to or removed from the collection.
* @type {*}
* @api stable
*/
this.element = opt_element;
};
ol.inherits(ol.CollectionEvent, ol.events.Event);
/**
* @enum {string}
*/
@@ -74,7 +27,7 @@ ol.CollectionProperty = {
*
* @constructor
* @extends {ol.Object}
* @fires ol.CollectionEvent
* @fires ol.Collection.Event
* @param {!Array.<T>=} opt_array Array.
* @template T
* @api stable
@@ -181,7 +134,7 @@ ol.Collection.prototype.insertAt = function(index, elem) {
this.array_.splice(index, 0, elem);
this.updateLength_();
this.dispatchEvent(
new ol.CollectionEvent(ol.CollectionEventType.ADD, elem));
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
};
@@ -239,7 +192,7 @@ ol.Collection.prototype.removeAt = function(index) {
this.array_.splice(index, 1);
this.updateLength_();
this.dispatchEvent(
new ol.CollectionEvent(ol.CollectionEventType.REMOVE, prev));
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
return prev;
};
@@ -256,9 +209,9 @@ ol.Collection.prototype.setAt = function(index, elem) {
var prev = this.array_[index];
this.array_[index] = elem;
this.dispatchEvent(
new ol.CollectionEvent(ol.CollectionEventType.REMOVE, prev));
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
this.dispatchEvent(
new ol.CollectionEvent(ol.CollectionEventType.ADD, elem));
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
} else {
var j;
for (j = n; j < index; ++j) {
@@ -275,3 +228,48 @@ ol.Collection.prototype.setAt = function(index, elem) {
ol.Collection.prototype.updateLength_ = function() {
this.set(ol.CollectionProperty.LENGTH, this.array_.length);
};
/**
* @enum {string}
*/
ol.Collection.EventType = {
/**
* Triggered when an item is added to the collection.
* @event ol.Collection.Event#add
* @api stable
*/
ADD: 'add',
/**
* Triggered when an item is removed from the collection.
* @event ol.Collection.Event#remove
* @api stable
*/
REMOVE: 'remove'
};
/**
* @classdesc
* Events emitted by {@link ol.Collection} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.Collection.Event}
* @param {ol.Collection.EventType} type Type.
* @param {*=} opt_element Element.
*/
ol.Collection.Event = function(type, opt_element) {
ol.events.Event.call(this, type);
/**
* The element that is added to or removed from the collection.
* @type {*}
* @api stable
*/
this.element = opt_element;
};
ol.inherits(ol.Collection.Event, ol.events.Event);

View File

@@ -6,7 +6,6 @@ goog.require('ol.events.Event');
goog.require('ol.events.EventType');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.MapBrowserPointerEvent');
@@ -232,9 +231,9 @@ ol.interaction.Modify = function(options) {
this.features_ = options.features;
this.features_.forEach(this.addFeature_, this);
ol.events.listen(this.features_, ol.CollectionEventType.ADD,
ol.events.listen(this.features_, ol.Collection.EventType.ADD,
this.handleFeatureAdd_, this);
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
ol.events.listen(this.features_, ol.Collection.EventType.REMOVE,
this.handleFeatureRemove_, this);
/**
@@ -327,7 +326,7 @@ ol.interaction.Modify.prototype.setMap = function(map) {
/**
* @param {ol.CollectionEvent} evt Event.
* @param {ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Modify.prototype.handleFeatureAdd_ = function(evt) {
@@ -349,7 +348,7 @@ ol.interaction.Modify.prototype.handleFeatureChange_ = function(evt) {
/**
* @param {ol.CollectionEvent} evt Event.
* @param {ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Modify.prototype.handleFeatureRemove_ = function(evt) {

View File

@@ -3,7 +3,7 @@ goog.provide('ol.interaction.SelectEvent');
goog.provide('ol.interaction.SelectEventType');
goog.require('ol.functions');
goog.require('ol.CollectionEventType');
goog.require('ol.Collection');
goog.require('ol.Feature');
goog.require('ol.array');
goog.require('ol.events');
@@ -185,9 +185,9 @@ ol.interaction.Select = function(opt_options) {
this.featureLayerAssociation_ = {};
var features = this.featureOverlay_.getSource().getFeaturesCollection();
ol.events.listen(features, ol.CollectionEventType.ADD,
ol.events.listen(features, ol.Collection.EventType.ADD,
this.addFeature_, this);
ol.events.listen(features, ol.CollectionEventType.REMOVE,
ol.events.listen(features, ol.Collection.EventType.REMOVE,
this.removeFeature_, this);
};
@@ -355,7 +355,7 @@ ol.interaction.Select.getDefaultStyleFunction = function() {
/**
* @param {ol.CollectionEvent} evt Event.
* @param {ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Select.prototype.addFeature_ = function(evt) {
@@ -367,7 +367,7 @@ ol.interaction.Select.prototype.addFeature_ = function(evt) {
/**
* @param {ol.CollectionEvent} evt Event.
* @param {ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Select.prototype.removeFeature_ = function(evt) {

View File

@@ -3,8 +3,6 @@ goog.provide('ol.interaction.SnapProperty');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEvent');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.Object');
goog.require('ol.Observable');
@@ -232,14 +230,14 @@ ol.interaction.Snap.prototype.getFeatures_ = function() {
/**
* @param {ol.source.VectorEvent|ol.CollectionEvent} evt Event.
* @param {ol.source.VectorEvent|ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Snap.prototype.handleFeatureAdd_ = function(evt) {
var feature;
if (evt instanceof ol.source.VectorEvent) {
feature = evt.feature;
} else if (evt instanceof ol.CollectionEvent) {
} else if (evt instanceof ol.Collection.Event) {
feature = evt.element;
}
this.addFeature(/** @type {ol.Feature} */ (feature));
@@ -247,14 +245,14 @@ ol.interaction.Snap.prototype.handleFeatureAdd_ = function(evt) {
/**
* @param {ol.source.VectorEvent|ol.CollectionEvent} evt Event.
* @param {ol.source.VectorEvent|ol.Collection.Event} evt Event.
* @private
*/
ol.interaction.Snap.prototype.handleFeatureRemove_ = function(evt) {
var feature;
if (evt instanceof ol.source.VectorEvent) {
feature = evt.feature;
} else if (evt instanceof ol.CollectionEvent) {
} else if (evt instanceof ol.Collection.Event) {
feature = evt.element;
}
this.removeFeature(/** @type {ol.Feature} */ (feature));
@@ -342,9 +340,9 @@ ol.interaction.Snap.prototype.setMap = function(map) {
if (map) {
if (this.features_) {
keys.push(
ol.events.listen(this.features_, ol.CollectionEventType.ADD,
ol.events.listen(this.features_, ol.Collection.EventType.ADD,
this.handleFeatureAdd_, this),
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
ol.events.listen(this.features_, ol.Collection.EventType.REMOVE,
this.handleFeatureRemove_, this)
);
} else if (this.source_) {

View File

@@ -1,8 +1,6 @@
goog.provide('ol.layer.Group');
goog.require('ol.Collection');
goog.require('ol.CollectionEvent');
goog.require('ol.CollectionEventType');
goog.require('ol.Object');
goog.require('ol.ObjectEventType');
goog.require('ol.events');
@@ -97,9 +95,9 @@ ol.layer.Group.prototype.handleLayersChanged_ = function(event) {
var layers = this.getLayers();
this.layersListenerKeys_.push(
ol.events.listen(layers, ol.CollectionEventType.ADD,
ol.events.listen(layers, ol.Collection.EventType.ADD,
this.handleLayersAdd_, this),
ol.events.listen(layers, ol.CollectionEventType.REMOVE,
ol.events.listen(layers, ol.Collection.EventType.REMOVE,
this.handleLayersRemove_, this));
for (var id in this.listenerKeys_) {
@@ -124,7 +122,7 @@ ol.layer.Group.prototype.handleLayersChanged_ = function(event) {
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @param {ol.Collection.Event} collectionEvent Collection event.
* @private
*/
ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) {
@@ -143,7 +141,7 @@ ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) {
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @param {ol.Collection.Event} collectionEvent Collection event.
* @private
*/
ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) {

View File

@@ -7,7 +7,6 @@ goog.provide('ol.MapProperty');
goog.require('goog.async.nextTick');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.MapBrowserEventHandler');
@@ -404,17 +403,17 @@ ol.Map = function(options) {
control.setMap(this);
}, this);
ol.events.listen(this.controls_, ol.CollectionEventType.ADD,
ol.events.listen(this.controls_, ol.Collection.EventType.ADD,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
event.element.setMap(this);
}, this);
ol.events.listen(this.controls_, ol.CollectionEventType.REMOVE,
ol.events.listen(this.controls_, ol.Collection.EventType.REMOVE,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
event.element.setMap(null);
@@ -429,17 +428,17 @@ ol.Map = function(options) {
interaction.setMap(this);
}, this);
ol.events.listen(this.interactions_, ol.CollectionEventType.ADD,
ol.events.listen(this.interactions_, ol.Collection.EventType.ADD,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
event.element.setMap(this);
}, this);
ol.events.listen(this.interactions_, ol.CollectionEventType.REMOVE,
ol.events.listen(this.interactions_, ol.Collection.EventType.REMOVE,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
event.element.setMap(null);
@@ -447,17 +446,17 @@ ol.Map = function(options) {
this.overlays_.forEach(this.addOverlayInternal_, this);
ol.events.listen(this.overlays_, ol.CollectionEventType.ADD,
ol.events.listen(this.overlays_, ol.Collection.EventType.ADD,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element));
}, this);
ol.events.listen(this.overlays_, ol.CollectionEventType.REMOVE,
ol.events.listen(this.overlays_, ol.Collection.EventType.REMOVE,
/**
* @param {ol.CollectionEvent} event Collection event.
* @param {ol.Collection.Event} event Collection event.
*/
function(event) {
var id = event.element.getId();

View File

@@ -7,7 +7,6 @@ goog.provide('ol.source.VectorEventType');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.ObjectEventType');
goog.require('ol.array');
@@ -348,7 +347,7 @@ ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) {
modifyingCollection = false;
}
});
ol.events.listen(collection, ol.CollectionEventType.ADD,
ol.events.listen(collection, ol.Collection.EventType.ADD,
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -356,7 +355,7 @@ ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) {
modifyingCollection = false;
}
}, this);
ol.events.listen(collection, ol.CollectionEventType.REMOVE,
ol.events.listen(collection, ol.Collection.EventType.REMOVE,
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;