Changing Services and Layers

Discussion created by jmgorman on Sep 17, 2010
Latest reply on Oct 6, 2010 by agray7501
Basically I am trying to turn on/off layers in a dynamic service and have the functionality to toggle between tiled services. The problem I am having is that I think the code I am using to toggle between tiled services, which comes from the esri sample code, is turning off the dynamic layers. If I turn on/ off the dynamic layers before I change the tiled service the dynamic work fine.  Once I toggle between the 2 tiled services the dynamic layer stops working.  I am having trouble figuring out how to avoid this.

I am using the following function to update layer visibility for the dynamic layers:

function updateLayerVisibilitySPED() {
        var inputs = dojo.query(".list_item"), input;
        //in this application layer 0 is always on.
        visible = [0];
        for (var i=0, il=inputs.length; i<il; i++) {
          if (inputs[i].checked) {

Then I was using the following for the switching of the titled layers (I am pretty sure it is hiding the dynamic layer but I am not sure how to write the code to exclude it):

function initLayer(url, id) {
        var layer = new esri.layers.ArcGISTiledMapServiceLayer(url, {id:id, "opacity":0.3, visible:false});
        return layer;

      function changeMap(layers) {
        for (var i=0; i<layers.length; i++) {

      function hideImageTiledLayers(layers) {
        for (var j=0, jl=map.layerIds.length; j<jl; j++) {
          var layer = map.getLayer(map.layerIds[j]);
          if (dojo.indexOf(layers, layer) == -1) {

Any help or advice would be appreciated.  Thanks