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();
  }
});
7
  • 1
    Do you have dojo.require("esri.dijit.Legend"); included in your script?
    – awesomo
    Commented May 1, 2013 at 17:24
  • 1
    Yes, ill add that to post.
    – LukePOLO
    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 .... ><
    – LukePOLO
    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.
    – whuber
    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.
    – awesomo
    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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.