Add method for retrieving ol.Overlay by id

This commit is contained in:
jonataswalker
2015-10-14 16:55:39 -03:00
parent fce065e185
commit 5dbaeb9ee5
2 changed files with 10 additions and 27 deletions

View File

@@ -467,21 +467,14 @@ ol.Map = function(options) {
event.element.setMap(null); event.element.setMap(null);
}, false, this); }, false, this);
this.overlays_.forEach( this.overlays_.forEach(this.addOverlayInternal_, this);
/**
* @param {ol.Overlay} overlay Overlay.
* @this {ol.Map}
*/
function(overlay) {
this.addOverlayInternal(overlay);
}, this);
goog.events.listen(this.overlays_, ol.CollectionEventType.ADD, goog.events.listen(this.overlays_, ol.CollectionEventType.ADD,
/** /**
* @param {ol.CollectionEvent} event Collection event. * @param {ol.CollectionEvent} event Collection event.
*/ */
function(event) { function(event) {
this.addOverlayInternal(/** @type {ol.Overlay} */ (event.element)); this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element));
}, false, this); }, false, this);
goog.events.listen(this.overlays_, ol.CollectionEventType.REMOVE, goog.events.listen(this.overlays_, ol.CollectionEventType.REMOVE,
@@ -489,7 +482,11 @@ ol.Map = function(options) {
* @param {ol.CollectionEvent} event Collection event. * @param {ol.CollectionEvent} event Collection event.
*/ */
function(event) { function(event) {
this.removeOverlayInternal(/** @type {ol.Overlay} */ (event.element)); var id = event.element.getId();
if (id !== undefined) {
delete this.overlayIdIndex_[id.toString()];
}
event.element.setMap(null);
}, false, this); }, false, this);
}; };
@@ -549,9 +546,9 @@ ol.Map.prototype.addOverlay = function(overlay) {
/** /**
* This deals with map's overlay collection changes. * This deals with map's overlay collection changes.
* @param {ol.Overlay} overlay Overlay. * @param {ol.Overlay} overlay Overlay.
* @protected * @private
*/ */
ol.Map.prototype.addOverlayInternal = function(overlay) { ol.Map.prototype.addOverlayInternal_ = function(overlay) {
var id = overlay.getId(); var id = overlay.getId();
if (id !== undefined) { if (id !== undefined) {
this.overlayIdIndex_[id.toString()] = overlay; this.overlayIdIndex_[id.toString()] = overlay;
@@ -1280,20 +1277,6 @@ ol.Map.prototype.removeOverlay = function(overlay) {
}; };
/**
* This deals with map's overlay collection changes.
* @param {ol.Overlay} overlay Overlay.
* @protected
*/
ol.Map.prototype.removeOverlayInternal = function(overlay) {
var id = overlay.getId();
if (id !== undefined) {
delete this.overlayIdIndex_[id.toString()];
}
overlay.setMap(null);
};
/** /**
* @param {number} time Time. * @param {number} time Time.
* @private * @private

View File

@@ -194,7 +194,7 @@ ol.Overlay.prototype.getElement = function() {
/** /**
* Get the feature identifier which is set on constructor. * Get the overlay identifier which is set on constructor.
* @return {number|string|undefined} Id. * @return {number|string|undefined} Id.
* @api * @api
*/ */