acwalker

Create legend from scratch

Discussion created by acwalker on Sep 24, 2013
Latest reply on Feb 12, 2014 by bgfield
I need to develop a legend/TOC that has both layer toggling and the symbols for each layer, just like you would see in ArcGIS Desktop.  I've already looked at the 3rd-party TOC widget and while it's a neat solution it doesn't fully satisfy our needs.  What I'd really like to learn is how that widget and also the legend dijit are mining the symbols for each layer in a map service. 

I did some digging and I have found the image URL for point layers in REST.  That one was easy.  After some experimenting I was able to harvest those images using the URL and inject them into my own legend pane.  But there does not appear to be symbol URLs for polygon or polyline layers in REST.  Instead I found the JSON where fill and outline properties are given, but this only applies to polygon layers.  I was able to dynamically build my own polygon symbol from the JSON using canvas in HTML 5.

So that leaves polylines and for whatever reason the JSON for polylines in REST is worthless.  I have a line layer that is a wide yellow stroke with a narrower black stroke in the middle, but you'd never know that looking at the JSON which says the line is a simple black stroke only.

Does anyone know how the legend dijit and TOC widgets are mining the graphics for each map service layer?  Is it somewhere in REST or what?

Outcomes