AnsweredAssumed Answered

Creating a legend with load event on an ArcGISDynamicMapService

Question asked by schlot on Apr 17, 2014
Latest reply on Apr 18, 2014 by schlot
My question is about creating a legend, but I think I need to give some explanation of what I have going on as some background.

I have created an interface that allows the user to select a particular county and then a category of information.  This is health data, so it's information like CO poisoning rates.   The county will zoom then into their location and depending on the category selected, it will load that type of information.

Here's where it gets tricky.  Each category is a service that has multiple years of data in it.  Each layer has a name that corresponds with the category(coCarbon) and a particular year's worth of data.  Each of the 4 services has several of these layers in it.   Looking at the service it looks something like this:

ServiceName:  EPHT_countyCarbon
layer0 - EPHTcoCarbon2000
layer1 - EPHTcoCarbon2001
layer2 - EPHTcoCarbon2002
etc

The user is allowed to view one category at a time, and then only one year's (one layer) of it.  By default it loads the last layer, by setting the visibleLayers on whatever is last one in the service.   I am populating a dropdown menu that will correspond to the year, which I've parsed out of the layer names.

I'm re-using the layer name 'ncdmLayer' over again, empty out my map of any layer currently named 'ncdmLayer'.  It's recreated each time the user goes back to the start to pick another category, which is calling some other service.

I'm getting lost on when to create the legend.   I tried to set the legend to be created when the ncdmLayer is created, but this isn't working for me.

Did I mention this is also mobile?  So I'm switching between views as I'm doing this as well, generating the legend in a mobileView that isn't currently visible.  Everything loads the way I want, but I really need a legend on this too. 

Here's my fiddle:
http://jsfiddle.net/schlot/tksZQ/

Outcomes