This thread is getting pretty long and also it looks like it's diverging into separate issues - might soon be time to start new threads for those individual issues.I think your original question was answered some time ago 🙂 I've changed all layers to use the layerToggle method, but am having trouble with the DynamicMapServiceLayer. FeatureLayers work just fine.
What sort of trouble? I need some FeatureLayers that have infoWindows, and some DynamicMapServiceLayers that have labels. (there may be a way to avoid this that I am overlooking).
You could use image-based layers (e.g. dynamic or tiled) for everything then use something like the IdentifyTask to retrieve attributes for display in an InfoWindow and there are some samples for this. Involves a round-trip per Identify operation though, depends on your needs etc. The DynamicMapServiceLayer, called 'boundaries' has an array of layerIDs that are integers from the service REST definition. These are carried over to the HTML checkbox that uses layerToggle. So for layerID = 1, I'm just using layerToggle(['1']).
However, when debugging, the layerIDs gets defined, but unlike with the supermarkets that works, the layer does not get defined during the layerToggle method. I'm stumped.
'boundaries' is a single layer...and you're not providing it with a layerId upon instantiation so the API auto-assigns one:
var imageParameters = new esri.layers.ImageParameters();
imageParameters.layerIds = [0,1,12,13,14,15,16,17,18,19,20,21,22,23];
//You were also missing a ; from the end of the following line:
imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW; //can also be: LAYER_OPTION_EXCLUDE, LAYER_OPTION_SHOW, LAYER_OPTION_INCLUDE
boundaries = new esri.layers.ArcGISDynamicMapServiceLayer(mapservice+"/MapServer", {"imageParameters":imageParameters});
Those layerIds are not any use for client-side referencing, their purpose is to be sent back to the server so that the (single) image generated contains only features from the layers in the service that are in that list. The docs have both DynamicMapServiceLayer and FeatureLayer parts well defined, but not the interaction between them. The problem seems to be using both addLayer and addLayers. I'm using addLayer for the DynamicMapServiceLayer, and it is working fine. I'm using addLayers for FeatureLayer, and it works fine. The two seem conflicted however. All are added in a single JS function, in the order I want, but all the FeatureLayers are drawn above (after) the DynamicMapServiceLayer. Any thoughts before I try overriding?
From the docs: Also, all graphics layers are always on top of TiledMapServiceLayers and DynamicMapServiceLayers....