Skip to content

Commit

Permalink
Make getLayers aware of layers in groups (origo-map#1200)
Browse files Browse the repository at this point in the history
* Make getLayers aware of layers in groups

* Update viewer.js

use type instead of layerType

* Update viewer.js

Has to include the layergroup as well

* Update viewer.js

Has to include the layergroup as well

* Update viewer.js
  • Loading branch information
jokd authored Mar 11, 2021
1 parent fc9902d commit 82a84b6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,17 @@ const Viewer = function Viewer(targetOption, options = {}) {
return layers;
};

const getLayer = layerName => getLayers().filter(layer => layer.get('name') === layerName)[0];
const getLayer = function getLayer(layerName) {
const layerArray = getLayers();
if (layerArray.some(layer => layer.get('name') === layerName)) {
return layerArray.find(layer => layer.get('name') === layerName);
} else if (layerArray.some(layer => layer.get('type') === 'GROUP')) {
const groupLayerArray = layerArray.filter(layer => layer.get('type') === 'GROUP');
const layersFromGroupLayersArray = groupLayerArray.map(groupLayer => groupLayer.getLayers().getArray());
return layersFromGroupLayersArray.flat().find(layer => layer.get('name') === layerName);
}
return undefined;
};

const getQueryableLayers = function getQueryableLayers() {
const queryableLayers = getLayers().filter(layer => layer.get('queryable') && layer.getVisible());
Expand Down

0 comments on commit 82a84b6

Please sign in to comment.