Layerlist widget with only one layer can be expanded

1955
15
06-12-2018 11:44 AM
HelenZhou
Occasional Contributor II

Hello,

I have a customized widget which load several layers:

            array.forEach(this.config.layers, function (layer) {
                        this.addLayerToMap(layer);
                }, this);

When I open the LayerList widget (the build-in widget from web appbuilder 2.8 - Layer List widget—Web AppBuilder for ArcGIS | ArcGIS ), only one layer can be expanded. With the same code, if the "layers" array only has one layer, this layer is expandable in the LayerList widget. Does anybody else has the same issue? Can LayerList be customized to work when multiple layers added at a time?

Thanks so much

Helen

Tags (2)
0 Kudos
15 Replies
HelenZhou
Occasional Contributor II

Robert, One more note - No customization for Layer list and Legend - they are build-in from Web Appbuilder 2.8. Thanks

Helen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   What I am saying is that if you use an OTB widget not custom code to add your layers you will not encounter this issue so the issue has to be in your code for adding the multiple layers. Maybe it is the fact that you are adding the layers in a loop and the layerlist widget does not have enough time to catch the changes. One way to test my theory is to add a setTimeout before you add the next layer. Another thing I would try is to get a reference to the Layer List widget and call it's layerListView.refresh() method.

0 Kudos
HelenZhou
Occasional Contributor II

Thanks Robert, I have setTimeout when loading a layer. It still behaves the same - only one layer is expandable. I will dig more in the layerlist widget code to see how the refresh is triggered.

Helen

0 Kudos
HelenZhou
Occasional Contributor II

Hi Robert,

I have had another finding. Your identify wdiget in my WAB application only display feature information for expandable loaded maps services. I am able to debugging your identify widget.js and find out that problem layers have newSubLayer length = 0.  So I am guessing in the WAB, there is an event triggered when new layers are added - something like LayerInfosChange in jimu. The change event has effects on all widgets which use map's operLayerInfos across in WAB applications, including layerlist, legend and identify, maybe others. Do you know if such an event exists?

Thanks

Helen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   In the jimu\LayerInfos\LayerInfos.js there is the _bindEvents function that listens for new layers being added to the map.

handleAdd = on(this.map, "layer-add-result", lang.hitch(this, this._onLayersChange, clazz.ADDED));
0 Kudos
arunepuri1
New Contributor III

Hi Helen,

I was having the same issue as you mentioned and I was able to resolve the issue by using below code.

Issue: When adding multiple ArcGISDynamicMapServiceLayer to the map. The layers in LayerList widget expand only one layer and rest won't expand.

Reason: As Robert mentioned when you are adding multiple layers at the same time, layer nodes are not added.

Solution:

//Create an array to hold all new layers

this.dynamicLayers = [];

//Add all dynamic layer to array

this.dynamicLayers.push(dynamicLayer1);

this.dynamicLayers.push(dynamicLayer2);

this.dynamicLayers.push(dynamicLayer3);

this.dynamicLayers.push(dynamicLayer4);

if (this.dynamicLayers.length > 0) {
//setTimeout is requried for multiple dynamic layer, else layer list node expand issue is there.
setTimeout(lang.hitch(this, function () {

//Use addLayers() to add multiple layers.
this.map.addLayers(this.dynamicLayers);
}), 500);
}

Regards,

Arun E

0 Kudos