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

915
3
Jump to solution
05-01-2013 12:09 PM
JoanneMcGraw
Occasional Contributor III
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/MapSe.... 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
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
It's a bug. Will fix it.
At this point, you can specifically call setVisibleLayers to turn on the layers.
Hope this helps.

var visibleLayers = response.itemInfo.itemData.operationalLayers[0].visibleLayers; var layer = map.getLayer("MAP_ANR_NRMPCOMPONENTS_WM_NOCACHE_1299"); layer.setVisibleLayers(visibleLayers);

View solution in original post

0 Kudos
3 Replies
JianHuang
Occasional Contributor III
It's a bug. Will fix it.
At this point, you can specifically call setVisibleLayers to turn on the layers.
Hope this helps.

var visibleLayers = response.itemInfo.itemData.operationalLayers[0].visibleLayers; var layer = map.getLayer("MAP_ANR_NRMPCOMPONENTS_WM_NOCACHE_1299"); layer.setVisibleLayers(visibleLayers);
0 Kudos
JoanneMcGraw
Occasional Contributor III
Jian,

Thank you for your response and confirmation that what I was experiencing was a problem in the JSAPI. Should I contact support in reference to this issue to ensure it gets into NIM and is not lost as an item that should be fixed?

Also, the suggested workaround has merit but is fairly specific to my example. It assumes the developer knows the name of the layer whose visibleLayers is incorrect and, further, that there is only one layer within the map where that is the case. For anyone else struggling with the same issue, a more generic piece of code in the callback function would be:

for (var i = 0; i < response.itemInfo.itemData.operationalLayers.length; i++){
    response.itemInfo.itemData.operationalLayers.layerObject.setVisibleLayers(response.itemInfo.itemData.operationalLayers.visibleLayers);
}


Let me know if I should contact support...

Cheers,
jtm
0 Kudos
JianHuang
Occasional Contributor III
No, you don't have to contact technical support. We will fix it and make sure it will be included.
0 Kudos