Changing Services and Layers

538
2
09-17-2010 11:04 AM
JaclynGorman
New Contributor
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.checked) {
            visible.push(inputs.id);
          }
        }
        SPED.setVisibleLayers(visible);
      }

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});
        map.addLayer(layer);
        return layer;
      }

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

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

Any help or advice would be appreciated.  Thanks

Jaclyn
0 Kudos
2 Replies
JaclynGorman
New Contributor
I figured out a work around, but thanks to everyone who visited my post
0 Kudos
AlexGray
New Contributor
What was your solution?
0 Kudos