<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Legend with Visible Layers - how to modify for sublayers? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207244#M19265</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Shuping,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the code.&amp;nbsp; It does as you say and adds checkboxes for all sublayers.&amp;nbsp; But did you notice that the legend is tripled?&amp;nbsp; It puts the same layers in the legend three times in a row.&amp;nbsp; I think this is a step in the right direction regarding the checkboxes though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Jul 2012 18:40:12 GMT</pubDate>
    <dc:creator>CurtWalker</dc:creator>
    <dc:date>2012-07-12T18:40:12Z</dc:date>
    <item>
      <title>Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207237#M19258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/widget_legendvisible.html"&gt;this tutorial&lt;/A&gt;&lt;SPAN&gt; to create a map with legend and checkboxes for turning layers on and off.&amp;nbsp; Currently it only gives one checkbox per map service if you are using a Dynamic Map Service (which I am because I need labels and Feature Layers do not support labels).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I modify this code so it gives a checkbox for every sublayer in the Dynamic Map Service instead of just one checkbox that turns everything on/off?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 11:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207237#M19258</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-12T11:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207238#M19259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/map_explicitlayerlist.html"&gt;this tutorial&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; I was trying to do what you're doing and this sample helped me put something together.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 12:50:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207238#M19259</guid>
      <dc:creator>BrettGreenfield__DNR_</dc:creator>
      <dc:date>2012-07-12T12:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207239#M19260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, I tried that one and it did give me a checkbox for each sublayer, but the problem is the legend doesn't update when you toggle layers on and off.&amp;nbsp; It seems load once when the maps loads and never refreshes.&amp;nbsp; I tired looking for another event for it to listen on that's fired when you toggle a sublayer's checkbox but I couldn't make it work.&amp;nbsp; How did you do it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 13:02:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207239#M19260</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-12T13:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207240#M19261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually, I ran into that same problem!&amp;nbsp; I pored over a lot of the help topics and they all claimed that the legend is supposed to update automatically when the layer visibility changed, but that never worked for me.&amp;nbsp; If anyone has an answer to it, I'd love to know!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 15:15:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207240#M19261</guid>
      <dc:creator>BrettGreenfield__DNR_</dc:creator>
      <dc:date>2012-07-12T15:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207241#M19262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, I just discovered that my legend will update if I zoom the map in or out after toggling a checkbox.&amp;nbsp; Better but still not great.&amp;nbsp; The user shouldn't have to do that.&amp;nbsp; So whatever even is fired with the map zooms in or out is also refreshing the legend.&amp;nbsp; If we can figure out what that is, or otherwise set that function to do a small zoom automatically when a checkbox is toggled, then I guess I could live with that.&amp;nbsp; I'm still working on it....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 16:22:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207241#M19262</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-12T16:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207242#M19263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To change the visibility of each individual layer of a map service, you need to work with the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/arcgisdynamicmapservicelayer.htm#setVisibleLayers" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGISDynamicMapServiceLayer.setVisibleLayers()&lt;/A&gt;&lt;SPAN&gt; method. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample I put together to demonstrate how to toggle the visibility of each individual layer of a map service by using check box. Hope this helps to get you start.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&amp;gt;
