Add a method to set the map layers

This commit is contained in:
Tim Schaub
2021-09-21 13:34:35 +00:00
parent b50f4ce107
commit a63735a649
2 changed files with 54 additions and 0 deletions
+17
View File
@@ -847,6 +847,23 @@ class PluggableMap extends BaseObject {
return /** @type {LayerGroup} */ (this.get(MapProperty.LAYERGROUP));
}
/**
* Clear any existing layers and add layers to the map.
* @param {Array<import("./layer/Base.js").default>|Collection<import("./layer/Base.js").default>} layers The layers to be added to the map.
* @api
*/
setLayers(layers) {
const group = this.getLayerGroup();
if (layers instanceof Collection) {
group.setLayers(layers);
return;
}
const collection = group.getLayers();
collection.clear();
collection.extend(layers);
}
/**
* Get the collection of layers associated with this map.
* @return {!Collection<import("./layer/Base.js").default>} Layers.