Add method for retrieving ol.Overlay by id
This commit is contained in:
@@ -557,9 +557,6 @@ ol.Map.prototype.addOverlayInternal = function(overlay) {
|
||||
this.overlayIdIndex_[id.toString()] = overlay;
|
||||
}
|
||||
overlay.setMap(this);
|
||||
goog.events.listen(
|
||||
overlay, ol.Object.getChangeEventType(overlay.getOverlayIdProperty()),
|
||||
this.handleOverlayIdChange_, false, this);
|
||||
};
|
||||
|
||||
|
||||
@@ -1103,28 +1100,6 @@ ol.Map.prototype.handleTileChange_ = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.events.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.Map.prototype.handleOverlayIdChange_ = function(event) {
|
||||
var overlay = /** @type {ol.Overlay} */ (event.target);
|
||||
var id = overlay.getId().toString();
|
||||
var oldId = event.oldValue;
|
||||
if (oldId && oldId != id) {
|
||||
delete this.overlayIdIndex_[oldId];
|
||||
}
|
||||
if (id in this.overlayIdIndex_) {
|
||||
if (this.overlayIdIndex_[id] !== overlay) {
|
||||
delete this.overlayIdIndex_[id];
|
||||
this.overlayIdIndex_[id] = overlay;
|
||||
}
|
||||
} else {
|
||||
this.overlayIdIndex_[id] = overlay;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,6 @@ goog.require('ol.extent');
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.OverlayProperty = {
|
||||
ID: 'id',
|
||||
ELEMENT: 'element',
|
||||
MAP: 'map',
|
||||
OFFSET: 'offset',
|
||||
@@ -78,7 +77,7 @@ ol.Overlay = function(options) {
|
||||
* @private
|
||||
* @type {number|string|undefined}
|
||||
*/
|
||||
this.id_ = undefined;
|
||||
this.id_ = options.id;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -195,8 +194,7 @@ ol.Overlay.prototype.getElement = function() {
|
||||
|
||||
|
||||
/**
|
||||
* Get the feature identifier. This is an identifier for the overlay and
|
||||
* is set explicitly by calling {@link ol.Overlay#setId}.
|
||||
* Get the feature identifier which is set on constructor.
|
||||
* @return {number|string|undefined} Id.
|
||||
* @api
|
||||
*/
|
||||
@@ -229,15 +227,6 @@ ol.Overlay.prototype.getOffset = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Workaround to overcome circular dependency.
|
||||
* @return {ol.OverlayProperty}
|
||||
*/
|
||||
ol.Overlay.prototype.getOverlayIdProperty = function() {
|
||||
return ol.OverlayProperty.ID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the current position of this overlay.
|
||||
* @return {ol.Coordinate|undefined} The spatial point that the overlay is
|
||||
@@ -348,22 +337,6 @@ ol.Overlay.prototype.setElement = function(element) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the feature id. The feature id can be used with the
|
||||
* {@link ol.Map#getOverlayById} method.
|
||||
* @param {number|string} id The feature id.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
ol.Overlay.prototype.setId = function(id) {
|
||||
goog.asserts.assert(id !== undefined, 'overlay id should be defined');
|
||||
if (id != this.id_) {
|
||||
this.id_ = id;
|
||||
this.set(ol.OverlayProperty.ID, id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the map to be associated with this overlay.
|
||||
* @param {ol.Map|undefined} map The map that the overlay is part of.
|
||||
|
||||
Reference in New Issue
Block a user