<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>
<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:Panel> <s:layout> <s:VerticalLayout paddingTop="10" gap="2"/> </s:layout> </s:Panel>
//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 } }
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); } }
Hi, Try this one out. It will add all layers automatically and make the first layer visible.<?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" > <mx:Script> <![CDATA[ import mx.events.ItemClickEvent; import mx.collections.ArrayCollection; import mx.controls.RadioButton; 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 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]); } private function radioClickHandler(event:ItemClickEvent):void { // update the visible layers to only show the layer selected dynamicLayer.visibleLayers = new ArrayCollection([event.index]); } ]]> </mx:Script> <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"> <mx:Array> <mx:String>Specialty/ESRI_StateCityHighway_USA</mx:String> <mx:String>Specialty/ESRI_StatesCitiesRivers_USA</mx:String> <mx:String>Demographics/ESRI_Census_USA</mx:String> </mx: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> </mx:Application>
<?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" > <mx:Script> <![CDATA[ import mx.events.ItemClickEvent; import mx.collections.ArrayCollection; import mx.controls.RadioButton; 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 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]); } private function radioClickHandler(event:ItemClickEvent):void { // update the visible layers to only show the layer selected dynamicLayer.visibleLayers = new ArrayCollection([event.index]); } ]]> </mx:Script> <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"> <mx:Array> <mx:String>Specialty/ESRI_StateCityHighway_USA</mx:String> <mx:String>Specialty/ESRI_StatesCitiesRivers_USA</mx:String> <mx:String>Demographics/ESRI_Census_USA</mx:String> </mx: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> </mx:Application>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.