Merging Table Of Content and Legend Info
Initially, while working on Gulf Of Mexico Response Map, the legend and table-of-content were two separate windows. That took too much real-estate, and a TOC layer was hard to correlate with the legend swatch by name only. So I set upon merging the legend window and the table-of-content into one window. There is plenty of TOC code as a visual tree component, but it is the legend UI that causes us trouble as there is no REST endpoint to get the layer swatch information. Well with the advent of FeatureLayer somebody can argue that this could be done. But you still have to go back and forth for each layer and get the rendering information. BTW, this will be remedied in 10.1, as a new REST endpoint will be introduced to get _all_ rendering information of a map service. In the meantime, I had to do something. As you can imagine the project map services were very dynamic and the layer content was changing constantly, so having a static legend is out of the question. There were attempts to create an ArcObject proxy, where the client application connects to that proxy who issues a SOAP request to an ArcGIS server for the legend info. The SOAP result is converted to JSON and forwarded back to the client for decoding and rendering. The code was written in .Net and have a Java based server. I wanted to be platform independent and have a two tier architecture (at least from a 10,000 feet perspective) and the introduction of a proxy was out of the question. So....I have to issue SOAP calls directly from the client to ArcGIS server. This is where the advent of FlashBuilder with its data connectivity option was a blessing. FlashBuilder can generate correctly stub code for ArcGIS SOAP methods based on a map service WSDL. This was impossible in FlexBuilder. Yes, it does bloat the code base a bit, but it is a small price to pay for such a dynamic system. The TOC code is based on the FlexViewer TOC code. I modified the item renderer to be of variable height to accommodate the renderer swatches as child elements. You can see the application in action here. And like usual, you can download the source code from here. Small note: First time through, it take a few seconds to get the swatches, so if you open the tree, it will look “plain” and somehow AGS returns blank swatches for tiled map services. not sure why ! have to ask the core team about that. Oh one more thing, in addition to adding the Flex API for AGS swc, make sure to include the Adobe provided fiber swcs. Until 10.1 (hopefully soon) hope this can help.
PS: If you have a 10 server - there is a REST way to get all the layers published in a map server that could be used to create swatches from the rendering information.
Comments
-hbostic
Added check on
if(legendGroup.LegendClasses)
to: getImageResult():ImageResult
and addLegendClasses(vbox:VBox):void
legendGroup.LegendClasses was returning null sometimes when adding service at runtime
Thanks this code rocks!!!!!!
Loved they way you presented at the ESRI conference.
thanks
xiaoming
I copied two files from the source code viewer and replaced it.
MapServer.as
and _Super_Mapserver.as
you will notice in _Super_Mapserver
the constructor is set to take two arrguments
public function _Super_MapServer(wsdlURL:String, service:String)
But where could we change the fonts to let it be “Layers” instead of “Lavers”?
Thanks again.
Thanks
Add the following in TOC class:
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
this.width= measureWidthOfItems();
this.height= measureHeightOfItems();
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
I read all the posts but unable to find the solution