Select to view content in your preferred language

Getting the visible layers

758
2
06-16-2010 01:22 PM
TomasDonda
New Contributor
Hello everyone. First of all excuse me if I do something wrong but´s the first time I ask something in a forum, i´m kinda newbie...
My problem is that I have a project with a ArcGISDynamicMapServiceLayer and this service turns on and off the layers according to the scale. I want to get a string of all the layers that are visible at a determined moment, for example, I´m looking at the map at an x scale, I click a button and I want to see the layers that are on at that moment.
Is this possible? So far I´ve tried with the following code but I get all the layers, not only the ones that are visible:

private void getListOfVisibleLayers()
        {
            string visibLayers = "";
            StringBuilder sbVisibleLayers = new StringBuilder();
            sbVisibleLayers.Append("&layersVisib=");

ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer serviceLayer =
(ArcGISDynamicMapServiceLayer)MyMap.Layers["PAE"];

            ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = serviceLayer.Layers;

            for (int index = 0; index < layerInfoArray.Length; index++)
            {
                if (layerInfoArray[index].DefaultVisibility == true)
                {
                    sbVisibleLayers.Append(layerInfoArray[index].Name);
                    sbVisibleLayers.Append(";");
                }
            }

            visibLayers = sbVisibleLayers.ToString();
        }

If you have any idea that could help me it would be great, if not, never mind. Thanks for all!
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
The scale info is available by the REST API  (e.g. http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4?...) but is not available out of the box with the Silverlight API (performance issue). You have to request the rest end point by yourself.

jgalang posted a nice TOC sample (http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=168...) which displays the TOC in a tree view and respects the scale dependencies. I guess he did almost what you are trying to do.
0 Kudos
TomasDonda
New Contributor
Thanks Dominique, all these things you showed me were really usefull. If someone else has this doubt, you´ll gotta know there´s no direct method. You´ll have to detect in which scale the user is (using the resolution) and from there see which layers are visible at that current range.

KND
0 Kudos