How do you dynamically define sublayers?

2048
3
09-16-2012 12:38 PM
AnthonyColby2
New Contributor
I have a service that I can add to the Viewer by including the following in the config.xml.....

       <operationallayers>
            <layer label="Towers" type="dynamic" visible="false" alpha="0.5" url="http://<servername>/ArcGIS/rest/services/CellTowers/MapServer">
                <sublayer id="1" label="3 Mobile"/>
                <sublayer id="2" label="O2"/>
                <sublayer id="3" label="Orange"/>
                <sublayer id="4" label="T Mobile"/>
   <sublayer id="5" label="Vodafone"/>
            </layer>
        </operationallayers>

When works perfectly and shows in the Map Switcher (which is my prefered tool over the Layer List widget) as it shows the top level service and then the five sublayers correctly named as per the defined labels - and each layer can be independantly turned on & off.

Now however, I have a number of other (but very similar) services that I want to add only when a particular widget is opened.  I can successfully add a service, or any of its sublayers individually, in code like this....


celltowerlayer = new ArcGISDynamicMapServiceLayer;
celltowerlayer.name = configXML.celltowerservice.@name;
celltowerlayer.alpha = 0.6;
celltowerlayer.url = celltowerservice;
celltowerlayer.addEventListener(FlexEvent.HIDE, celltowerlayer_hideHandler);
map.addLayer(celltowerlayer);

But how do you define the sublayers provided as part of the dynamic map service on this occasion?

I've read many threads and comments that suggest in 2.5 and prior this may not have been possible (or atleast straightforward).  Has this changed in version 3.0?

Any ideas anyone?

Thanks,

Tony
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Tony,

   Hmm... You are using the sublayer attribute for a purpose other than what it was designed for, so that is why you are having an issue trying to get this to work in action script code. Sublayer was added to the viewer to be able to define a popup for individual layers in a tiled and/or dynamic map service, through the use of poupconfig. Your available options for defining which layers of a dynamic map service are available are few, and most likely not your are hoping for. Your first option id to define the visibleLayers property ( which defines what layers of the map service are visible, this does not mean that the layers not in this array are not added to the map, they are just set to not currently visible). Your second option is to use a layerDefinitions array. This option does allow you to exclude individual features of a layer of a map service (but understand that you provide a SQL statement for each layer or your don't). Still this option is not a simple way of defining which map service layer(s) are or are not added to the map. The final option is to add an individual layer as type feature instead of type dynamic.

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:

0 Kudos
KennyHoran
New Contributor III
I'm looking to do something similar.  My users would like to save the results of an Identify or Search query, so I just convert them to a FeatureLayer and it pops up in the TOC.  After a few queries the TOC gets kinda large though, so I'd like to place them in a hierarchy by category.  I can generate a blank FeatureLayer named "Identify Queries" and "Search Queries" that appears in the TOC, but unfortunately I see no way to attach sublayers to them.

Tony, one approach that may work is to define all of your operationallayers but use the Map Switcher <excludelayer> config option to hide them.  That will load each layer but keep it off the TOC.  Then in your event you can rename the desired layer so that it no longer matches the <excludelayer> entry, causing it to appear.  It just might work.
0 Kudos
AnthonyGiles
Frequent Contributor
Tony,

How is specifying the labels in your sub layer tags any different than naming the layers in the mxd for your service and just adding the whole map service, this allows you to turn individual layers on and off in the map switcher widget.

When you want to add a new service in just have the sub layers named in the mxd as you want them to appear in the application or am I totally missing what you are trying to acheive.

Regards

Anthony

P.S. How is the new job going?
0 Kudos