After much perusing for solutions, I've decided to post my problem as a question. I'm trying to load the legends that are built into the ArcGIS Service Layers I'm using. I'm loading about 7 Dynamic Service Layers and 7 Feature Layers. Each one of the Dynamic Service Layers has it's own legend whereas, each of the Feature Layers is sharing the same very long legend that shows all the color references for all the different layers.

According to the documentation on legends, it should be pretty simple. My code snippet is small but I really believe I'm missing something here. If people whine for more, I can include more later.

var legend = new Legend({
   map: map
}, "key");

The legend contents load to a div called "key". From what I can tell before the browser freezes and crashes, is that some legend contents are loading to the div. This is where it gets hung up. It seems like there are too many legend contents in different places or that it cannot locate one or some of the legend contents on the server. Is there something that I'm missing when it comes to loading legends?

This is the error I get... "Cannot read property '_layers' of undefined"

EDIT After trying to isolate some of the layers to see which ones are causing an issue. I still get the error when I'm trying to load more than 4 legends from different layers. Is there a way to make loading the legends more efficient? How do you only load one legend at a time?

EDIT Here's some more information describing more details of my problem. I've changed the name of my div from "key" to "loadlegend"

I'm trying to get legends loaded from a feature service that contains multiple legends within the same layer. The browser loads forever and sometimes gets some of the legends loaded and then crashes at a certain point. It looks like all the legends are contained in the same layer on the feature service. You can see my development website with all the firebug notices here. image of crashing website with struggling firebug

I've also tested other feature services with multiple legends and not had this issue. I'm not sure if it has to do with the shear quantity of legends mine contains or what. I think there are at least 10 legends in the single feature layer. screenshot of test with sample server

You can also see where I've got this little test of the sample server on JSFiddle, although the results are a little funny looking. If you copy and paste the code into ArcGIS Sandbox, it should work though. Sidenote, why does the legend look different when I go to the reference link?

  • i can't reproduce the behavior you're describing. i'd recommend replacing the layers in this sample with your own one at a time and see if you can identify an individual culprit. if they all load fine, you can take a closer look at your own custom page layout. – John Gravois Mar 31 '15 at 16:30
  • @JohnGravois That's a great idea! I'll try it out and let you know how it goes. – daniella Mar 31 '15 at 19:50
  • @JohnGravois just from initial testing, it looks like I get a "no legend" error with some layers and with others, I'll get a legend to load – daniella Apr 1 '15 at 21:26
  • "If people whine for more" is probably not an expression that will attract potential answerers to volunteer their time to help with this question. Re-writing the title and re-reading/writing the question to flow better rather than looking like several tack ons may do better. – PolyGeo Jul 16 '15 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.