Select to view content in your preferred language

Dynamic Legend item sort order

1957
3
Jump to solution
07-26-2013 07:48 AM
AaronPerry
Occasional Contributor
This is regarding Robert Scheitlin's Dynamic Legend widget located here.  I am using the 3.2 uncompiled version.  My operational layers seem to be displaying in no particular order in the widget.  I'm sure it's based on something, but right now it seems quite random.

Can anyone explain the logic behind the sorting of items in the Dynamic Legend widget, and how/where I might go about changing or controlling it?  I'd really like to have them in the order they are listed in the Map Switcher widget.

Thanks,
Aaron
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AaronPerry
Occasional Contributor
I solved this by upgrading my source code from 3.2 to 3.4 and using the out of the box Legend widget. 

I went to the Dynamic Legend widget because the 3.2 OOB Legend widget wasn't updating when layers were turned on and off, or when graphics layers were added by my widgets. 

Today I rebuilt my viewer with a fresh download of 3.4 source and the OOB Legend works as expected now and is itself dynamic.  And it nicely matches the Map Switcher ordering which is what I wanted from Dynamic Legend when I asked this question. 

Thanks,
Aaron

View solution in original post

0 Kudos
3 Replies
AaronPerry
Occasional Contributor
I solved this by upgrading my source code from 3.2 to 3.4 and using the out of the box Legend widget. 

I went to the Dynamic Legend widget because the 3.2 OOB Legend widget wasn't updating when layers were turned on and off, or when graphics layers were added by my widgets. 

Today I rebuilt my viewer with a fresh download of 3.4 source and the OOB Legend works as expected now and is itself dynamic.  And it nicely matches the Map Switcher ordering which is what I wanted from Dynamic Legend when I asked this question. 

Thanks,
Aaron
0 Kudos
RhettZufelt
MVP Notable Contributor
For me, one of the other nice features of the Dynamic legend was the nice white background that the OOB doesn't have.

Can modify the bottom of the OOB LegendWidget.mxml to this to get the white box that the dynamic legend has:

    <viewer:WidgetTemplate id="wTemplate">
  <s:Rect bottom="0"
    left="0"
    right="0"
    top="0">
   <s:stroke>
    <mx:SolidColorStroke 
          alpha="{getStyle('borderAlpha')}"
          color="{getStyle('borderColor')}"
          weight="1"/>
   </s:stroke>
   <s:fill>
    <s:SolidColor alpha="1" color="0xffffff"/>
   </s:fill>
  </s:Rect>
  <esri:Legend id="myLegend"
                     width="100%" height="100%"
                     top="10"
                     respectCurrentMapScale="{respectCurrentMapScale}"/>

    </viewer:WidgetTemplate>


R_
0 Kudos
AaronPerry
Occasional Contributor
Thanks for the tip Rhett.  I actually got rid of the white background on the Dynamic Legend widget since I was using the sandy color theme which is a light BG already.  The background I had looked better than a white box to me.  I totally understand the contrast benefit of a white box, but I pretty much had that with the background color I was using.
0 Kudos