Select to view content in your preferred language

group layers and visibility of sublayers

1630
1
04-05-2011 09:00 PM
DrewDowling
Frequent Contributor
I'm having an issue with turning on and off layers. I am programmatically swapping between different group layers. The problem is that all all sub layers in a group layer turn on, not just those that are already set to visible.

I have tried to loop through the sub layers adding only the ones I want to the visibilelLayers array but when the map redraws all the layers are turned on. I know my looping works because I look at the visibileLayers array in the debugger and the correct ids are present but at some stage this get overwritten and all the sublayer ids are returned by the server

Is this default behavior and is there a way around it?

I have included my code below. I have a function that takes a layerInfo object and adds its id to the visibileLayers array. It then loops through the sublayers array and if the default visibility is true it also adds the sublayer to the visibileLayers.



            private function addLayer(layerInfo:LayerInfo):void
            {
                SiteProfileService.visibleLayers.removeAll();
                SiteProfileService.visibleLayers.addItem(layerInfo.id);
                 if ( layerInfo.subLayerIds.length > 0)
                {
                    var sublayers:Array = layerInfo.subLayerIds;
                    for (var i:int = 0; i < sublayers.length; i++)
                    {
                        trace (SiteProfileService.layerInfos[sublayers].name);
                        trace (SiteProfileService.layerInfos[sublayers].defaultVisibility);

                        if (SiteProfileService.layerInfos[sublayers].defaultVisibility == true)
                        {
                            SiteProfileService.visibleLayers.addItem(sublayers);
                        }
                        else
                        {
                            var idIndex:int = SiteProfileService.visibleLayers.getItemIndex(sublayers);
                            if (idIndex != -1)
                            {
                                SiteProfileService.visibleLayers.removeItemAt(idIndex);
                            }
                        }
                    }
                }
               
            }
Tags (2)
0 Kudos
1 Reply
DrewDowling
Frequent Contributor
OK figured it out. When a group layer is toggled on all sub layers are turned on automatically. If this is not the desired behavior do not toggle on the group layer, instead toggle on just the desired sub layers. Sub layers will be visible even when the parent layer is not part of the visibleLayers array.

I didn't see this documented anywhere and it is different behavior than ArcMap.
0 Kudos