Select to view content in your preferred language

layer.setLayerVisibility() not working for DynamicMapServiceLayer

697
1
01-10-2012 12:25 PM
JasonGreenlaw
Regular Contributor
I initially posted this question in the 10.1 beta forum but thought this might be the better place for it.

I'm having problems toggling the visibility of layers in a dynamically-drawn map service (10.1 beta 2) using the JavaScript API (versions 2.5 and 2.6 behave the same).

I am following the sample described at http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/map_explicitla....

When I point my code to the sample MapServer given in the example ("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map..."), which appears to be at version 10.0, the setLayerVisibility method works fine; however when I point the same code to my own 10.1 beta 2 map service (and modify the layer IDs accordingly), it ceases to work properly.

Using the Service Editor, under Capabilities > Mapping, I've enabled "Allow per request modification of layer order and symbology," but this did not solve the problem. 

The strange thing is that it seems to work partially, because my layer does appear when I first set its visibility (as long as I am at the initial map extent).  But when I pan or zoom, the layer becomes broken and does not redraw at any scale, and if I call
layer.setVisibleLayers([-1]);
to turn all layers off, the layer remains on screen.

The DynamicMapServiceLayer displays fine if I specify the visible layer IDs in the ImageParameters property during construction, but as soon as I call setVisibleLayers() it becomes broken.

Very strange behavior.  A bug in 10.1 or the JavaScript API I wonder?

Jason
0 Kudos
1 Reply
JasonGreenlaw
Regular Contributor
Sorry - the title of this thread should read "layer.setVisibleLayers() ...", not "setLayerVisibility() ...".
0 Kudos