Service Layers

483
1
11-04-2012 12:00 PM
ShaunWeston
Occasional Contributor
I'm just working on a script that turns on/off various layers, which works fine for everything except service layers where I'm having to add and remove them from the document. I'd rather just have service layers in the map document and set visibility to true or false, but this does not seem to work.

So is the visible property not available with service layers? If you had service layers in your map document and wanted to turn them on and off, you can't do that?
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Frequent Contributor
Apparently, yes, it is supported by the layer object, although I don't remember if I've actually used it - for serviceProperties, if supported, it is specifically stated at the below link that there is a return possible for either an ArcSDE dictionary or a Web service dictionary.  For the return on the dictionary key 'ServiceType' for a Web service, the type property can be ImageServer, IMS, MapServer, TiledInternetLayer, WMS, or WCS.  Based on the fact that you can access a Web service layer via the layer object, I don't see why you cannot toggle it on/off (visible: true/false) in a map document.  Don't know if you've tried that already, maybe it isn't supported after all?

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/

So the thing to do is to test support for this property because the 'visible' property doc (at the above link) states:
"Not all layers support the visible property (for example, restricted Web service layers), so it is good practice to test for this ahead of time using the supports method."

If you have the layer object test to see if the 'visible' property is supported, I think like this (if 'lyr' is your layer object):
>>> lyr.supports("VISIBLE")

...or this so at least you'll know whether supported or not:
if lyr.supports("VISIBLE"):
    if lyr.visible:
        lyr.visible = False
        print 'layer visible property toggled off'
    else:
        lyr.visible = True
        print 'layer visible property toggled on'
else:
    print 'layer does not support visible property'


Of course, the above code does not include the preliminary setup for the map doc object, etc., and saving the visible settings to the map doc afterward.  Hope that helps.
0 Kudos