layer.setLayerVisibility() not working for DynamicMapServiceLayer

Discussion created by greenlaw on Jan 10, 2012
Latest reply on Jan 10, 2012 by greenlaw
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

When I point my code to the sample MapServer given in the example (""), 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
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?