Change signature of ol.layer.Group#getLayers

This commit changes the signature of ol.layer.Group#getLayers from {ol.Collection.<ol.layer.Base>|undefined} to {!ol.Collection.<ol.layer.Base>}. In this way the caller is guaranteed that getLayers returns a dereferencable object.
This commit is contained in:
Éric Lemoine
2014-09-05 12:24:05 +02:00
committed by Frederic Junod
parent bfef6ab075
commit 96f7d6323a
2 changed files with 5 additions and 7 deletions

View File

@@ -56,7 +56,7 @@ ol.layer.Group = function(opt_options) {
ol.Object.getChangeEventType(ol.layer.GroupProperty.LAYERS),
this.handleLayersChanged_, false, this);
if (goog.isDef(layers)) {
if (goog.isDefAndNotNull(layers)) {
if (goog.isArray(layers)) {
layers = new ol.Collection(goog.array.clone(layers));
} else {
@@ -145,13 +145,13 @@ ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) {
/**
* @return {ol.Collection.<ol.layer.Base>|undefined} Collection of
* @return {!ol.Collection.<ol.layer.Base>} Collection of
* {@link ol.layer.Layer layers} that are part of this group.
* @observable
* @api stable
*/
ol.layer.Group.prototype.getLayers = function() {
return /** @type {ol.Collection.<ol.layer.Base>|undefined} */ (this.get(
return /** @type {!ol.Collection.<ol.layer.Base>} */ (this.get(
ol.layer.GroupProperty.LAYERS));
};
goog.exportProperty(
@@ -161,7 +161,7 @@ goog.exportProperty(
/**
* @param {ol.Collection.<ol.layer.Base>|undefined} layers Collection of
* @param {!ol.Collection.<ol.layer.Base>} layers Collection of
* {@link ol.layer.Layer layers} that are part of this group.
* @observable
* @api stable

View File

@@ -495,7 +495,6 @@ ol.Map.prototype.addInteraction = function(interaction) {
*/
ol.Map.prototype.addLayer = function(layer) {
var layers = this.getLayerGroup().getLayers();
goog.asserts.assert(goog.isDef(layers));
layers.push(layer);
};
@@ -703,7 +702,7 @@ goog.exportProperty(
/**
* Get the collection of layers associated with this map.
* @return {ol.Collection.<ol.layer.Base>|undefined} Layers.
* @return {!ol.Collection.<ol.layer.Base>|undefined} Layers.
* @api stable
*/
ol.Map.prototype.getLayers = function() {
@@ -1147,7 +1146,6 @@ ol.Map.prototype.removeInteraction = function(interaction) {
*/
ol.Map.prototype.removeLayer = function(layer) {
var layers = this.getLayerGroup().getLayers();
goog.asserts.assert(goog.isDef(layers));
return layers.remove(layer);
};