Group layers and the Flex viewer

4347
18
11-10-2010 11:33 PM
RaymondBlack
New Contributor
Hi,
I have a map service with more than 30 layers grouped into several categories.  Some of these groups also have sub-groups i.e. the hierarchy contains several levels.  It appears that the Flex viewer does not honour the visibility settings of the parent (group) layer.  For example if I have a group layer called Biodiversity and have several scale dependent children of this layer, whenever I zoom in, the child layers switch on automatically even if the parent (group) layer is switched off.  It seems as if the flex viewer only looks at the visibility parameter of the individual layers - not at the visibility parameters of the entire hierarchy.  This is completely counter-intuitive and indeed counter-productive since the viewer is spending inordinate amounts of time drawing layers that are not required.  Needless to say it also generates a lot of confusion among users.  Does anyone know how to correct this behaviour?  I'm assuming it's a bug with the flex map component in that it doesn't traverse the layer tree to discover the visibility parameters of parent layers?

Note: All the grouping and default visibility in this example is set in the .mxd.

Thanks,

Raymond Black
Tags (2)
0 Kudos
18 Replies
RaymondBlack
New Contributor
Mea culpa,

It isn't the Flex Map that's causing the problem.  It's the Layer List widget.  Everything is fine until I select or deselect something on the widget.  I guess it's when the widget rereads the list of visible layers that it switches everything on and ignores the group hierarchy.

Now that I know what it is, I'l have a go at fixing it!  (Unless of course someone else already has a fix 😉 )

++ Ray
0 Kudos
BjornSvensson
Esri Regular Contributor
FYI - In Flex Viewer 2.1, as you've noticed, there are a few different issues with both default visibility for group layers and for turning on/off group layers.  For version 2.2, we are planning to take advantage of a new legend component (and make sure that it works properly with group layers).
0 Kudos
RaymondBlack
New Contributor
Thanks Bjorn,

I look forward to the update in version 2.2.  The legend is another problem that I have on my to-do list, so the fact that the next release will address this too will be very helpful.

++ Ray
0 Kudos
RaymondBlack
New Contributor
Hi Bjorn,

I agree with Andrea.  This morning I tried the Flex 2.2 viewer (with Flex 2.2 API library) against an ArcGIS 10 map server with multiple group layers and there is no difference in operation between this version and the last one.  If I switch on (or off) any of the group layers ALL the sub layers in other groups are drawn - even if their Group header is switched OFF.

Further, the legend widget doesn't work at all.  I just get the icon that says it couldn't find any operational layers - despite the fact that the layerlist widget can find them with out any difficulty.  Also if I close the legend widget, it cannot be opened again.

I checked the documentation to see if there was something I was missing in the configuration.  If I am missing anything it's missing in the documentation also.  Looks like we're using the release before test methodology.

++ Ray
0 Kudos
MarkSmith1
Occasional Contributor
I'm just trying out the Legend widget for the first time today and I notice that unless the operational layer is a "feature" layer it isn't showing up in the legend. I have a couple of dynamic mapservices in my operational layer list and they have a single data frame with 3 - 4 layers in them.

Is this a bug or is it by design?
0 Kudos
MehulChoksey
Esri Contributor
Here is more info on layers supported by legend widget and requirements for it:

http://help.arcgis.com/en/webapi/flex/apiref/index.html?com/esri/ags/components/Legend.html&com/esri...

especially note this excerpt from doc:
"If the layers are version 10 or lower the legend is created using the  ArcGIS.com legend service.  In order to use the ArcGIS.com legend service your map service needs to  be publicly accessible and your application must be able to access  ArcGIS.com."

and more info on legend widget is at  http://help.arcgis.com/en/webapps/flexviewer/help/Default.htm#CSHID=widgets%2Flegend_widget.htm|Star...

Also note that by default the layers from the basemap are not used for displaying legend.You will need to set <usebasemaps> to true in  config file of the legend widget. Hope this helps.
0 Kudos
MarkSmith1
Occasional Contributor
Thanks. I applied Service Pack 1 and now the dynamic map layers are showing up.

Mark
0 Kudos
RameshNarayan
New Contributor
Hi all,

I fixed the group layers toggle issue.
Added below if condition before "for loop" in "accumVisibleLayers()" funtion of "TocMapLayerItem.as". and it's working fine for me.

if(item.visible)
{
}
------------------------------------------------
file path : src\com.esri.viewer\components\toc\tocClasses\TocMapLayerItem.as
below is the modified function

private function accumVisibleLayers(item:TocItem, accum:Array, useLayerInfoName:Boolean = false):void
    {
        if (item.isGroupLayer())
        {
            // Don't include group layer IDs/names in the visible layer list, since the ArcGIS REST API
            // implicitly turns on all child layers when the group layer is visible. This goes
            // counter to what most users have come to expect from apps, e.g. ArcMap.
          
            //Added by Kiran to fix the group layers toggle issue
if(item.visible)
{
             for each (var child:TocItem in item.children)
             {
                 accumVisibleLayers(child, accum, useLayerInfoName);
             }
}
        }
        else
        { // Leaf layer
            if (item.visible)
            {
                if (item is TocLayerInfoItem)
                {
                    var layer:TocLayerInfoItem = TocLayerInfoItem(item);
                    accum.push(useLayerInfoName ? layer.layerInfo.name : layer.layerInfo.id);
                }
            }
        }
    }

---------------------------------------------------------------------

Thanks & Regards,
Kiran M
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Kiran,

   Great Job! Finally with esri's changes in 2.2 and your code the TOC finally operates as expected.
0 Kudos