AnsweredAssumed Answered

esri.arcgis.utils.createMap: Is Default Visibility obstructing Dynamic Layer display?

Question asked by myESRIUName on May 1, 2013
Latest reply on May 2, 2013 by Jian
I have created two Web Maps in ArcGIS Online that point to the Map Service http://anrmaps.vermont.gov/arcgis/rest/services/map_services/MAP_ANR_NRMPCOMPONENTS_WM_NOCACHE/MapServer. That Map Service "supports dynamic layers" and most layers' default visibility is set to false. Only Town Boundary (22) is set to true. The first Web Map (http://www.arcgis.com/home/webmap/viewer.html?webmap=007aebfe9bd44795b80165a8f1869d41) shows the layer that is visible by default (22: Town Boundary). The second Web Map (http://www.arcgis.com/home/webmap/viewer.html?webmap=d96c2c13889a495eb56ac9c24624f189) shows a layer that is not visible by default (7: SN8 - Wetlands).

When I use esri.arcgis.utils.createMap to add the first Web Map to a web page, the Web Map is displayed correctly. When I try to view the second Web Map, no layer is visible from the MAP_ANR_NRMPCOMPONENTS_WM_NOCACHE Map Service. You can try this with the following sample code (see the "TODO"s: Update the proxy settings; and, Toggle which Web Map to display by un-/commenting the createMap parameter):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <title>Create Map</title>     <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css" />     <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/tundra/tundra.css" /> <style>       html, body { height: 100%; width: 100%; margin: 0; padding: 0; } </style>     <script type="text/javascript">var djConfig = {parseOnLoad: true};</script>     <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.4compact"></script> <script type="text/javascript"> dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.arcgis.utils"); dojo.require("dijit.form.Button");  var map = null;  function init() {      // TODO:     // 1. Update the proxy's URL for your configuration; and,     // 2. Add an entry in the proxy script for: "http://anrmaps.vermont.gov/arcgis/rest/services/"      esri.config.defaults.io.proxyUrl = "/proxy/proxy.php";       // TODO:     // Un-/comment the createMap parameter to indicate which Web Map to load      var mapDeferred = esri.arcgis.utils.createMap(         "007aebfe9bd44795b80165a8f1869d41"          // using visible layer //        "d96c2c13889a495eb56ac9c24624f189"        // using not visible layer         ,"map"         ,{             mapOptions: {                 wrapAround180:true             }         }     );     mapDeferred.addCallback(         function(response) {             map = response.map;         }     );      dojo.connect(         dijit.byId("myDebugger")         ,"onClick"         ,function(){             debugger; // to view map object         }     ); } dojo.addOnLoad(init); </script>   </head>   <body>     <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;">       <button id="myDebugger" dojotype="dijit.form.Button" region="top">Debug</button>       <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="border:1px solid #000;padding:0;"></div>     </div>   </body> </html>


When I look at the arcgis.com JSON response for the Web Map in Fiddler (http://www.arcgis.com/sharing/rest/content/items/d96c2c13889a495eb56ac9c24624f189/data?f=json), the operationalLayers' visibleLayers property is correctly set to 7.  But, after the map is loaded, if I look at the map object in the debugger (use the Debug button at the top of the page), it's _layers' MAP_ANR_NRMPCOMPONENTS_WM_NOCACHE_1299.visibleLayers is an empty array.

What reasons might explain why the visibleLayers value is not maintained properly here? Or, is it just that the Map Service's default visibility is overriding the Web Map's settings in this regard?

Cheers,
jtm

Outcomes