The toc widget is acting strange. it is not loading. sometimes after multiple refresh, it loads fine.
here is the error message I get:
here is my code
//define Proxy esriConfig.defaults.io.proxyUrl = "proxy.ashx"; esriConfig.defaults.io.alwaysUseProxy = false; //============================ map.on("load", function (evt) { mapReady(); getLayers(); }); //LEGEND CHECKBOX function getLayers() { map.on("layer-add-result", function (evt) { // console.log(evt); try { toc = new TOC({ map: map, layerInfos: [{ layer: layerName, title: "Layers", collapsed: false, slider: true }] }, 'legendDiv'); toc.startup(); } catch (ex) { // console(ex.toString()); } }) }
I am not sure why the toc is not loading correctly. Any ideas?
The error message is :
message: "Unable to load http://www.arcgis.com/sharing/tools/legend?soapUrl=http
Solved! Go to Solution.
One addition...when using the "layers-add-result" event, you'll have to add the layers using the syntax
map.addLayers([yourLayer1, yourLayer2]);
So it sometimes loads after multiple refreshes? Have you tried other browsers to see what happens? Have you tried clearing your cache on your current browser? It seems weird that it sometimes loads and sometimes doesn't. I am just curious to know what things you have tried in terms of troubleshooting.
Yes, Adrian, after clearing all the caches and browser history, the toc does load the legend just fine. I don't understand what's going on the cache and the TOC. I going to try Ken idea.. and see
Thanks
You should start the TOC in the "layers-add-results" event because the "layer-add-result" event will fire for the basemap layers in addition to the other layers you add.
Add this line into your event to see how often it fires:
console.log("Added layer " + evt.layer.id);
Ken is absolutely right!
that fixed the issue.
Thank you.