AnsweredAssumed Answered

Toggle layers error

Question asked by mcdade31 on Aug 27, 2012
Latest reply on Aug 27, 2012 by mcdade31
I have added code from the Dynamically Create Layer List sample to my app. It works as expected, except, it loads without my basemap.

I have a switch basemap dropdown that still populates with all the ESRI basemaps, however, they don't load when clicked. When I do click on one, it eliminates my DynamicMapServiceLayer.

I added the following in the init():

layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisprod2/arcgis/rest/services/Dynamic/CountyTest/MapServer");          if (layer.loaded) {           buildLayerList(layer);         }         else {           dojo.connect(layer, "onLoad", buildLayerList);         }


and then separate functions of:
function buildLayerList(layer) {         var items = dojo.map(layer.layerInfos,function(info,index){           if (info.defaultVisibility) {             visible.push(info.id);           }           return "<input type='checkbox' class='list_item'" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label>";         });          dojo.byId("layer_list").innerHTML = items.join(' ');          layer.setVisibleLayers(visible);         map.addLayer(layer);        }        function updateLayerVisibility() {         var inputs = dojo.query(".list_item"), input;              visible = [];          dojo.forEach(inputs,function(input){           if (input.checked) {               visible.push(input.id);           }           });         //if there aren't any layers visible set the array to be -1         if(visible.length === 0){           visible.push(-1);         }         layer.setVisibleLayers(visible);       }


I get the following error in Chrome Developer Tools when I try to switch basemap
1. Resource interpreted as Script but transferred with MIME type tex/plain: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

Any ideas why the basemaps will not load initially or switch?

Outcomes