Add Event to ol.Object
This commit is contained in:
@@ -34,7 +34,7 @@ Interactions for [vector features](ol.Feature.html)
|
||||
<tr><th>Projections</th><th>Observable objects</th><th>Other components</th></tr>
|
||||
<tr><td><p>All coordinates and extents need to be provided in view projection (default: EPSG:3857). To transform, use [ol.proj.transform()](ol.proj.html#.transform) and [ol.proj.transformExtent()](ol.proj.html#.transformExtent).</p>
|
||||
[ol.proj](ol.proj.html)</td>
|
||||
<td><p>Changes to all [ol.Objects](ol.Object.html) can observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.ObjectEvent](ol.ObjectEvent.html) with information on the changed property and old value.</p>
|
||||
<td><p>Changes to all [ol.Objects](ol.Object.html) can observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.Object.Event](ol.Object.Event.html) with information on the changed property and old value.</p>
|
||||
<td>[ol.DeviceOrientation](ol.DeviceOrientation.html)<br>
|
||||
[ol.Geolocation](ol.Geolocation.html)<br>
|
||||
[ol.Overlay](ol.Overlay.html)<br></td>
|
||||
|
||||
@@ -47,7 +47,7 @@ exports.handlers = {
|
||||
if (!cls.fires) {
|
||||
cls.fires = [];
|
||||
}
|
||||
event = 'ol.ObjectEvent#event:change:' + name;
|
||||
event = 'ol.Object.Event#event:change:' + name;
|
||||
if (cls.fires.indexOf(event) == -1) {
|
||||
cls.fires.push(event);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Settable</th>
|
||||
<th><a href="ol.ObjectEvent.html">ol.ObjectEvent</a> type</th>
|
||||
<th><a href="ol.Object.Event.html">ol.Object.Event</a> type</th>
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -109,22 +109,28 @@ oli.ModifyEvent.prototype.features;
|
||||
oli.ModifyEvent.prototype.mapBrowserEvent;
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
*/
|
||||
oli.Object;
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
oli.ObjectEvent = function() {};
|
||||
oli.Object.Event = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
oli.ObjectEvent.prototype.key;
|
||||
oli.Object.Event.prototype.key;
|
||||
|
||||
|
||||
/**
|
||||
* @type {*}
|
||||
*/
|
||||
oli.ObjectEvent.prototype.oldValue;
|
||||
oli.Object.Event.prototype.oldValue;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -187,7 +187,7 @@ ol.control.OverviewMap.prototype.setMap = function(map) {
|
||||
|
||||
/**
|
||||
* Handle map property changes. This only deals with changes to the map's view.
|
||||
* @param {ol.ObjectEvent} event The propertychange event.
|
||||
* @param {ol.Object.Event} event The propertychange event.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.handleMapPropertyChange_ = function(event) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
goog.provide('ol.Object');
|
||||
goog.provide('ol.ObjectEvent');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.Observable');
|
||||
@@ -7,39 +6,6 @@ goog.require('ol.events.Event');
|
||||
goog.require('ol.obj');
|
||||
|
||||
|
||||
/**
|
||||
* @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.ObjectEvent}
|
||||
* @constructor
|
||||
*/
|
||||
ol.ObjectEvent = function(type, key, oldValue) {
|
||||
ol.events.Event.call(this, type);
|
||||
|
||||
/**
|
||||
* The name of the property whose value is changing.
|
||||
* @type {string}
|
||||
* @api stable
|
||||
*/
|
||||
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 stable
|
||||
*/
|
||||
this.oldValue = oldValue;
|
||||
|
||||
};
|
||||
ol.inherits(ol.ObjectEvent, ol.events.Event);
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -82,7 +48,7 @@ ol.inherits(ol.ObjectEvent, ol.events.Event);
|
||||
* @constructor
|
||||
* @extends {ol.Observable}
|
||||
* @param {Object.<string, *>=} opt_values An object with key-value pairs.
|
||||
* @fires ol.ObjectEvent
|
||||
* @fires ol.Object.Event
|
||||
* @api
|
||||
*/
|
||||
ol.Object = function(opt_values) {
|
||||
@@ -167,9 +133,9 @@ ol.Object.prototype.getProperties = function() {
|
||||
ol.Object.prototype.notify = function(key, oldValue) {
|
||||
var eventType;
|
||||
eventType = ol.Object.getChangeEventType(key);
|
||||
this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue));
|
||||
this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
|
||||
eventType = ol.Object.EventType.PROPERTYCHANGE;
|
||||
this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue));
|
||||
this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
|
||||
};
|
||||
|
||||
|
||||
@@ -231,8 +197,41 @@ ol.Object.prototype.unset = function(key, opt_silent) {
|
||||
ol.Object.EventType = {
|
||||
/**
|
||||
* Triggered when a property is changed.
|
||||
* @event ol.ObjectEvent#propertychange
|
||||
* @event ol.Object.Event#propertychange
|
||||
* @api stable
|
||||
*/
|
||||
PROPERTYCHANGE: 'propertychange'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
ol.Object.Event = function(type, key, oldValue) {
|
||||
ol.events.Event.call(this, type);
|
||||
|
||||
/**
|
||||
* The name of the property whose value is changing.
|
||||
* @type {string}
|
||||
* @api stable
|
||||
*/
|
||||
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 stable
|
||||
*/
|
||||
this.oldValue = oldValue;
|
||||
|
||||
};
|
||||
ol.inherits(ol.Object.Event, ol.events.Event);
|
||||
|
||||
Reference in New Issue
Block a user