<?xml version="1.0" encoding="utf-8"?> <mx:DataGrid xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="populateArray()"> <fx:Script> <![CDATA[ import com.esri.ags.Map; import com.esri.ags.layers.ArcGISDynamicMapServiceLayer; import com.esri.ags.layers.ArcGISTiledMapServiceLayer; import com.esri.ags.layers.Layer; import com.esri.ags.layers.supportClasses.LayerInfo; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.utils.ObjectUtil; private var _map:Map; private var dp:ArrayCollection = new ArrayCollection(); public function get map():Map { return _map; } public function set map(value:Map):void { _map = value; } private function populateArray():void { var NumLayers:int = _map.layerIds.length; var mapLayer:Layer = new Layer(); var layerInfos:Array = new Array(); for (var i:int=0; i<NumLayers; i++) { mapLayer = (_map.getLayer(_map.layerIds)); if (mapLayer.className == 'ArcGISDynamicMapServiceLayer') { layerInfos = ArcGISDynamicMapServiceLayer(mapLayer).layerInfos; var infoArrayLength:int = layerInfos.length; for (var n:int; n<infoArrayLength; n++) { dp.addItem({name: layerInfos.name, defaultVisibility: layerInfos.defaultVisibility, mapType: mapLayer.className, mapID: mapLayer.id, layerID: layerInfos.id}); } } else if (mapLayer.className == 'ArcGISTiledMapServiceLayer') { dp.addItem({name: mapLayer.id, defaultVisibility: mapLayer.visible, mapType: mapLayer.className, mapID: mapLayer.id}) } } setDataProvider(); } private function setDataProvider():void { dataProvider = dp; } public function showLayer(layerIndex:int):void { if (dp[layerIndex].mapType == 'ArcGISTiledMapServiceLayer') { _map.getLayer(dp[layerIndex].mapID).visible = true; } else if (dp[layerIndex].mapType == 'ArcGISDynamicMapServiceLayer') { var visibleLayers:ArrayCollection = (ArcGISDynamicMapServiceLayer(_map.getLayer(dp[layerIndex].mapID)).visibleLayers) visibleLayers.addItem(dp[layerIndex].layerID); } } public function hideLayer(layerIndex:int):void { if (dp[layerIndex].mapType == 'ArcGISTiledMapServiceLayer') { _map.getLayer(dp[layerIndex].mapID).visible = false; } else if (dp[layerIndex].mapType == 'ArcGISDynamicMapServiceLayer') { var visibleLayers:ArrayCollection = (ArcGISDynamicMapServiceLayer(_map.getLayer(dp[layerIndex].mapID)).visibleLayers) var idIndex:int = visibleLayers.getItemIndex(int(dp[layerIndex].layerID)); if (idIndex != -1) { visibleLayers.removeItemAt(idIndex); } } } private function removeBusyCursor(event:Event):void { cursorManager.removeBusyCursor(); } ]]> </fx:Script> <mx:columns> <mx:DataGridColumn dataField="defaultVisibility" headerText="Visibility" width="70" itemRenderer="components.LayerVisibilityRenderer"/> <mx:DataGridColumn dataField="name" headerText="Layer Name"/> </mx:columns> </mx:DataGrid>
<?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" horizontalAlign="center" implements="mx.controls.listClasses.IDropInListItemRenderer"> <fx:Script> <![CDATA[ import com.esri.ags.layers.supportClasses.LayerInfo; import mx.controls.Alert; import mx.controls.listClasses.BaseListData; private var _listData:BaseListData; public function get listData():BaseListData { return _listData; } public function set listData(value:BaseListData):void { _listData = value; } private function clickHandler(event:MouseEvent):void { var layerIndex:int = listData.rowIndex; if (cb.selected) { LayerVisibility(listData.owner).showLayer(layerIndex); } else { LayerVisibility(listData.owner).hideLayer(layerIndex); } } ]]> </fx:Script> <mx:CheckBox id="cb" selected="{data.defaultVisibility}" click="clickHandler(event)"/> </mx:HBox>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.