Dynamic Legend widget for Flexviewer 2.0

5049
65
07-29-2010 01:18 PM
RobertScheitlin__GISP
MVP Emeritus
All,

    I am happy to announce the first community developed (and shared on the code gallery) widget for the Flexviewer 2.0. I have finalized my Dynamic Legend Widget for the 2.0 FlexViewer and shared it for all to use.

This version is COMPLETELY dependent on 2 things

  1. ArcGIS Server 10 map services

  2. Flex Viewer 2.0 and obviously Flex API 2.0


I have made it XML configurable this time so that you can specify that certain map services or certain layers in a map service are not to be displayed in the widget.

It is called dynamic because the legend will only draw map services and layer that are visible in your map. It respects scale dependency of layers and if the layer is checked in the TOC or operational layer TOC. The legend automatically redraws when layers have been checked/unchecked and when zooming in or out and a layer scale dependency has been meet.

I hope you enjoy it and I HOPE that you read and understand that it will not work with mapservices that are not served from a ArcGIS 10 Server.

http://www.arcgis.com/home/item.html?id=f60406b9f52340d59eb557bf64136af6

PS. don't forget to rate the code.
Tags (2)
0 Kudos
65 Replies
ReneRubalcava
Honored Contributor
Hi Robert, I just wanted to give you a big thanks. I wanted to make sure it was ok with you that I've added your functions to build the swatches into a function in my flex library in my signature.
SwatchFactory
I couldn't find an email for you, or I would have just sent one.
I put a sample up of how I'm using it in a non-widget capacity.
Thanks again.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rene,

   That's fine with me. Keep op the good work on the FlexMapTools.
0 Kudos
CattyannCampbell
Frequent Contributor
Simon,

     You do need to compile it your self. I have always had bad experiences distributing compiled swfs in the past.


Oh now I see why this widget does not work for my app. Need to compile it but no way of compiling it without a copy of Flash 4 which we don't have a copy of on our server nor would I know what I'm doing even if we had one...
0 Kudos
JoshuaCoates
Deactivated User
How do I create a swf for this dynamiclegend widget? Also, is this what I need in order to have the legend appear on my layers as they do in arcmap....with the colors and symbology showing and not just the title of the layer? One more thing, can you post an example of the xml for the widget so that I can see what <configuration> looks like with an example plugged in?! Thank you so much!

Josh
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joshua,

   Most of your questions can be answered by just clicking on the link as it has a working sample website. As far as make a swf that is as simple as adding the code to your FlexViewer2.0 SOURCE code (not the precompiled version) and following the instructions in the readme.txt
0 Kudos
JoshuaCoates
Deactivated User
I have clicked on the link and looked through it, however it just has an example of the live map. Not the configuration. And I have followed the directions in the readme file, it does not tell you how to compile a swf file though. I have added the dynamiclegendwidget into my flex project....is that what you mean by "adding the code to your FlexViewer2.0 SOURCE code"?? I am using the precompiled data for flexviewer, I have modified it to plug in my services and data.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joshua,

   Like I said
(not the precompiled version)
If you want to use this widget than you have to compile it and how you compile it is to get the FlexViewer2.0 source code and add it as a project in Flex or Flash Builder. Once you have the FlexViewer2.0 project setup then you can copy in the DynamicLegend widget to the widgets folder, add the DynamicLegendWidget.mxml to your projects modules list and compile the whole FlexViewer2.0 source. Most of the time on the forum and code gallery you are going to find code and sample that will require you to be using the FlexViewer source, and this widget is one of those. You will be limited in what you can do with the viewer if you only use the pre-compiled source.
0 Kudos
JoshuaCoates
Deactivated User
Ok, sorry if my lack of flex knowledge and computer xml configuring is causing confusion. I suppose I am not using the precompiled. Because like you just mentioned, I downloaded the source code originally, added it as a flex project. I have configured the xml as I need it for my service and web map. I just found this dynamiclegend widget, downloaded and unzipped the file. I put the dynamic folder into the widgets folder in my project. Now when you say "add the DynamicLegendWidget.mxml to your projects modules list and compile the whole FlexViewer2.0 source" this is where I am lost. I do not understand what that means. In the widgets folder of my project, I have a DynamicLegend folder, within this folder, I have the dynamiclegendwidget.mxml, dynamiclegendwidget.xml,legenddatagroup.as, and legenditenrenderer.mxml files. Maybe this is just over my head, but I really have no computer coding experience or knowledge of some of the terminology used sometimes.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joshua,

   OK, now we are on the right track. What you have to do to add a widget to the projects module list is this:

1. Right click on the FlexViewer project in the "Package Explorer" window (FlashBuilder) or "Flex Navigator" window (FlexBuilder) and choose properties.

2. In this dialog on the left window find "Flex Modules" and click the add button on the right

3. browse to the widgets/DynamicLegend/DynamicLegendWidget.mxml file and add it.

Now when you run the project it will compile the DynamicLegendWidget.swf file.
0 Kudos
JoshuaCoates
Deactivated User
Ok, thank you. I have the swf compiled. Now i added
"<widget label="Dynamic Legend" x="50" y="100"
      icon="assets/images/i_legend2.png"
      config="widgets/DynamicLegend/DynamicLegendWidget.xml"
      url="widgets/DynamicLegend/DynamicLegendWidget.swf"/>"
to the widgetcontainer......but the widget does not display when I run the project. I am not sure what to put in the dynamiclegendwidget xml for the configuration either. I see that the it shows the text that mapservice must be specified and all that, but I just am not sure of text and formatting to make it work properly. Does anyone have their xml for the dynamiclegend widget that I can see as an example for how they plugged in their own code?!
0 Kudos