Solved! Go to Solution.
<!DOCTYPE html> <html> <head> <title>Create a Web Map</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } #layerList{ background-color: #fff; position: absolute !important; z-index: 99; padding:10px; top:10px; right:20px; } </style> <script>var dojoConfig = { parseOnLoad:true };</script> <script src="http://js.arcgis.com/3.7compact/"></script> <script> var map; require([ "esri/map", "esri/arcgis/utils", "dojo/_base/array", "dojo/dom-construct", "dojo/on", "dojo/domReady!" ], function (Map, arcgisUtils, array, domConstruct, on) { arcgisUtils.createMap("f8ec60a8c38047e78571b4b77eb706a4", "mapDiv").then(function (response) { map = response.map //Get the layers in the map. var operationalLayers = response.itemInfo.itemData.operationalLayers; array.forEach(operationalLayers , function(layer){ //create a checkbox and label for each layer in the map var cbox = domConstruct.create("input",{ type: "checkbox", name: layer.title, value: layer.id, checked: layer.visibility },"layerList"); var cbox_label = domConstruct.create("label",{ htmlFor: layer.title, innerHTML: layer.title + "</br>" },"layerList"); //When the checkbox is clicked change the layer visibility on(cbox, "click", function(evt){ //Find the layer based on the layer id var layerid = evt.target.value; var layer = map.getLayer(layerid); layer.setVisibility(evt.srcElement.checked); }); }) }); }); </script> </head> <body> <div id="mapDiv"></div> <div id="layerList"></div> </body> </html>
<!DOCTYPE html> <html> <head> <title>Create a Web Map</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.7/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } #layerList{ background-color: #fff; position: absolute !important; z-index: 99; padding:10px; top:10px; right:20px; } </style> <script>var dojoConfig = { parseOnLoad:true };</script> <script src="http://js.arcgis.com/3.7compact/"></script> <script> var map; require([ "esri/map", "esri/arcgis/utils", "dojo/_base/array", "dojo/dom-construct", "dojo/on", "dojo/domReady!" ], function (Map, arcgisUtils, array, domConstruct, on) { arcgisUtils.createMap("f8ec60a8c38047e78571b4b77eb706a4", "mapDiv").then(function (response) { map = response.map //Get the layers in the map. var operationalLayers = response.itemInfo.itemData.operationalLayers; array.forEach(operationalLayers , function(layer){ //create a checkbox and label for each layer in the map var cbox = domConstruct.create("input",{ type: "checkbox", name: layer.title, value: layer.id, checked: layer.visibility },"layerList"); var cbox_label = domConstruct.create("label",{ htmlFor: layer.title, innerHTML: layer.title + "</br>" },"layerList"); //When the checkbox is clicked change the layer visibility on(cbox, "click", function(evt){ //Find the layer based on the layer id var layerid = evt.target.value; var layer = map.getLayer(layerid); layer.setVisibility(evt.srcElement.checked); }); }) }); }); </script> </head> <body> <div id="mapDiv"></div> <div id="layerList"></div> </body> </html>