I am new to JavaScript API. I have a map with a number of feature layers added. I would like to be able to turn on and off these layers through the JavaScript API, yet I cannot seem to find a way to recognize the different layers on the map through the API.
I also asked our developer to get a code snippet that would actually run, verbatim... He commented out the part that we tried to do the layer hiding. This should run as a html file for you if you wanted to try it. We could not get your statment ( esri.arcgisonline.map.main.mapLayers) to run. It through back the error we mentioned previously.
Sorry for taking your time, but thanks again for your previous responses.
This should as an html file... however we had to add a proxy line to our website config to get it to work.
popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 2), new dojo.Color([255, 0, 0, 0.1])) }, dojo.create("div"));
Would it be possible for you to post a complete working set of your code example. That might help me understand why we could not get the statement: "esri.arcgisonline.map.main.mapLayers[0].layer.hide()" to be recognized.
I was speaking with an ESRI employee and he said the layers added this way are actually graphic objects... so he suggested a small change to our code... which works! Thanks so much.
function mapLoaded() {
var layerIds = map.graphicsLayerIds; console.log(layerIds.length); var layer; for (var i=0; i < layerIds.length; i++) { layer = map.getLayer(layerIds); console.log(layer.name); layer.hide(); }