I am trying to add a legend, and it gets to the console.log, but it fails at on the line after it.
It does not show any errors saying it failed, but it wont continue past that line.
map[map_div_id]
holds the map (we have multiple maps on the page).
Any Ideas?
//add the legend
dojo.connect(map[map_div_id],'onLayersAddResult',function(results){
var layerInfo = dojo.map(results, function(layer,index){
return {layer:layer.layer,title:index};
});
if(layerInfo.length > 0){
console.log(layerInfo);
var legendDijit = new esri.dijit.Legend({
map:map[map_div_id],
layerInfos:layerInfo
},"legendDiv");
legendDijit.startup();
}
});
raykendo
2,1872 gold badges17 silver badges26 bronze badges
-
1Do you have dojo.require("esri.dijit.Legend"); included in your script?awesomo– awesomo2013年05月01日 17:24:33 +00:00Commented May 1, 2013 at 17:24
-
1Yes, ill add that to post.LukePOLO– LukePOLO2013年05月01日 17:25:23 +00:00Commented May 1, 2013 at 17:25
-
1dojo.require("esri.map"); dojo.require("esri.tasks.query"); dojo.require("esri.layers.FeatureLayer"); dojo.require("esri.tasks.gp"); dojo.require("esri.dijit.Legend"); had to be outside the function .... ><LukePOLO– LukePOLO2013年05月01日 18:00:30 +00:00Commented May 1, 2013 at 18:00
-
3Welcome to our site! Please do not alter your question to reflect the solution you found. The best approach is to post your solution as an actual answer: it's perfectly ok for the person who asks a question to answer it themselves. In this way we will have a record of your original question and your answer, which is more useful for future visitors.whuber– whuber2013年05月01日 18:26:12 +00:00Commented May 1, 2013 at 18:26
-
2Instead of editing the post with the solution -- it's better to put it as the answer. You can answer your own question.awesomo– awesomo2013年05月01日 18:26:49 +00:00Commented May 1, 2013 at 18:26
1 Answer 1
The answer is to put the dojo.requires outside of the function instead of inside.
lang-js