wangwei9969

Get Layer By ComboBox

Discussion created by wangwei9969 on Jul 29, 2011
Latest reply on Jul 29, 2011 by DSwingley-esristaff
I want to be able to turn on and off the layer (visibleLayers) by ComboBox. I'm attempting to create three ComboBoxs for the user to toggle the visibility of layers in a dynamic map service layer. these three ComboxBoxs Respectively represent "dynamic services", "Year", "Month" .
I know the code is problem, but I will not modify,Please help me.
I referred to the http://forums.arcgis.com/threads/2106-Radio-Button-on-off-Layers?highlight=Dynamic+layers

Here's One of them my relevant MapServer:

http://219.246.47.247/ArcGIS/rest/services/day5/MapServer

Service Description:

Map Name: Layers

All Layers and Tables

Layers:


xianjie (0)
ma021011 (1)
ma021021 (2)
ma031101 (3)
ma061215 (4)
ma061215 (5)

eg."ma021011": "ma" representative "Lable"; "02" representative "Year(2002)"; "10" representative "month"; "11" representative "day"

my relevant mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      xmlns:esri="http://www.esri.com/2008/ags"
      minWidth="955" minHeight="600">
<s:layout>
  <s:VerticalLayout/>
</s:layout>
<fx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.RadioButton;
   import mx.events.ItemClickEvent;
  
   private function loadLayerName():void
   {
    layerPanel.removeAllChildren();
   
    //loop through each layer and add as a radiobutton
    var aa:String = "ma" + yearURL.selectedItem.toString() + monthURL.selectedItem.toString();
  
   
    for(var i:uint = 0; i < (dynamicLayer.layerInfos.length); i++)
    {
    
     if (aa = dynamicLayer.layerInfos[i].name);
     {
    
     var radioBtn:RadioButton = new RadioButton;
     radioBtn.groupName = "radioBtnGroup";
     radioBtn.value = i;
     radioBtn.label = dynamicLayer.layerInfos[i].name;
     layerPanel.addChild(radioBtn);
     }
    }
   
    //set the visible layer the first radio button
    radioBtnGroup.selectedValue = 0;
    dynamicLayer.visibleLayers = new ArrayCollection([0]);
   }
  
   private function radioClickHandler(event:ItemClickEvent):void
   {
    // update the visible layers to only show the layer selected
    dynamicLayer.visibleLayers = new ArrayCollection([event.index]);
   
   }  
  ]]>
</fx:Script>
<fx:Declarations>
  <!-- �?�?可�?�??素�?�?�?�?��?��?��?�对象�?�?��?�此�? -->
</fx:Declarations>

<esri:Map id="myMap">
 
  <esri:ArcGISDynamicMapServiceLayer id="dynamicLayer"
             load="loadLayerName()"
             url="http://219.246.47.247/ArcGIS/rest/services/{myURL.selectedItem}/MapServer" />
</esri:Map>

<mx:ComboBox id="myURL" selectedIndex="0" horizontalCenter="0">
  <fx:Array>
  
   <fx:String>day</fx:String>
   <fx:String>day5</fx:String>
   <fx:String>day10</fx:String>
  </fx:Array>
 
</mx:ComboBox>

<mx:ComboBox id="yearURL">
  <fx:Array>
  
   <fx:String>2002</fx:String>
   <fx:String>2003</fx:String>
   <fx:String>2006</fx:String>
  </fx:Array>
 
</mx:ComboBox>

<mx:ComboBox id="monthURL">
  <fx:Array>
  
   <fx:String>10</fx:String>
   <fx:String>11</fx:String>
   <fx:String>12</fx:String>
   <fx:String>01</fx:String>
   <fx:String>02</fx:String>
   <fx:String>03</fx:String>
  </fx:Array>
 
</mx:ComboBox>

<mx:Panel id="layerPanel" width="300" height="250" x="20" y="250" paddingLeft="20">
  <mx:RadioButtonGroup id="radioBtnGroup" itemClick="radioClickHandler(event)"/>
</mx:Panel>

</s:Application>

Outcomes