Select to view content in your preferred language

Robert Scheitlin or anybody else, please help!!! TOC Table of Contents and Legend!

3212
13
Jump to solution
03-12-2012 05:43 AM
by Anonymous User
Not applicable
Original User: ionara_wilson

Hi Robert /ESRI users

I really need to find help for this:



I need help with the TOC Table of Content ArcScript posted on the arcscript page by Tom Hill. I am developing a Flex app outside of the Flex Viewer. I need to have the Group TOC and the legends. I was already able to put together the website with the map, the group TOC and the legend using the esri Legend component. What I need help is with the following:

1 - Have one layer always visible (in my case the county layer)
2 - Have all the other layers off when another layer (other than the layer that is always visible, the counties layer) is checked on
3- Have the legend pop up for the layer that is checked on (right now I would have the legend visible for all the layers that are checked on, I just need to have one single for the one layer checked on)
4-  There should be only one legend always. Whatever you see on the map you should see on the legend, just one legend for just one map checked on and visible

I am attaching the image of my web app, the mxml of my main app and the  code I downloaded and used for the table of contents.

Thank you for any help in advance!!!
0 Kudos
13 Replies
by Anonymous User
Not applicable
Original User: rscheitlin

Ionara,

   Here is a quick sample with the legend portion:

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"                 layout="vertical"                 xmlns:esri="http://www.esri.com/2008/ags"                 paddingBottom="8" paddingLeft="8"                 paddingRight="8" paddingTop="8"                  backgroundColor="0x999999">     <mx:Script>         <![CDATA[             import mx.collections.ArrayCollection;             import mx.controls.RadioButton;             import mx.events.FlexEvent;             import mx.events.ItemClickEvent;                          private function loadLayerName():void             {                 myLegend.layers = null;                 layerPanel.removeAllChildren();                                  //loop through each layer and add as a radiobutton                 for(var i:uint = 0; i < (dynamicLayer.layerInfos.length); i++)                 {                     var radioBtn:RadioButton = new RadioButton;                     radioBtn.groupName = "radioBtnGroup";                     radioBtn.value = i;                     radioBtn.label = dynamicLayer.layerInfos.name;                     layerPanel.addChild(radioBtn);                 }                                  //set the visible layer the first radio button                 radioBtnGroup.selectedValue = 0;                 dynamicLayer.visibleLayers = new ArrayCollection([0]);                 myLegend.layers = [dynamicLayer];                 myLegend.visible = true;             }                          private function radioClickHandler(event:ItemClickEvent):void             {                 myLegend.layers = null;                 // update the visible layers to only show the layer selected                 dynamicLayer.visibleLayers = new ArrayCollection([event.index]);                 myLegend.layers = [dynamicLayer];             }                      ]]>     </mx:Script>          <mx:HDividedBox width="100%" height="100%" backgroundColor="0x999999">         <mx:Canvas height="100%" width="100%" backgroundColor="0xffffff">             <esri:Map id="myMap">                 <esri:extent>                     <esri:Extent xmin="-126" ymin="27" xmax="-72" ymax="50">                         <esri:SpatialReference wkid="4326"/>                     </esri:Extent>                 </esri:extent>                 <esri:ArcGISDynamicMapServiceLayer id="dynamicLayer" name="Legend"                                                    load="loadLayerName()"                                                    url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/{myURL.selectedItem.value}/MapServer" />             </esri:Map>         </mx:Canvas>         <mx:Canvas height="100%" width="300" backgroundColor="0xffffff"                    horizontalScrollPolicy="off"                    verticalScrollPolicy="off">             <mx:VBox width="300" height="100%" paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10"                      verticalGap="8">                 <mx:ComboBox id="myURL" selectedIndex="0" labelField="label" width="100%">                     <mx:ArrayCollection>                         <mx:Object label="US City State Highway" value="Specialty/ESRI_StateCityHighway_USA" />                         <mx:Object label="US City State Rivers" value="Specialty/ESRI_StatesCitiesRivers_USA" />                         <mx:Object label="US Demographics" value="Demographics/ESRI_Census_USA" />                     </mx:ArrayCollection>                 </mx:ComboBox>                 <mx:VBox id="layerPanel" width="100%" height="20%" verticalGap="3">                     <mx:RadioButtonGroup id="radioBtnGroup" itemClick="radioClickHandler(event)"/>                 </mx:VBox>                 <mx:Canvas id="legendPanel" width="100%" height="80%">                     <esri:Legend id="myLegend" layers="[]"                                  map="{myMap}" visible="false"                                  respectCurrentMapScale="false"/>                 </mx:Canvas>             </mx:VBox>         </mx:Canvas>     </mx:HDividedBox> </mx:Application> 


You not marking the thread as answered or promoting responses that are helpful does not encourage people to continue to help you.

Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
0 Kudos
ionarawilson1
Deactivated User
Many thanks Robert.  I will try the legend the way you posted and see if I get rid of the error messages! Sorry for not marking it as answered. I am new here so I am not sure about how things work yet. Please let me know if it is still showing as not answered! Thanks again!!!
0 Kudos
ionarawilson1
Deactivated User
Hi everybody

Just to help other users: When I first used Robert's code I kept getting the error "could not resolve esri legend to a component implementation" (When I use the 2.0 library on 3.6 sdk). When  I used a newer library (I believe it is because the esri legend component is something created with the 2.2 library )  I got rid of that error message but then I got these errors: Type was not found or was not a compile-time constant: Group, Type was not found or was not a compile-time constant: solidColorstroke. I was using SDK 3.6 when I had these errors, but once I switched to the 4.0 SDK the problems disappeared!!!  Thank you again Robert, this is awesome, I am so happy for your code!!!!
0 Kudos
ionarawilson1
Deactivated User
Does anybody have any idea why with this code when I first load the webpage (with links to my data, not ESRI data like the code here) sometimes the legend shows two layers instead of one?

Thank you!
0 Kudos