How can I loop over layer groups/subgroups and print their ids (eg. title) in console.log? this seems to be not working:
map.getLayers().forEach(function(layer) {
if(layer instanceof layer.LayerGroup) {
layer.getLayers().forEach(function(groupLayer) {
layer.textContent = myLayers;
console.log(myLayers);
});
}
});
and this is the group/subgroup/layer structure:
const subgroup1 = new LayerGroup({
title: 'sb1',
fold: 'close',
visible: false,
layers: [
new WebGLTileLayer({
title: 'l1_sb1',
style: bac,
source: new GeoTIFF({
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
new WebGLTileLayer({
title: 'l1_sb2',
style: bac,
source: new GeoTIFF({
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
],
});
const subgroup2 = new LayerGroup({
title: 'sb2',
fold: 'close',
visible: false,
layers: [
new WebGLTileLayer({
title: 'l2_sb1',
style: slo,
source: new GeoTIFF({
normalize: false,
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
new WebGLTileLayer({
title: 'l2_sb2',
style: slo,
source: new GeoTIFF({
normalize: false,
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
],
});
const subgroup3 = new LayerGroup({
title: 'sb3',
fold: 'close',
visible: false,
layers: [
new WebGLTileLayer({
title: 'l1_sb3',
style: tri,
source: new GeoTIFF({
normalize: false,
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
new WebGLTileLayer({
title: 'l2_sb3',
style: tri,
source: new GeoTIFF({
normalize: false,
sources: [{
url: 'raster/xxx.tif',
nodata: 0,
}],
}),
}),
],
});
const analisis = new LayerGroup({
title: 'analisis',
fold: 'close',
layers: [
subgroup1,
subgroup2,
subgroup3,
],
});
Thanks in advance for any pointers,