I want to see empty Group Layers in the layers widget, but it seems that it can't be done.
Is there a possibility to see them without adding another layer?
Here is a code sample:
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>
MapImageLayer - Wrong spatialReference
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.22/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.22/"></script>
<script>
/*****************************************************************
*demo code loading service with incorrect spatialReference, result- the layer is loaded but view.when() and view.whenLayerView() are not being triggerd
*and there are no errors
*****************************************************************/
require(["esri/Map",
"esri/views/MapView",
"esri/layers/GroupLayer",
"esri/widgets/LayerList",
"esri/widgets/Expand",
"esri/geometry/SpatialReference"], (
Map,
MapView,
GroupLayer,
LayerList,
Expand,
SpatialReference
) => {
const layer = new GroupLayer();
const map = new Map({
layers: [layer]
});
const view = new MapView({
container: "viewDiv",
map: map,
spatialReference: new SpatialReference({ wkid: 102100 }),
zoom: 3
});
const layerList = new LayerList({
view: view
});
const layersExpand = new Expand({
view: view,
content: layerList,
expandIconClass: "esri-icon-layers",
id: "expandWidget"
});
view.ui.add(layersExpand, "top-right");
layer.when(() => {
console.log('layer loaded')
},
() => {
console.log('failed to load layer')
});
/*****************************************************************
*layer was loaded but this is not getting called and no error callback
*****************************************************************/
view.when(() => {
console.log('view is ready')
}, ()=> {
console.log('view error')
});
/*****************************************************************
* layer view is not created here and we do not get any error
*****************************************************************/
view.whenLayerView(layer)
.then(function (layerView) {
console.log('layer view created')
})
.catch(function (error) {
console.log('creating layer view failed')
});
});
</script>
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#viewDiv {
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 60px;
}
</style>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Thank you
For group layer to visible in LayerList use
I noticed that it is the default value, tried to add it anyway and it doesn't seem to work.
Hi there,
GroupLayer is visible in the LayerList even if it empty. You won't see the arrow to expand to see the layers in the GroupLayer because the layer is empty. If you drag and drop layers into the GroupLayer then you will see the arrow to expand. Not sure if this is what you are talking about.
With your code, you should see this when your app is initialized.
This isn't what i'm talking about.
My issue is that when I try to load empty group layers, I don't see the group layers in the layers widget. I want to see them all the time even if they're empty.
for that matter if i put an empty group layer 'x' in a group layer 'y', I won't see either of them.
By the way - I don't use a basemap and I do not want to use one.