From 9aae8aeb261b2265b41a15096e68574ffabb8dc4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 18 Feb 2018 22:29:50 -0700 Subject: [PATCH] Export CollectionEvent from ol/Collection --- src/ol/Collection.js | 62 ++++++++++++++++++----------------- src/ol/CollectionEventType.js | 4 +-- src/ol/PluggableMap.js | 12 +++---- src/ol/interaction/Modify.js | 4 +-- src/ol/interaction/Select.js | 4 +-- src/ol/interaction/Snap.js | 10 +++--- src/ol/layer/Group.js | 4 +-- 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/ol/Collection.js b/src/ol/Collection.js index a4c97d06b3..d57fc2e831 100644 --- a/src/ol/Collection.js +++ b/src/ol/Collection.js @@ -17,6 +17,33 @@ const Property = { }; +/** + * @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. + */ +export const CollectionEvent = function(type, opt_element) { + + Event.call(this, type); + + /** + * The element that is added to or removed from the collection. + * @type {*} + * @api + */ + this.element = opt_element; + +}; + +inherits(CollectionEvent, Event); + + /** * @typedef {{unique: (boolean|undefined)}} */ @@ -33,7 +60,7 @@ export let CollectionOptions; * * @constructor * @extends {ol.Object} - * @fires ol.Collection.Event + * @fires ol.CollectionEvent * @param {Array.=} opt_array Array. * @param {CollectionOptions=} opt_options Collection options. * @param {boolean|undefined} opt_options.unique Disallow the same item from @@ -162,7 +189,7 @@ Collection.prototype.insertAt = function(index, elem) { this.array_.splice(index, 0, elem); this.updateLength_(); this.dispatchEvent( - new Collection.Event(CollectionEventType.ADD, elem)); + new CollectionEvent(CollectionEventType.ADD, elem)); }; @@ -222,7 +249,7 @@ Collection.prototype.removeAt = function(index) { const prev = this.array_[index]; this.array_.splice(index, 1); this.updateLength_(); - this.dispatchEvent(new Collection.Event(CollectionEventType.REMOVE, prev)); + this.dispatchEvent(new CollectionEvent(CollectionEventType.REMOVE, prev)); return prev; }; @@ -242,9 +269,9 @@ Collection.prototype.setAt = function(index, elem) { const prev = this.array_[index]; this.array_[index] = elem; this.dispatchEvent( - new Collection.Event(CollectionEventType.REMOVE, prev)); + new CollectionEvent(CollectionEventType.REMOVE, prev)); this.dispatchEvent( - new Collection.Event(CollectionEventType.ADD, elem)); + new CollectionEvent(CollectionEventType.ADD, elem)); } else { let j; for (j = n; j < index; ++j) { @@ -276,29 +303,4 @@ Collection.prototype.assertUnique_ = function(elem, opt_except) { } }; -/** - * @classdesc - * Events emitted by {@link ol.Collection} instances are instances of this - * type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.Collection.Event} - * @param {ol.CollectionEventType} type Type. - * @param {*=} opt_element Element. - */ -Collection.Event = function(type, opt_element) { - - Event.call(this, type); - - /** - * The element that is added to or removed from the collection. - * @type {*} - * @api - */ - this.element = opt_element; - -}; -inherits(Collection.Event, Event); - export default Collection; diff --git a/src/ol/CollectionEventType.js b/src/ol/CollectionEventType.js index 1649783d30..a3f93ae83b 100644 --- a/src/ol/CollectionEventType.js +++ b/src/ol/CollectionEventType.js @@ -8,13 +8,13 @@ export default { /** * Triggered when an item is added to the collection. - * @event ol.Collection.Event#add + * @event ol.CollectionEvent#add * @api */ ADD: 'add', /** * Triggered when an item is removed from the collection. - * @event ol.Collection.Event#remove + * @event ol.CollectionEvent#remove * @api */ REMOVE: 'remove' diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 17394eec2b..7ec33a5e94 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -371,7 +371,7 @@ const PluggableMap = function(options) { listen(this.controls, CollectionEventType.ADD, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { event.element.setMap(this); @@ -379,7 +379,7 @@ const PluggableMap = function(options) { listen(this.controls, CollectionEventType.REMOVE, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { event.element.setMap(null); @@ -396,7 +396,7 @@ const PluggableMap = function(options) { listen(this.interactions, CollectionEventType.ADD, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { event.element.setMap(this); @@ -404,7 +404,7 @@ const PluggableMap = function(options) { listen(this.interactions, CollectionEventType.REMOVE, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { event.element.setMap(null); @@ -414,7 +414,7 @@ const PluggableMap = function(options) { listen(this.overlays_, CollectionEventType.ADD, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element)); @@ -422,7 +422,7 @@ const PluggableMap = function(options) { listen(this.overlays_, CollectionEventType.REMOVE, /** - * @param {ol.Collection.Event} event Collection event. + * @param {ol.CollectionEvent} event CollectionEvent. */ function(event) { const overlay = /** @type {ol.Overlay} */ (event.element); diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index d58c416b8c..e01300603e 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -355,7 +355,7 @@ Modify.prototype.handleSourceRemove_ = function(event) { /** - * @param {ol.Collection.Event} evt Event. + * @param {ol.CollectionEvent} evt Event. * @private */ Modify.prototype.handleFeatureAdd_ = function(evt) { @@ -377,7 +377,7 @@ Modify.prototype.handleFeatureChange_ = function(evt) { /** - * @param {ol.Collection.Event} evt Event. + * @param {ol.CollectionEvent} evt Event. * @private */ Modify.prototype.handleFeatureRemove_ = function(evt) { diff --git a/src/ol/interaction/Select.js b/src/ol/interaction/Select.js index 593d4f3a7e..df425c54de 100644 --- a/src/ol/interaction/Select.js +++ b/src/ol/interaction/Select.js @@ -349,7 +349,7 @@ Select.getDefaultStyleFunction = function() { /** - * @param {ol.Collection.Event} evt Event. + * @param {ol.CollectionEvent} evt Event. * @private */ Select.prototype.addFeature_ = function(evt) { @@ -361,7 +361,7 @@ Select.prototype.addFeature_ = function(evt) { /** - * @param {ol.Collection.Event} evt Event. + * @param {ol.CollectionEvent} evt Event. * @private */ Select.prototype.removeFeature_ = function(evt) { diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index 6c5fdf6663..0aaca4e09d 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -2,7 +2,7 @@ * @module ol/interaction/Snap */ import {getUid, inherits} from '../index.js'; -import Collection from '../Collection.js'; +import {CollectionEvent} from '../Collection.js'; import CollectionEventType from '../CollectionEventType.js'; import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js'; import {listen, unlistenByKey} from '../events.js'; @@ -214,14 +214,14 @@ Snap.prototype.getFeatures_ = function() { /** - * @param {ol.source.Vector.Event|ol.Collection.Event} evt Event. + * @param {ol.source.Vector.Event|ol.CollectionEvent} evt Event. * @private */ Snap.prototype.handleFeatureAdd_ = function(evt) { let feature; if (evt instanceof VectorSource.Event) { feature = evt.feature; - } else if (evt instanceof Collection.Event) { + } else if (evt instanceof CollectionEvent) { feature = evt.element; } this.addFeature(/** @type {ol.Feature} */ (feature)); @@ -229,14 +229,14 @@ Snap.prototype.handleFeatureAdd_ = function(evt) { /** - * @param {ol.source.Vector.Event|ol.Collection.Event} evt Event. + * @param {ol.source.Vector.Event|ol.CollectionEvent} evt Event. * @private */ Snap.prototype.handleFeatureRemove_ = function(evt) { let feature; if (evt instanceof VectorSource.Event) { feature = evt.feature; - } else if (evt instanceof Collection.Event) { + } else if (evt instanceof CollectionEvent) { feature = evt.element; } this.removeFeature(/** @type {ol.Feature} */ (feature)); diff --git a/src/ol/layer/Group.js b/src/ol/layer/Group.js index a986ee894c..3a4c516e53 100644 --- a/src/ol/layer/Group.js +++ b/src/ol/layer/Group.js @@ -121,7 +121,7 @@ LayerGroup.prototype.handleLayersChanged_ = function(event) { /** - * @param {ol.Collection.Event} collectionEvent Collection event. + * @param {ol.CollectionEvent} collectionEvent CollectionEvent. * @private */ LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) { @@ -136,7 +136,7 @@ LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) { /** - * @param {ol.Collection.Event} collectionEvent Collection event. + * @param {ol.CollectionEvent} collectionEvent CollectionEvent. * @private */ LayerGroup.prototype.handleLayersRemove_ = function(collectionEvent) {