Dynamic Legend widget for Flexviewer 2.0

4666
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
ShawnKraft
New Contributor III
Robert I think I got it.  I am gonna test it real quick and will let you know in the morning whether it worked.
0 Kudos
CharlesHarris
New Contributor II
Thanks Robert!  I will give it a look this morning 🙂
0 Kudos
ShawnKraft
New Contributor III
Robert you were right.  I used the analyze map in arcmap and I have a few warnings that would affect the symbology.  When I checked the arcgis/rest/services for that service I did see that some layers have a min scale set.  So I will work on that and let you know if that resolves it but it will I am sure.
0 Kudos
CharlesHarris
New Contributor II
Thanks so much for the help Robert.  I've gotten everything to work but get a Error 1034: Type Coercion Failed error during the first time that the legend is shown.  It references layer "0" in the Map Service which is a point layer.  Is that why?  If so can I filter it so that it is not included in the legend?  I do not need it to show up in the legend.  I'm including a screenshot of the error that I'm getting.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jeremy,

   I am not sure why you are getting this error. When you look at this layer in the REST Service directory for you see the symbology for the point layer displayed?
0 Kudos
ReneRubalcava
Frequent Contributor II
Thanks for doing the leg work on this one Robert. I'm incorporating/tweaking your methods to create swatches into a current layer visibility component I have. Writing up/debugging those renderer symbols must have taken you forever.
0 Kudos
CharlesHarris
New Contributor II
Jeremy,

   I am not sure why you are getting this error. When you look at this layer in the REST Service directory for you see the symbology for the point layer displayed?


Yes sir, sure do.  It's a picture marker symbol.  However, I want to make sure that it isn't included in the legend.  Here's a screenshot of the services webpage for that layer.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jeremy,

   Try replacing this code which now ignores layer 0 that is your point layer

//Legend Addition   
   protected function initLegend():void
   {
    legendAC = new ArrayCollection([]);
    ParcelData.getAllDetails(new AsyncResponder(allDtlsResult, allDtlsFault,"ParcelData"));
    function allDtlsResult(event:AllDetails,lname:String):void
    {
     for each (var lDetails:LayerDetails in event.layersDetails){
      if(lDetails.id > 0){
       if(lDetails.drawingInfo){
        //Add the layers name
        var layName:Object = {
         lname: lname,
         id: lDetails.id,
          otype: "layerName",
          label: lDetails.name,
          minscale: lDetails.minScale,
          maxscale: lDetails.maxScale,
          rend: null
        }
        legendAC.addItem(layName);
        
        if(lDetails.drawingInfo.renderer is com.esri.ags.renderers.UniqueValueRenderer)
        {
         var uv:UniqueValueRenderer = lDetails.drawingInfo.renderer as UniqueValueRenderer;
         for (var i:int=0; i<uv.infos.length; i++)
         {
          var uvObj:Object = {
           lname: lname,
           id: lDetails.id,
            parentlabel: lDetails.name,
            minscale: lDetails.minScale,
            maxscale: lDetails.maxScale,
            rend: uv.infos
          }
          legendAC.addItem(uvObj);
         }
        }
        if(lDetails.drawingInfo.renderer is com.esri.ags.renderers.SimpleRenderer)
        {
         var simObj:Object = {
          lname: lname,
          id: lDetails.id,
           parentlabel: lDetails.name,
           minscale: lDetails.minScale,
           maxscale: lDetails.maxScale,
           rend: lDetails.drawingInfo.renderer
         }
         legendAC.addItem(simObj);
        }
        if(lDetails.drawingInfo.renderer is com.esri.ags.renderers.ClassBreaksRenderer)
        {
         var cb:ClassBreaksRenderer = lDetails.drawingInfo.renderer as ClassBreaksRenderer;
         for (var j:int=0; j<cb.infos.length; j++)
         {
          var cbObj:Object = {
           lname: lname,
           id: lDetails.id,
            parentlabel: lDetails.name,
            minscale: lDetails.minScale,
            maxscale: lDetails.maxScale,
            rend: cb.infos
          }
          legendAC.addItem(cbObj);
         }
        }
       }
      }
     }
    }
    function allDtlsFault(event:FaultEvent):void
    {
     Alert.show(event.message.toString());
    }
   }
//End Legend Addition
0 Kudos
CharlesHarris
New Contributor II
Robert-

That works great.  I didn't read the code in detail until you sent me the update...It makes perfect sense that all I would need to do is start with ids > 0.  Thanks again for all of the help...I'm still a bit fuzzy on the interaction of the components, but I can follow the code.  I doubt I would've been able to write it from nothing though.  Thanks for the big help!

Jeremy
0 Kudos
ShawnKraft
New Contributor III
Robert, got it working.  Excellent tool thank you.
0 Kudos