Layerlist widget with only one layer can be expanded

1954
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
RobertScheitlin__GISP
MVP Emeritus

Helen,

   What errors if any are present in the web console when you try to expand those?

0 Kudos
HelenZhou
Occasional Contributor II

Hi Robert, I don't see any error message in the web debug window's console section. I have noticed that in LayerListView.js file, only one layer's sublayer goes to line 100 to place subnode.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

That means when it is looping through the new layers you added it does not see any sublayers for them. Is that not the case for those layers?

0 Kudos
HelenZhou
Occasional Contributor II

Robert, The map service has sublayers (at least one). if I use the same code and assign only one layer to the layers array (the same layer that has issue being expanded), the layer listed in the layerlist is able to be expanded.

In the screenshot before, Zoning Info is not expandable when added with other layers the same time. When manually add one value to the "Layer" array. It is expandable.Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   Strange I have never seen that behavior. How are those layers being added to the map? Is it through a custom widget or code?

0 Kudos
HelenZhou
Occasional Contributor II

It is through a customized widget that I customized from the Addlayer widget (AddLayer Widget ). The original widget is used to add one layer when a check box is checked. It works with the layerlist which expands the layer node. What I have customized is to add a dijit/form/Select above the layer list in the widget.html. When the value changes in the select, a few map services are added to the map. The map services are added to the map in a loop. I have also noticed that Web AppBuilder build-in Legend widget only display the legend for the layer which is expandable in the layerlist widget.

Here is the code which load a few map services. addLayerToMap is reused from the original code. Themelayers is the array of IDs for map services which will be loaded in the map.

              array.forEach(this.config.layers, function (layer) {
                    if (themeLayers.indexOf(layer.name) != -1) //find the fire
                    {
                        //1. Check box checked
                        var cb = registry.byId(layer.name);
                        cb.setValue(true);
                        //2. Load layer to map
                        this.addLayerToMap(layer);
                    }
                }, this);

The screenshot below shows when Planning is selected, map services "Other Info", "Small CellInfo", "Trans Plan Info" are loaded to the map.

0 Kudos
HelenZhou
Occasional Contributor II

Robert,

After further debugging, I found that in LayerListView,js, the layer that is expandable has newSubLayers length >0. And the layer that is non-expandable has the newSubLayers length property as 0. The layer is loaded as map service which obviously has at least one sublayer.

As I said before, when I load only one map service (same map service url), the newSubLayer length is > 0.

Do you know what will be the reason?

Thanks

Helen

Load with other map services

VS - load as the only map service

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   It has to be something in your code with the layer creation or the addLayerToMap function then.

0 Kudos
HelenZhou
Occasional Contributor II

Hello Rober,

Thanks for help, It doesn't look like the customized code has something. I have created a very simple WAB application at this location Test LayerList WAB 

If I select add one map service from the drop down list, 911 is added to the map which is expandable. But I I choose add 2 map services from the drop down list, USA and Census are added to the map, only one layer is expandable. It looks random, my IE has USA expandable and Google has Census expandable.And the legend only lists the layers that are expandable.

I have changed my code to be this simple by loading map service url this way-                           

         var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
                {"id" : "census", opacity: 0.5});

                this.map.addLayer(dynamicMapServiceLayer);             

Thanks so much for help.

Helen

0 Kudos