1

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
asked May 1, 2013 at 17:11
7
  • 1
    Do you have dojo.require("esri.dijit.Legend"); included in your script? Commented May 1, 2013 at 17:24
  • 1
    Yes, ill add that to post. Commented May 1, 2013 at 17:25
  • 1
    dojo.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 .... >< Commented May 1, 2013 at 18:00
  • 3
    Welcome 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. Commented May 1, 2013 at 18:26
  • 2
    Instead of editing the post with the solution -- it's better to put it as the answer. You can answer your own question. Commented May 1, 2013 at 18:26

1 Answer 1

2

The answer is to put the dojo.requires outside of the function instead of inside.

answered May 7, 2013 at 15:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.