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
  var layerInfo = dojo.map(results, function(layer,index){
    return {layer:layer.layer,title:index};

  if(layerInfo.length > 0){

    var legendDijit = new esri.dijit.Legend({

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

1 Answer 1


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 that you have read and understand our privacy policy and code of conduct.

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