Select to view content in your preferred language

Right container for ESRI:Legend

3192
5
08-29-2011 08:50 AM
WilliamBailey
Emerging Contributor
I am using "<ESRI:Legend" in my own component/pop-up.
Right now I have it located within a "<mx:TitleWindow with code as follows.
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:esri="http://www.esri.com/2008/ags"
    width="350" height="400"
    clipContent="false"
    verticalScrollPolicy="on"
    preinitialize="preInit();"
    title="Map Legend"
    showCloseButton="true"
    close="{PopUpManager.removePopUp(this)}">
  <mx:Script>
  <![CDATA[
  import com.esri.ags.Map;
  import com.esri.ags.components.Legend;
  import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
  import mx.managers.PopUpManager;
  [Bindable]private var theMap:Map;
  [Bindable]private var legendLayers:ArcGISDynamicMapServiceLayer;   
  private function preInit():void
  {
     theMap = this.parentApplication.map;
     legendLayers = this.parentApplication.baseMap;
     legendLayers.name="SCPA";
              }
                           ]]>
  </mx:Script>
     <esri:Legend id="myLegend"
        width="350" height="400"
        respectCurrentMapScale="true"
        layers="{[legendLayers]}"
        map="{theMap}"/>
</mx:TitleWindow>

The two problems I am encountering are:
1: The legend is showing all layers, not just the visible ones. (my test project; where legend and map are in same file, works flawlessly)
2. The legend extends vertically and horizontally past the containing TitleWindow (see pic)

Any help would be appreciated.
Thanks
Bill
Tags (2)
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Bill,

1. Are you sure that your other legend component implementation honors layer visibility? I should honor scale dependency.

2. You need to wrap the legend component in a scroller:

            <s:Scroller width="100%" height="100%">
                <esri:Legend id="myLegend"
                             width="350" height="400"
                             respectCurrentMapScale="true"
                             layers="{[legendLayers]}"
                             map="{theMap}"/>
            </Scroller>
WilliamBailey
Emerging Contributor
After further review of Map... the legend is respecting scale, is there a way to also respect visibility?

I did get the Legend to stay in bounds by adding "clipContent=true" to TitleWindow and playing with height and width.

p.s. I could not get Legend to work inside "<s:Scroller"  
'com.esri.ags.components.Legend' is not assignable to the default property, 'viewport', of type 'spark.core.IViewport'.

thanks for your help
0 Kudos
KenBuja
MVP Esteemed Contributor
I didn't wrap my legend in a scroller, but put it in a VGroup along with a transparency slider.

    <s:VGroup id="legendGroup" width="100%" height="100%" visible="{layerBenthic.visible}">
        <s:HGroup width="100%" horizontalAlign="center" paddingTop="10">
            <s:VGroup width="100%" horizontalAlign="center">
                <s:Label text="Layer Transparency"/>
                <s:HSlider id="toolAlpha" minimum="0" maximum="100" snapInterval="1" liveDragging="true"
                           width="75%" change="changeTransparency()" value="100"/>
            </s:VGroup>
        </s:HGroup>
        <esri:Legend id="legendMap" map="{mapMain}" layers="{layerBenthic}" width="100%" height="100%"
                     respectCurrentMapScale="true" x="10" />
    </s:VGroup>
0 Kudos
WilliamBailey
Emerging Contributor
Ken,   Nice and clean, thanks for the tip.
Anyone get the new Legend object to respect current layer visibility?
Maybe next version?   please
0 Kudos
JHayes
by
Frequent Contributor
Nice work gentlemen!

Any chance I could get the AS code for the transperency?

Thanks,
0 Kudos