diff --git a/src/ol/Feature.js b/src/ol/Feature.js index fa0de7875f..8cf65df0c7 100644 --- a/src/ol/Feature.js +++ b/src/ol/Feature.js @@ -5,7 +5,7 @@ import {assert} from './asserts.js'; import {listen, unlisten, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; import {inherits} from './index.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import Geometry from './geom/Geometry.js'; import Style from './style/Style.js'; @@ -90,7 +90,7 @@ const Feature = function(opt_geometryOrProperties) { this.geometryChangeKey_ = null; listen( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); if (opt_geometryOrProperties !== undefined) { @@ -266,11 +266,11 @@ Feature.prototype.setId = function(id) { */ Feature.prototype.setGeometryName = function(name) { unlisten( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); this.geometryName_ = name; listen( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); this.handleGeometryChanged_(); }; diff --git a/src/ol/Geolocation.js b/src/ol/Geolocation.js index c3a0671983..4cebf5ea81 100644 --- a/src/ol/Geolocation.js +++ b/src/ol/Geolocation.js @@ -3,7 +3,7 @@ */ import {inherits} from './index.js'; import GeolocationProperty from './GeolocationProperty.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import {listen} from './events.js'; import EventType from './events/EventType.js'; import {circular as circularPolygon} from './geom/Polygon.js'; @@ -79,10 +79,10 @@ const Geolocation = function(opt_options) { this.watchId_ = undefined; listen( - this, BaseObject.getChangeEventType(GeolocationProperty.PROJECTION), + this, getChangeEventType(GeolocationProperty.PROJECTION), this.handleProjectionChanged_, this); listen( - this, BaseObject.getChangeEventType(GeolocationProperty.TRACKING), + this, getChangeEventType(GeolocationProperty.TRACKING), this.handleTrackingChanged_, this); if (options.projection !== undefined) { diff --git a/src/ol/Object.js b/src/ol/Object.js index 67ccb3c354..2a51192d43 100644 --- a/src/ol/Object.js +++ b/src/ol/Object.js @@ -7,6 +7,40 @@ import Observable from './Observable.js'; import Event from './events/Event.js'; import {assign} from './obj.js'; + +/** + * @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 + */ +const BaseObjectEvent = function(type, key, oldValue) { + Event.call(this, type); + + /** + * The name of the property whose value is changing. + * @type {string} + * @api + */ + 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 + */ + this.oldValue = oldValue; + +}; +inherits(BaseObjectEvent, Event); + + /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -85,11 +119,11 @@ const changeEventTypeCache = {}; * @param {string} key Key name. * @return {string} Change name. */ -BaseObject.getChangeEventType = function(key) { +export function getChangeEventType(key) { return changeEventTypeCache.hasOwnProperty(key) ? changeEventTypeCache[key] : (changeEventTypeCache[key] = 'change:' + key); -}; +} /** @@ -133,10 +167,10 @@ BaseObject.prototype.getProperties = function() { */ BaseObject.prototype.notify = function(key, oldValue) { let eventType; - eventType = BaseObject.getChangeEventType(key); - this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); + eventType = getChangeEventType(key); + this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue)); eventType = ObjectEventType.PROPERTYCHANGE; - this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); + this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue)); }; @@ -191,35 +225,4 @@ BaseObject.prototype.unset = function(key, opt_silent) { }; -/** - * @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 - */ -BaseObject.Event = function(type, key, oldValue) { - Event.call(this, type); - - /** - * The name of the property whose value is changing. - * @type {string} - * @api - */ - 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 - */ - this.oldValue = oldValue; - -}; -inherits(BaseObject.Event, Event); export default BaseObject; diff --git a/src/ol/Overlay.js b/src/ol/Overlay.js index a4a01a125a..b739ae480b 100644 --- a/src/ol/Overlay.js +++ b/src/ol/Overlay.js @@ -3,7 +3,7 @@ */ import {inherits} from './index.js'; import MapEventType from './MapEventType.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import OverlayPositioning from './OverlayPositioning.js'; import {CLASS_SELECTABLE} from './css.js'; import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js'; @@ -126,23 +126,23 @@ const Overlay = function(options) { this.mapPostrenderListenerKey = null; listen( - this, BaseObject.getChangeEventType(Property.ELEMENT), + this, getChangeEventType(Property.ELEMENT), this.handleElementChanged, this); listen( - this, BaseObject.getChangeEventType(Property.MAP), + this, getChangeEventType(Property.MAP), this.handleMapChanged, this); listen( - this, BaseObject.getChangeEventType(Property.OFFSET), + this, getChangeEventType(Property.OFFSET), this.handleOffsetChanged, this); listen( - this, BaseObject.getChangeEventType(Property.POSITION), + this, getChangeEventType(Property.POSITION), this.handlePositionChanged, this); listen( - this, BaseObject.getChangeEventType(Property.POSITIONING), + this, getChangeEventType(Property.POSITIONING), this.handlePositioningChanged, this); if (options.element !== undefined) { diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 83c1869fce..36780ba8cd 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -10,7 +10,7 @@ import MapBrowserEventType from './MapBrowserEventType.js'; import MapEvent from './MapEvent.js'; import MapEventType from './MapEventType.js'; import MapProperty from './MapProperty.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import ObjectEventType from './ObjectEventType.js'; import TileQueue from './TileQueue.js'; import View from './View.js'; @@ -346,13 +346,13 @@ const PluggableMap = function(options) { this.skippedFeatureUids_ = {}; listen( - this, BaseObject.getChangeEventType(MapProperty.LAYERGROUP), + this, getChangeEventType(MapProperty.LAYERGROUP), this.handleLayerGroupChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.VIEW), + listen(this, getChangeEventType(MapProperty.VIEW), this.handleViewChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.SIZE), + listen(this, getChangeEventType(MapProperty.SIZE), this.handleSizeChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.TARGET), + listen(this, getChangeEventType(MapProperty.TARGET), this.handleTargetChanged_, this); // setProperties will trigger the rendering of the map if the map diff --git a/src/ol/control/MousePosition.js b/src/ol/control/MousePosition.js index d7311769f9..65e62beca1 100644 --- a/src/ol/control/MousePosition.js +++ b/src/ol/control/MousePosition.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import {listen} from '../events.js'; import EventType from '../events/EventType.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import Control from '../control/Control.js'; import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js'; @@ -48,7 +48,7 @@ const MousePosition = function(opt_options) { }); listen(this, - BaseObject.getChangeEventType(PROJECTION), + getChangeEventType(PROJECTION), this.handleProjectionChanged_, this); if (options.coordinateFormat) { diff --git a/src/ol/control/OverviewMap.js b/src/ol/control/OverviewMap.js index e052e0d6bb..d0ac6ebaaa 100644 --- a/src/ol/control/OverviewMap.js +++ b/src/ol/control/OverviewMap.js @@ -6,7 +6,7 @@ import Collection from '../Collection.js'; import PluggableMap from '../PluggableMap.js'; import MapEventType from '../MapEventType.js'; import MapProperty from '../MapProperty.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import ObjectEventType from '../ObjectEventType.js'; import Overlay from '../Overlay.js'; import OverlayPositioning from '../OverlayPositioning.js'; @@ -270,7 +270,7 @@ OverviewMap.prototype.handleMapPropertyChange_ = function(event) { */ OverviewMap.prototype.bindView_ = function(view) { listen(view, - BaseObject.getChangeEventType(ViewProperty.ROTATION), + getChangeEventType(ViewProperty.ROTATION), this.handleRotationChanged_, this); }; @@ -282,7 +282,7 @@ OverviewMap.prototype.bindView_ = function(view) { */ OverviewMap.prototype.unbindView_ = function(view) { unlisten(view, - BaseObject.getChangeEventType(ViewProperty.ROTATION), + getChangeEventType(ViewProperty.ROTATION), this.handleRotationChanged_, this); }; diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index 00091a8eb0..15efa83991 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -2,7 +2,7 @@ * @module ol/control/ScaleLine */ import {inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {assert} from '../asserts.js'; import Control from '../control/Control.js'; import ScaleLineUnits from '../control/ScaleLineUnits.js'; @@ -98,7 +98,7 @@ const ScaleLine = function(opt_options) { }); listen( - this, BaseObject.getChangeEventType(UNITS), + this, getChangeEventType(UNITS), this.handleUnitsChanged_, this); this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 632651b878..7f0a1e5935 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -6,7 +6,7 @@ import EventType from '../events/EventType.js'; import Feature from '../Feature.js'; import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; import {listen} from '../events.js'; import Event from '../events/Event.js'; @@ -365,7 +365,7 @@ const Draw = function(options) { } listen(this, - BaseObject.getChangeEventType(InteractionProperty.ACTIVE), + getChangeEventType(InteractionProperty.ACTIVE), this.updateState_, this); }; diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index 7564086d93..b0fc3100ca 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -3,7 +3,7 @@ */ import {inherits} from '../index.js'; import Collection from '../Collection.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {listen} from '../events.js'; import Event from '../events/Event.js'; import {TRUE} from '../functions.js'; @@ -80,7 +80,7 @@ const Translate = function(opt_options) { this.lastFeature_ = null; listen(this, - BaseObject.getChangeEventType(InteractionProperty.ACTIVE), + getChangeEventType(InteractionProperty.ACTIVE), this.handleActiveChanged_, this); }; diff --git a/src/ol/layer/Group.js b/src/ol/layer/Group.js index 3a4c516e53..99035973f9 100644 --- a/src/ol/layer/Group.js +++ b/src/ol/layer/Group.js @@ -4,7 +4,7 @@ import {getUid, inherits} from '../index.js'; import Collection from '../Collection.js'; import CollectionEventType from '../CollectionEventType.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import ObjectEventType from '../ObjectEventType.js'; import {assert} from '../asserts.js'; import {listen, unlistenByKey} from '../events.js'; @@ -58,7 +58,7 @@ const LayerGroup = function(opt_options) { this.listenerKeys_ = {}; listen(this, - BaseObject.getChangeEventType(Property.LAYERS), + getChangeEventType(Property.LAYERS), this.handleLayersChanged_, this); if (layers) { diff --git a/src/ol/layer/Heatmap.js b/src/ol/layer/Heatmap.js index c30749dd00..ec8474503e 100644 --- a/src/ol/layer/Heatmap.js +++ b/src/ol/layer/Heatmap.js @@ -3,7 +3,7 @@ */ import {listen} from '../events.js'; import {inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {createCanvasContext2D} from '../dom.js'; import VectorLayer from '../layer/Vector.js'; import {clamp} from '../math.js'; @@ -81,7 +81,7 @@ const Heatmap = function(opt_options) { this.styleCache_ = null; listen(this, - BaseObject.getChangeEventType(Property.GRADIENT), + getChangeEventType(Property.GRADIENT), this.handleGradientChanged_, this); this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT); @@ -91,10 +91,10 @@ const Heatmap = function(opt_options) { this.setRadius(options.radius !== undefined ? options.radius : 8); listen(this, - BaseObject.getChangeEventType(Property.BLUR), + getChangeEventType(Property.BLUR), this.handleStyleChanged_, this); listen(this, - BaseObject.getChangeEventType(Property.RADIUS), + getChangeEventType(Property.RADIUS), this.handleStyleChanged_, this); this.handleStyleChanged_(); diff --git a/src/ol/layer/Layer.js b/src/ol/layer/Layer.js index 20b4207bd3..412e99a865 100644 --- a/src/ol/layer/Layer.js +++ b/src/ol/layer/Layer.js @@ -4,7 +4,7 @@ import {listen, unlistenByKey} from '../events.js'; import EventType from '../events/EventType.js'; import {getUid, inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import BaseLayer from '../layer/Base.js'; import LayerProperty from '../layer/Property.js'; import {assign} from '../obj.js'; @@ -63,7 +63,7 @@ const Layer = function(options) { } listen(this, - BaseObject.getChangeEventType(LayerProperty.SOURCE), + getChangeEventType(LayerProperty.SOURCE), this.handleSourcePropertyChange_, this); const source = options.source ? options.source : null;