Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

  if(layerInfo.length > 0){

    var legendDijit = new esri.dijit.Legend({

share|improve this question
Do you have dojo.require("esri.dijit.Legend"); included in your script? – awesomo May 1 '13 at 17:24
Yes, ill add that to post. – LukePOLO May 1 '13 at 17:25
dojo.require(""); dojo.require("esri.tasks.query"); dojo.require("esri.layers.FeatureLayer"); dojo.require(""); dojo.require("esri.dijit.Legend"); had to be outside the function .... >< – LukePOLO May 1 '13 at 18:00
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 '13 at 18:26
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 '13 at 18:26
up vote 2 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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