diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 8831009077..622a98a221 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -86,7 +86,7 @@ * @property {ol.Coordinate|undefined} center The initial center for the view. * The coordinate system for the center is specified with the `projection` * option. Default is `undefined`, and layer sources will not be fetched if - * this is not set. + * this is not set. * @property {ol.Extent|undefined} extent The extent that constrains the center, * in other words, center cannot be set outside this extent. * Default is `undefined`. @@ -173,12 +173,12 @@ /** * @typedef {Object} olx.control.DefaultsOptions - * @property {boolean|undefined} attribution Attribution. + * @property {boolean|undefined} attribution Attribution. Default is `true`. * @property {olx.control.AttributionOptions|undefined} attributionOptions * Attribution options. - * @property {boolean|undefined} logo Logo. + * @property {boolean|undefined} logo Logo. Default is `true`. * @property {olx.control.LogoOptions|undefined} logoOptions Logo options. - * @property {boolean|undefined} zoom Zoom. + * @property {boolean|undefined} zoom Zoom. Default is `true`. * @property {olx.control.ZoomOptions|undefined} zoomOptions Zoom options. * @todo stability experimental */ @@ -213,9 +213,10 @@ /** * @typedef {Object} olx.control.ScaleLineOptions * @property {string|undefined} className CSS Class name. Default is `ol-scale-line`. - * @property {number|undefined} minWidth Minimum width in pixels. + * @property {number|undefined} minWidth Minimum width in pixels. Default is `64`. * @property {Element|undefined} target Target. * @property {ol.control.ScaleLineUnits|undefined} units Units. + * Default is `ol.control.ScaleLineUnits.METRIC`. * @todo stability experimental */ @@ -295,20 +296,20 @@ * Interactions for the map. Default is `true` for all options. * @typedef {Object} olx.interaction.DefaultsOptions * @property {boolean|undefined} altShiftDragRotate Whether Alt-Shift-drag - * rotate is desired. + * rotate is desired. Default is `true`. * @property {boolean|undefined} doubleClickZoom Whether double click zoom is - * desired. - * @property {boolean|undefined} dragPan Whether drag-pan is desired. + * desired. Default is `true`. + * @property {boolean|undefined} dragPan Whether drag-pan is desired. Default is `true`. * @property {boolean|undefined} keyboard Whether keyboard interaction is - * desired. + * desired. Default is `true`. * @property {boolean|undefined} mouseWheelZoom Whether mousewheel zoom is - * desired. + * desired. Default is `true`. * @property {boolean|undefined} shiftDragZoom Whether Shift-drag zoom is - * desired. + * desired. Default is `true`. * @property {boolean|undefined} touchPan Whether touch pan is - * desired. - * @property {boolean|undefined} touchRotate Whether touch rotate is desired. - * @property {boolean|undefined} touchZoom Whether touch zoom is desired. + * desired. Default is `true`. + * @property {boolean|undefined} touchRotate Whether touch rotate is desired. Default is `true`. + * @property {boolean|undefined} touchZoom Whether touch zoom is desired. Default is `true`. * @property {number|undefined} zoomDelta Zoom delta. * @property {number|undefined} zoomDuration Zoom duration. * @todo stability experimental @@ -493,14 +494,14 @@ /** * @typedef {Object} olx.source.MapGuideOptions * @property {string|undefined} url The mapagent url. - * @property {number|undefined} metersPerUnit The meters-per-unit value. - * @property {ol.Extent|undefined} extent Extent.. - * @property {boolean|undefined} useOverlay If true, will use - * GETDYNAMICMAPOVERLAYIMAGE. + * @property {number|undefined} metersPerUnit The meters-per-unit value. Default is `1`. + * @property {ol.Extent|undefined} extent Extent. + * @property {boolean|undefined} useOverlay If `true`, will use + * `GETDYNAMICMAPOVERLAYIMAGE`. * @property {ol.proj.ProjectionLike} projection Projection. - * @property {number|undefined} ratio Ratio. 1 means image requests are the size - * of the map viewport, 2 means twice the size of the map viewport, and so - * on. + * @property {number|undefined} ratio Ratio. `1` means image requests are the size + * of the map viewport, `2` means twice the size of the map viewport, and so + * on. Default is `1`. * @property {Array.|undefined} resolutions Resolutions. If specified, * requests will be made for these resolutions only. * @property {Object|undefined} params Additional parameters. @@ -544,9 +545,9 @@ * `1.3.0` by default. `WIDTH`, `HEIGHT`, `BBOX` and `CRS` (`SRS` for WMS * version < 1.3.0) will be set dynamically. * @property {ol.proj.ProjectionLike} projection Projection. - * @property {number|undefined} ratio Ratio. 1 means image requests are the size - * of the map viewport, 2 means twice the size of the map viewport, and so - * on. + * @property {number|undefined} ratio Ratio. `1` means image requests are the size + * of the map viewport, `2` means twice the size of the map viewport, and so + * on. Default is `1.5`. * @property {Array.|undefined} resolutions Resolutions. If specified, * requests will be made for these resolutions only. * @property {string|undefined} url WMS service URL. diff --git a/src/ol/object.js b/src/ol/object.js index a918f8df06..14edbb94c6 100644 --- a/src/ol/object.js +++ b/src/ol/object.js @@ -103,15 +103,6 @@ ol.ObjectAccessor.prototype.transform = function(from, to) { }; -/** - * @enum {string} - */ -ol.ObjectProperty = { - ACCESSORS: 'ol_accessors_', - BINDINGS: 'ol_bindings_' -}; - - /** * Base class implementing KVO (Key Value Observing). @@ -129,6 +120,12 @@ ol.Object = function(opt_values) { */ this.values_ = {}; + /** + * @private + * @type {Object.} + */ + this.accessors_ = {}; + /** * Lookup of beforechange listener keys. * @type {Object.} @@ -136,6 +133,12 @@ ol.Object = function(opt_values) { */ this.beforeChangeListeners_ = {}; + /** + * @private + * @type {Object.} + */ + this.listeners_ = {}; + if (goog.isDef(opt_values)) { this.setValues(opt_values); } @@ -173,16 +176,6 @@ ol.Object.capitalize = function(str) { }; -/** - * @param {ol.Object} obj Object. - * @return {Object.} Accessors. - */ -ol.Object.getAccessors = function(obj) { - return obj[ol.ObjectProperty.ACCESSORS] || - (obj[ol.ObjectProperty.ACCESSORS] = {}); -}; - - /** * @param {string} key Key name. * @return {string} Change name. @@ -205,16 +198,6 @@ ol.Object.getGetterName = function(key) { }; -/** - * @param {ol.Object} obj Object. - * @return {Object.} Listeners. - */ -ol.Object.getListeners = function(obj) { - return obj[ol.ObjectProperty.BINDINGS] || - (obj[ol.ObjectProperty.BINDINGS] = {}); -}; - - /** * @param {string} key String. * @return {string} Setter name. @@ -261,8 +244,7 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) { // listen for change:targetkey events var eventType = ol.Object.getChangeEventType(targetKey); - var listeners = ol.Object.getListeners(this); - listeners[key] = goog.events.listen(target, eventType, function() { + this.listeners_[key] = goog.events.listen(target, eventType, function() { this.notifyInternal_(key); }, undefined, this); @@ -273,8 +255,7 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) { undefined, this); var accessor = new ol.ObjectAccessor(target, targetKey); - var accessors = ol.Object.getAccessors(this); - accessors[key] = accessor; + this.accessors_[key] = accessor; this.notifyInternal_(key); return accessor; }; @@ -312,14 +293,16 @@ ol.Object.prototype.createBeforeChangeListener_ = function(key, targetKey) { */ ol.Object.prototype.get = function(key) { var value; - var accessors = ol.Object.getAccessors(this); + var accessors = this.accessors_; if (accessors.hasOwnProperty(key)) { var accessor = accessors[key]; var target = accessor.target; var targetKey = accessor.key; var getterName = ol.Object.getGetterName(targetKey); - if (target[getterName]) { - value = target[getterName](); + var getter = /** @type {function(): *|undefined} */ + (goog.object.get(target, getterName)); + if (goog.isDef(getter)) { + value = getter.call(target); } else { value = target.get(targetKey); } @@ -336,7 +319,7 @@ ol.Object.prototype.get = function(key) { * @return {Array.} List of property names. */ ol.Object.prototype.getKeys = function() { - var accessors = ol.Object.getAccessors(this); + var accessors = this.accessors_; var keysObject; if (goog.object.isEmpty(this.values_)) { if (goog.object.isEmpty(accessors)) { @@ -372,7 +355,7 @@ ol.Object.prototype.getProperties = function() { for (key in this.values_) { properties[key] = this.values_[key]; } - for (key in ol.Object.getAccessors(this)) { + for (key in this.accessors_) { properties[key] = this.get(key); } return properties; @@ -387,7 +370,7 @@ ol.Object.prototype.getProperties = function() { * @todo stability experimental */ ol.Object.prototype.notify = function(key) { - var accessors = ol.Object.getAccessors(this); + var accessors = this.accessors_; if (accessors.hasOwnProperty(key)) { var accessor = accessors[key]; var target = accessor.target; @@ -420,15 +403,17 @@ ol.Object.prototype.notifyInternal_ = function(key) { ol.Object.prototype.set = function(key, value) { this.dispatchEvent( new ol.ObjectEvent(ol.ObjectEventType.BEFOREPROPERTYCHANGE, key)); - var accessors = ol.Object.getAccessors(this); + var accessors = this.accessors_; if (accessors.hasOwnProperty(key)) { var accessor = accessors[key]; var target = accessor.target; var targetKey = accessor.key; - var setterName = ol.Object.getSetterName(targetKey); value = accessor.from(value); - if (target[setterName]) { - target[setterName](value); + var setterName = ol.Object.getSetterName(targetKey); + var setter = /** @type {function(*)|undefined} */ + (goog.object.get(target, setterName)); + if (goog.isDef(setter)) { + setter.call(target, value); } else { target.set(targetKey, value); } @@ -445,12 +430,14 @@ ol.Object.prototype.set = function(key, value) { * @todo stability experimental */ ol.Object.prototype.setValues = function(values) { - var key, value, setterName; + var key; for (key in values) { - value = values[key]; - setterName = ol.Object.getSetterName(key); - if (this[setterName]) { - this[setterName](value); + var value = values[key]; + var setterName = ol.Object.getSetterName(key); + var setter = /** @type {function(*)|undefined} */ + (goog.object.get(this, setterName)); + if (goog.isDef(setter)) { + setter.call(this, value); } else { this.set(key, value); } @@ -465,14 +452,13 @@ ol.Object.prototype.setValues = function(values) { * @todo stability experimental */ ol.Object.prototype.unbind = function(key) { - var listeners = ol.Object.getListeners(this); + var listeners = this.listeners_; var listener = listeners[key]; if (listener) { delete listeners[key]; goog.events.unlistenByKey(listener); var value = this.get(key); - var accessors = ol.Object.getAccessors(this); - delete accessors[key]; + delete this.accessors_[key]; this.values_[key] = value; } @@ -490,7 +476,7 @@ ol.Object.prototype.unbind = function(key) { * @todo stability experimental */ ol.Object.prototype.unbindAll = function() { - for (var key in ol.Object.getListeners(this)) { + for (var key in this.listeners_) { this.unbind(key); } }; diff --git a/src/ol/observable.js b/src/ol/observable.js index 6becf17b47..5b20280df6 100644 --- a/src/ol/observable.js +++ b/src/ol/observable.js @@ -10,6 +10,8 @@ goog.require('goog.events.EventTarget'); * and unregistration. * @constructor * @extends {goog.events.EventTarget} + * @suppress {checkStructDictInheritance} + * @struct * @todo stability experimental */ ol.Observable = function() {