&amp;lt;html&amp;gt;
&amp;nbsp; &amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--The viewport meta tag is used to improve the presentation and behavior of the samples
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on iOS devices--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;Updating the legend to display visible layers&amp;lt;/title&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.0/js/dojo/dijit/themes/claro/claro.css"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;style&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; html, body { height: 98%; width: 98%; margin: 0; padding: 5px; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #rightPane{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width:20%;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #legendPane{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; border: solid #97DCF2 1px;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/style&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;var djConfig = {parseOnLoad: true};&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.0"&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.BorderContainer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.ContentPane");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.AccordionContainer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.map");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.dijit.Legend");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.arcgis.utils");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.form.CheckBox");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var map;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendLayers = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendLayer;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function init() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var initialExtent = new esri.geometry.Extent({"xmin":-117.98,"ymin":33.95,"xmax":-116.92,"ymax":34.44,"spatialReference":{"wkid":4326}});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = new esri.Map("map", { extent: esri.geometry.geographicToWebMercator(initialExtent)});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Add the terrain service to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&amp;amp;f=typekeywords:service&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(basemap);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var quakeLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer",{id:'quakes'});

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legendLayers.push({layer:quakeLayer,title:'Earthquakes'});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var fireLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer",{id:'fire'});

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legendLayers.push({layer:fireLayer,title:"Fire"});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map,'onLayersAddResult',function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legend = new esri.dijit.Legend({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map:map,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerInfos:legendLayers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },"legendDiv");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.startup();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayers([fireLayer,quakeLayer]);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map,'onLayersAddResult',function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var layerLists=[];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;&amp;nbsp; dojo.forEach(legendLayers,function(layer){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerLists.push(buildLayerList(layer));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.byId("layer_list").innerHTML = layerLists.join('');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map, 'onLoad', function(theMap) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //resize the map when the browser resizes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt; function buildLayerList(layer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var visible = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var items = dojo.map(layer.layer.layerInfos,function(info,index){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (info.defaultVisibility) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(info.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "&amp;lt;input type='checkbox' class='" + layer.title + "' checked='true' id='" + info.id + "' onclick='updateLayerVisibility();' /&amp;gt;&amp;lt;label for='" + info.id + "'&amp;gt;" + info.name + "&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.layer.setVisibleLayers(visible);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return items.join(' ');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function updateLayerVisibility() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(legendLayers,function(layer){&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var inputs = dojo.query("."+ layer.title), input;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var visible = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(inputs,function(input){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (input.checked) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(input.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if there aren't any layers visible set the array to be -1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(visible.length === 0){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(-1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.layer.setVisibleLayers(visible);&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.addOnLoad(init);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/script&amp;gt;
&amp;nbsp; &amp;lt;/head&amp;gt;
 
&amp;nbsp; &amp;lt;body class="claro"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="content" dojotype="dijit.layout.BorderContainer" design="headline" gutters="true" style="width: 100%; height: 100%; margin: 0;"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="rightPane" dojotype="dijit.layout.ContentPane" region="right"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.AccordionContainer"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.ContentPane" id="legendPane" title="Legend"&amp;nbsp; selected="true"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="legendDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.ContentPane" title="Natural Disasters" &amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;span style="padding:10px 0;" id="layer_list"&amp;gt;&amp;lt;/span&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="toggle" style="padding: 2px 2px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;lt;/body&amp;gt;
 
&amp;lt;/html&amp;gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:14:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207242#M19263</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2021-12-11T10:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207243#M19264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To change the visibility of each individual layer in the map, you need to work with the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/arcgisdynamicmapservicelayer.htm#setVisibleLayers" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGISDynamicMapServiceLayer.setVisibleLayers()&lt;/A&gt;&lt;SPAN&gt; method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To change the visibility of each individual layer in the legend control, you need to work with the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/legend.htm#hideLayers" rel="nofollow noopener noreferrer" target="_blank"&gt;Legend.hideLayers&lt;/A&gt;&lt;SPAN&gt; property. Then follow by calling &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/legend.htm#referesh" rel="nofollow noopener noreferrer" target="_blank"&gt;Legend.fefresh()&lt;/A&gt;&lt;SPAN&gt; method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a sample I put together to demonstrate how to toggle the visibility of each individual layer of a map service by using check box. The corresponding legend will auto-update itself in the legend control. Hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&amp;gt;
&amp;lt;html&amp;gt;
&amp;nbsp; &amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--The viewport meta tag is used to improve the presentation and behavior of the samples
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on iOS devices--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;Updating the legend to display visible layers&amp;lt;/title&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.0/js/dojo/dijit/themes/claro/claro.css"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;style&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; html, body { height: 98%; width: 98%; margin: 0; padding: 5px; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #rightPane{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width:20%;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #legendPane{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; border: solid #97DCF2 1px;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/style&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;var djConfig = {parseOnLoad: true};&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.0"&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.BorderContainer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.ContentPane");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.layout.AccordionContainer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.map");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.dijit.Legend");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("esri.arcgis.utils");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.require("dijit.form.CheckBox");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var map;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendLayers = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legendLayer;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var legend;
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function init() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var initialExtent = new esri.geometry.Extent({"xmin":-117.98,"ymin":33.95,"xmax":-116.92,"ymax":34.44,"spatialReference":{"wkid":4326}});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = new esri.Map("map", { extent: esri.geometry.geographicToWebMercator(initialExtent)});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Add the terrain service to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&amp;amp;f=typekeywords:service&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(basemap);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var quakeLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer",{id:'quakes'});

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legendLayers.push({layer:quakeLayer,title:'Earthquakes'});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var fireLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer",{id:'fire'});

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legendLayers.push({layer:fireLayer,title:"Fire"});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map,'onLayersAddResult',function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend = new esri.dijit.Legend({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map:map,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerInfos:legendLayers
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },"legendDiv");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.startup();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayers([fireLayer,quakeLayer]);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map,'onLayersAddResult',function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var layerLists=[];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;&amp;nbsp; dojo.forEach(legendLayers,function(layer){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerLists.push(buildLayerList(layer));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.byId("layer_list").innerHTML = layerLists.join('');&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(map, 'onLoad', function(theMap) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //resize the map when the browser resizes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;&amp;nbsp; function buildLayerList(layer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var visible = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var hide=[];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var items = dojo.map(layer.layer.layerInfos,function(info,index){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (info.defaultVisibility) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(info.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hide.push(input.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "&amp;lt;input type='checkbox' class='" + layer.title + "' checked='true' id='" + info.id + "' onclick='updateLayerVisibility();' /&amp;gt;&amp;lt;label for='" + info.id + "'&amp;gt;" + info.name + "&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.layer.setVisibleLayers(visible);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.hidLayers=hide;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.refresh();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return items.join(' ');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function updateLayerVisibility() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(legendLayers,function(layer){&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var inputs = dojo.query("."+ layer.title), input;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var visible = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var hide=[];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach(inputs,function(input){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (input.checked) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(input.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hide.push(input.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if there aren't any layers visible set the array to be -1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(visible.length === 0){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(-1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.layer.setVisibleLayers(visible);&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.hidLayers=hide;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; legend.refresh();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.addOnLoad(init);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/script&amp;gt;
&amp;nbsp; &amp;lt;/head&amp;gt;
 
&amp;nbsp; &amp;lt;body class="claro"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="content" dojotype="dijit.layout.BorderContainer" design="headline" gutters="true" style="width: 100%; height: 100%; margin: 0;"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="rightPane" dojotype="dijit.layout.ContentPane" region="right"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.AccordionContainer"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.ContentPane" id="legendPane" title="Legend"&amp;nbsp; selected="true"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="legendDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div dojoType="dijit.layout.ContentPane" title="Natural Disasters" &amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;span style="padding:10px 0;" id="layer_list"&amp;gt;&amp;lt;/span&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="toggle" style="padding: 2px 2px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;lt;/body&amp;gt;
 
&amp;lt;/html&amp;gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207243#M19264</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2021-12-11T10:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207244#M19265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Shuping,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the code.&amp;nbsp; It does as you say and adds checkboxes for all sublayers.&amp;nbsp; But did you notice that the legend is tripled?&amp;nbsp; It puts the same layers in the legend three times in a row.&amp;nbsp; I think this is a step in the right direction regarding the checkboxes though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 18:40:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207244#M19265</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-12T18:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207245#M19266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Shuping,&lt;BR /&gt;&lt;BR /&gt;Thanks for the code.&amp;nbsp; It does as you say and adds checkboxes for all sublayers.&amp;nbsp; But did you notice that the legend is tripled?&amp;nbsp; It puts the same layers in the legend three times in a row.&amp;nbsp; I think this is a step in the right direction regarding the checkboxes though.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tested my sample again, however I don't see the tripled legend issue. It runs correctly in both Firefox, Chrome, and IE. Please see the attached screenshot 1-&amp;gt;2-&amp;gt;3-&amp;gt;4.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16035[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16036[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16037[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16038[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please feel free to let me know if I overlooked any detail. Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2012 19:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207245#M19266</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2012-07-12T19:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207246#M19267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's really weird. I just tried your code again to make sure.&amp;nbsp; I pasted your code into a fresh document and hit it with IE and FF.&amp;nbsp; In FF the legend appears normal, but in IE9 I get the tripled legend.&amp;nbsp; Here's a screenshot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16063[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 13:22:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207246#M19267</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-13T13:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207247#M19268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That's really weird. I just tried your code again to make sure.&amp;nbsp; I pasted your code into a fresh document and hit it with IE and FF.&amp;nbsp; In FF the legend appears normal, but in IE9 I get the tripled legend.&amp;nbsp; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;Umm....My IE9 works fine with it. Try to clear the browser cache to see if it helps. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hey Curt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Update: I found tripled legend issue is reproducible in 32-bit IE. The issue is caused by the unnecessary call of "legend.refresh();" in the "buildLayerList()" function. Go ahead and remove it. The app shall runs correctly this time. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16065[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 13:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207247#M19268</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2012-07-13T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207248#M19269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; To change the visibility of each individual layer in the map, you need to work with the&amp;nbsp;&amp;nbsp; &lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/arcgisdynamicmapservicelayer.htm#setVisibleLayers" rel="nofollow"&gt;ArcGISDynamicMapServiceLayer.setVisibleLayers()&lt;/A&gt; method.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;To change the visibility of each individual layer in the legend control, you need to work with the&amp;nbsp;&amp;nbsp; &lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/legend.htm#hideLayers" rel="nofollow"&gt;Legend.hideLayers&lt;/A&gt; property. Then follow by calling&amp;nbsp;&amp;nbsp; &lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/legend.htm#referesh" rel="nofollow"&gt;Legend.fefresh()&lt;/A&gt; method.&amp;nbsp; &lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Update:&lt;/SPAN&gt;&lt;SPAN&gt; I tested again and found there seems no need to use the Legend.hideLayers property. The legend control knows which layer has changed its visibility. Attached is the updated sample. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Correct:&lt;/SPAN&gt;&lt;SPAN&gt; In the #6 post, code lines #92 and #113 have spell errors. They should be "legend.hid&lt;/SPAN&gt;&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;&lt;SPAN&gt;Layers=hide;". I missed the "&lt;/SPAN&gt;&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;&lt;SPAN&gt;". Sorry. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 23:32:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207248#M19269</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2012-07-13T23:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207249#M19270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Update:&lt;/SPAN&gt; I tested again and found there seems no need to use the Legend.hideLayers property. The legend control knows which layer has changed its visibility. Attached is the updated sample.&amp;nbsp;&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Correct:&lt;/SPAN&gt; In the #6 post, code lines #92 and #113 have spell errors. They should be "legend.hid&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;Layers=hide;". I missed the "&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;". Sorry. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Shuping,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code works fine with the esri sample server, but when i replace it with my map service neither the TOC nor the legend gets created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am interested only in TOC though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Am i missing anything here?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 12:18:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207249#M19270</guid>
      <dc:creator>PramodHarithsa1</dc:creator>
      <dc:date>2012-07-16T12:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207250#M19271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Update:&lt;/SPAN&gt; I tested again and found there seems no need to use the Legend.hideLayers property. The legend control knows which layer has changed its visibility. Attached is the updated sample.&amp;nbsp;&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;Correct:&lt;/SPAN&gt; In the #6 post, code lines #92 and #113 have spell errors. They should be "legend.hid&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;Layers=hide;". I missed the "&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;e&lt;/SPAN&gt;". Sorry. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, that did fix the triple legend issue for me. But, when I have pulled in my own map service it does not show up in the table of contents with checkboxes. It does however appear in the legend. I"m not sure what's keeping it from working in the TOC.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 13:02:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207250#M19271</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-16T13:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207251#M19272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Shuping,&lt;BR /&gt;&lt;BR /&gt;The code works fine with the esri sample server, but when i replace it with my map service neither the TOC nor the legend gets created.&lt;BR /&gt;I am interested only in TOC though.&lt;BR /&gt;Am i missing anything here?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;Are you working with ArcGIS 10.0 or newer map service? If it is a 10.0 SP1 or newer map service, you can check its legend resource directly at the REST endpoint via URL: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;&amp;lt;mapservice-url&amp;gt;/legend&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g. &lt;/SPAN&gt;&lt;A href="http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/legend"&gt;http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/legend&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does yours legend show up at the REST endpoint?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 13:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207251#M19272</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2012-07-16T13:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207252#M19273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks, that did fix the triple legend issue for me.&amp;nbsp; But, when I have pulled in my own map service it does not show up in the table of contents with checkboxes.&amp;nbsp; It does however appear in the legend.&amp;nbsp; I"m not sure what's keeping it from working in the TOC.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I add the checkboxes to the "dojo.byId("layer_list").innerHTML". So, it depends on where the "layer_list" element is defined in the HTML, in the TOC or Legend ContentPane. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;lt;div dojoType="dijit.layout.ContentPane" title="TOC" &amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;span style="padding:10px 0;" id="layer_list"&amp;gt;&amp;lt;/span&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div id="toggle" style="padding: 2px 2px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207252#M19273</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2021-12-11T10:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207253#M19274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you working with ArcGIS 10.0 or newer map service? If it is a 10.0 SP1 or newer map service, you can check its legend resource directly at the REST endpoint via URL: http://&amp;lt;mapservice-url&amp;gt;/legend&lt;BR /&gt;&lt;BR /&gt;e.g. &lt;A href="http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/legend"&gt;http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/legend&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Does yours legend show up at the REST endpoint?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes it sure does.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer/legend"&gt;https://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer/legend&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 18:33:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207253#M19274</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-16T18:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207254#M19275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't understand it.&amp;nbsp; If I copy and paste your code into a fresh document and hit it in a browser, I get a webmap with the ESRI layers and both Legend and TOC work just fine.&amp;nbsp; Then the only thing I change is to paste the URL for my map service in place of the quakes layer, and refresh.&amp;nbsp; The map loads, the data displays, and the legend populates, but the checkboxes for the TOC are gone.&amp;nbsp; It won't even show the checkboxes for the other ESRI sublayers.&amp;nbsp; What is it about my map service that breaks the TOC?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer"&gt;http://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 18:43:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207254#M19275</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-16T18:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207255#M19276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I don't understand it.&amp;nbsp; If I copy and paste your code into a fresh document and hit it in a browser, I get a webmap with the ESRI layers and both Legend and TOC work just fine.&amp;nbsp; Then the only thing I change is to paste the URL for my map service in place of the quakes layer, and refresh.&amp;nbsp; The map loads, the data displays, and the legend populates, but the checkboxes for the TOC are gone.&amp;nbsp; It won't even show the checkboxes for the other ESRI sublayers.&amp;nbsp; What is it about my map service that breaks the TOC?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer"&gt;http://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this one:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 12:37:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207255#M19276</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2012-07-17T12:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Legend with Visible Layers - how to modify for sublayers?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207256#M19277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Shuping,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the new code.&amp;nbsp; The legend is now working with my service, thanks.&amp;nbsp; However, when the map loads only two layers are visible on the map and in the legend, yet all of the checkboxes in the TOC are checked.&amp;nbsp; If I uncheck one of them it fires the functions and suddenly all the other layers appear all at once, both in the map and in the legend.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's very close!&amp;nbsp; Just this last bug and it'll will be perfect.&amp;nbsp; Thanks for your help.&amp;nbsp; Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jul 2012 16:01:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/legend-with-visible-layers-how-to-modify-for/m-p/207256#M19277</guid>
      <dc:creator>CurtWalker</dc:creator>
      <dc:date>2012-07-23T16:01:06Z</dc:date>
    </item>
  </channel>
</rss>

