That's really weird. I just tried your code again to make sure. I pasted your code into a fresh document and hit it with IE and FF. In FF the legend appears normal, but in IE9 I get the tripled legend.
Umm....My IE9 works fine with it. Try to clear the browser cache to see if it helps.
To change the visibility of each individual layer in the map, you need to work with the ArcGISDynamicMapServiceLayer.setVisibleLayers() method.
To change the visibility of each individual layer in the legend control, you need to work with the Legend.hideLayers property. Then follow by calling Legend.fefresh() method.
Update: 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.
Correct: In the #6 post, code lines #92 and #113 have spell errors. They should be "legend.hid eLayers=hide;". I missed the " e". Sorry. 🙂
Update: 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.
Correct: In the #6 post, code lines #92 and #113 have spell errors. They should be "legend.hid eLayers=hide;". I missed the " e". Sorry. 🙂
Hi Shuping,
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.
I am interested only in TOC though.
Am i missing anything here?
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.
<div dojoType="dijit.layout.ContentPane" title="TOC" > <span style="padding:10px 0;" id="layer_list"></span> <div id="toggle" style="padding: 2px 2px;"></div> </div>
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://<mapservice-url>/legend
e.g. http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/...
Does yours legend show up at the REST endpoint?
I don't understand it. 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. Then the only thing I change is to paste the URL for my map service in place of the quakes layer, and refresh. The map loads, the data displays, and the legend populates, but the checkboxes for the TOC are gone. It won't even show the checkboxes for the other ESRI sublayers. What is it about my map service that breaks the TOC?
http://map.entrix.com/ArcGIS/rest/services/07856001/titan_working_20111220_acw/MapServer