AnsweredAssumed Answered

Hide Tiled Layer Using Array

Question asked by cleotokos on Jan 20, 2016
Latest reply on Jan 20, 2016 by JimmyKroon

Hi all, I'm not sure where I'm going wrong. I have many many ArcGISTiledMapServiceLayers in my map that need to be hidden/shown en masse. So I created an array containing the names of each layer, and would like to use a loop to go through the array and hide each element.

 

var swipeLayerOrthos2015 = new ArcGISTiledMapServiceLayer("http://cop-gis4:6080/arcgis/rest/services/Orthos/Orthos2015_WGS1984_MIXED/MapServer");
        var swipeLayerOrthos2014 = new ArcGISTiledMapServiceLayer("http://cop-gis4:6080/arcgis/rest/services/Orthos/Orthos2014_WGS1984_MIXED/MapServer");
        var swipeLayerOrthos2014RB = new ArcGISTiledMapServiceLayer("http://cop-gis4:6080/arcgis/rest/services/Orthos/Orthos2014RB_WGS1984_MIXED/MapServer");

var orthoArray = [];

orthoArray.push('swipeLayerOrthos2015', 'swipeLayerOrthos2014', 'swipeLayerOrthos2014RB');

updateOrthos();

function updateOrthos(){       
        var targetOrtho;
       
        for (var i = 0; i < orthoArray.length; i++) {
            targetOrtho = orthoArray[i];
            targetOrtho.hide();
         }
    }

When I run this, I get an 'Uncaught TypeError: targetOrtho.hide is not a function'

 

I'm not sure what I'm doing wrong, if I change things so that a variable holds the ortho's name and then hide that, it works ie.

 

var targetOrtho = swipeLayerOrthos2010;

targetOrtho.hide();

 

Works just fine. I'm not sure how my loop is really different from that. I've tried printing out each item in orthoArray to the console and it looks ok to me. Does anyone see what I'm missing? I can make a jsfiddle if the above isn't clear.

Outcomes