private function loadLayerName():void
{
layerPanel.removeAllChildren();
//loop through each layer and add as a radiobutton
for(var i:uint = 0; i < (dynamicLayer.layerInfos.length); i++)
{
var chks:CheckBox = new CheckBox;
chks.name="{checks}"
chks.label= dynamicLayer.layerInfos.name;
layerPanel.addChild(chks);
}
}
//add event listener
var chks:CheckBox = new CheckBox;
chks.addEventListener(Event.CHANGE, chk_changeHandler);
protected function chk_changeHandler(event:Event):void
{
var checkBox:CheckBox = event.currentTarget as CheckBox;
if (checkBox.selected = true)
{
trace("check is selected");
//add to visiblelayers
}
else
{
// remove from visiblelayers
}
}
<s:Panel> <s:layout> <s:VerticalLayout paddingTop="10" gap="2"/> </s:layout> </s:Panel>
<fx:Declarations>
<s:RadioButtonGroup id="radioBtnGroup" itemClick="radioBtnGroup_itemClickHandler(event)" />
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<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"
load="loadLayerName()"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/{myURL.selectedItem}/MapServer" />
</esri:Map>
<mx:ComboBox id="myURL" selectedIndex="0" horizontalCenter="0">
<fx:Array>
<fx:String>Specialty/ESRI_StateCityHighway_USA</fx:String>
<fx:String>Specialty/ESRI_StatesCitiesRivers_USA</fx:String>
<fx:String>Demographics/ESRI_Census_USA</fx:String>
</fx:Array>
</mx:ComboBox>
<s:Panel id="layerPanel" y="250" width="300" height="250" horizontalCenter="0" >
<s:layout>
<s:VerticalLayout paddingTop="10" gap="2"/>
</s:layout>
<s:RadioButton label="Button 1" groupName="radioBtnGroup"/>
<s:RadioButton label="Button 2" groupName="radioBtnGroup"/>
</s:Panel>
<s:RadioButton label="Button 1" group="{radioBtnGroup}"/>
<?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" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.events.LayerEvent;
import mx.collections.ArrayCollection;
import mx.events.ItemClickEvent;
import spark.components.RadioButton;
protected function loadLayerName(event:LayerEvent):void
{
layerPanel.removeAllElements()
//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.group = radioBtnGroup;
radioBtn.value = i;
radioBtn.label = dynamicLayer.layerInfos.name;
layerPanel.addElement(radioBtn);
}
//set the visible layer the first radio button
radioBtnGroup.selectedValue = 0;
dynamicLayer.visibleLayers = new ArrayCollection([0]);
}
protected 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>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:RadioButtonGroup id="radioBtnGroup" itemClick="radioClickHandler(event)"/>
</fx:Declarations>
<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"
load="loadLayerName(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/{myURL.selectedItem}/MapServer" />
</esri:Map>
<s:ComboBox id="myURL" selectedIndex="0" horizontalCenter="0" width="300">
<s:dataProvider>
<s:ArrayList>
<fx:String>Specialty/ESRI_StateCityHighway_USA</fx:String>
<fx:String>Specialty/ESRI_StatesCitiesRivers_USA</fx:String>
<fx:String>Demographics/ESRI_Census_USA</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:ComboBox>
<s:Panel id="layerPanel" width="300" height="250" x="20" y="250">
<s:layout>
<s:VerticalLayout paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"/>
</s:layout>
</s:Panel>
</s:Application>