diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index c0f796e74b..c918144fcb 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -13,7 +13,7 @@ import GeometryType from '../geom/GeometryType.js'; import {fromCircle} from '../geom/Polygon.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import {getValues} from '../obj.js'; -import VectorSource from '../source/Vector.js'; +import {VectorSourceEvent} from '../source/Vector.js'; import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; @@ -219,7 +219,7 @@ Snap.prototype.getFeatures_ = function() { */ Snap.prototype.handleFeatureAdd_ = function(evt) { let feature; - if (evt instanceof VectorSource.Event) { + if (evt instanceof VectorSourceEvent) { feature = evt.feature; } else if (evt instanceof CollectionEvent) { feature = evt.element; @@ -234,7 +234,7 @@ Snap.prototype.handleFeatureAdd_ = function(evt) { */ Snap.prototype.handleFeatureRemove_ = function(evt) { let feature; - if (evt instanceof VectorSource.Event) { + if (evt instanceof VectorSourceEvent) { feature = evt.feature; } else if (evt instanceof CollectionEvent) { feature = evt.element; diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 20f2f256c8..5479cc65c2 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -21,6 +21,33 @@ import SourceState from '../source/State.js'; import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; + +/** + * @classdesc + * Events emitted by {@link ol.source.Vector} instances are instances of this + * type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.source.Vector.Event} + * @param {string} type Type. + * @param {ol.Feature=} opt_feature Feature. + */ +export const VectorSourceEvent = function(type, opt_feature) { + + Event.call(this, type); + + /** + * The feature being added or removed. + * @type {ol.Feature|undefined} + * @api + */ + this.feature = opt_feature; + +}; +inherits(VectorSourceEvent, Event); + + /** * @classdesc * Provides a source of features for vector layers. Vector features provided @@ -191,7 +218,7 @@ VectorSource.prototype.addFeatureInternal = function(feature) { } this.dispatchEvent( - new VectorSource.Event(VectorEventType.ADDFEATURE, feature)); + new VectorSourceEvent(VectorEventType.ADDFEATURE, feature)); }; @@ -283,7 +310,7 @@ VectorSource.prototype.addFeaturesInternal = function(features) { } for (let i = 0, length = newFeatures.length; i < length; i++) { - this.dispatchEvent(new VectorSource.Event(VectorEventType.ADDFEATURE, newFeatures[i])); + this.dispatchEvent(new VectorSourceEvent(VectorEventType.ADDFEATURE, newFeatures[i])); } }; @@ -364,7 +391,7 @@ VectorSource.prototype.clear = function(opt_fast) { this.loadedExtentsRtree_.clear(); this.nullGeometryFeatures_ = {}; - const clearEvent = new VectorSource.Event(VectorEventType.CLEAR); + const clearEvent = new VectorSourceEvent(VectorEventType.CLEAR); this.dispatchEvent(clearEvent); this.changed(); }; @@ -709,7 +736,7 @@ VectorSource.prototype.handleFeatureChange_ = function(event) { } } this.changed(); - this.dispatchEvent(new VectorSource.Event( + this.dispatchEvent(new VectorSourceEvent( VectorEventType.CHANGEFEATURE, feature)); }; @@ -805,7 +832,7 @@ VectorSource.prototype.removeFeatureInternal = function(feature) { } else { delete this.undefIdIndex_[featureKey]; } - this.dispatchEvent(new VectorSource.Event( + this.dispatchEvent(new VectorSourceEvent( VectorEventType.REMOVEFEATURE, feature)); }; @@ -840,29 +867,4 @@ VectorSource.prototype.setLoader = function(loader) { this.loader_ = loader; }; - -/** - * @classdesc - * Events emitted by {@link ol.source.Vector} instances are instances of this - * type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.source.Vector.Event} - * @param {string} type Type. - * @param {ol.Feature=} opt_feature Feature. - */ -VectorSource.Event = function(type, opt_feature) { - - Event.call(this, type); - - /** - * The feature being added or removed. - * @type {ol.Feature|undefined} - * @api - */ - this.feature = opt_feature; - -}; -inherits(VectorSource.Event, Event); export default VectorSource;