Map Legend and Layer Control for ESRI Flex API 2.0
Recently, my twitter buddy ruprictGeek developed a Legend Resource Application using Sinatra that would generate an image of Legend for a map service using Ruby. This is a pretty awesome tool, and something that I think could prove useful for things like simplified metadata pages of available map services fr organizations, or bringing a quick legend into a web application. It also taught me a little Ruby and how if you are going to do some Ruby dev, you’re better off not using Windows for it, just my opinion. But I digress, it got me started down a path to build something a little more robust for my Flex Applications.
I had put this implementation on the back burner when I realized how involved creating the symbology in the application would be. Then lo and behold a few weeks back, Mr. Robert Scheitlin released a Dynamic Legend Widget for FlexViewer 2.0. Robert has been a big contributor on the ESRI Flex forums and is a wizard of the ESRI Flex API and ESRI FlexViewer. Now, I don’t use the FlexViewer for various reasons, but he did all of the leg work in his widget that was needed to actually translate the Map Service symbology into something that could be used in Flex. I already had a component that would pull Layers from a Map and allowed you to turn services on and off, as well as individual sub layers. I was pretty happy with it. But the one question I always get asked by my users is, Where’s the legend? We can’t release without a legend. As a side note, most developers might have a project with one or two core stakeholders that steer the project, my main project has about a dozen and if I have a dozen people asking for a legend, I listen.
So what I did was incorporate the work done by Mr. Scheitlin into my current Layer Control tool and created a LegendManager component that will display all symbology and allow you to turn layers on and off. I’m pretty happy with it. This component is part of my FlexMapTools library on github. I’ve included skins and itemRenderers in FlexMapTools, but feel free to modify these to meet your needs. Skin them up and make them as pretty as you’d like. You’ll notice I have not built a skin for the button to expand sub layer details.
An example of the tool in action can be found here.
If you have some trouble using the component if you set up your visible layers using a config.xml file, please read the notes in LayerInfoDetails. You may need to search your visible layers using a string and not an int. It was an odd issue I ran into porting this tool to FlexMapTools.
As always, I am always looking for comments/critiques. I’m more intermediate, so I’m always looking to learn more and see how what Ive done stands up to the pros. Thanks again to Robert Scheitlin for tackling how to draw the legend symbology in Flex and thanks to Glenn Goodrich (ruprictGeek) for inspiring me to get this component off the ground.