<?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" xmlns:samples="com.*" pageTitle="Layers and Legends"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function application1_initializeHandler(event:FlexEvent):void { myLegend.layers = [ myDynamicService ]; } ]]> </fx:Script> <s:layout> <s:VerticalLayout horizontalAlign="center" paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20"/> </s:layout> <mx:HDividedBox width="100%" height="100%"> <esri:Map id="myMap"> <esri:ArcGISDynamicMapServiceLayer id="myDynamicService" name=" " load="myDynamicService.defaultVisibleLayers()" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/MapServer"/> </esri:Map> <mx:VBox width="40%" height="100%"> <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Layers"> <samples:LayerTOC mapLayer="{myDynamicService}"/> </mx:Panel> <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Legend"> <esri:Legend id="myLegend" width="100%" height="100%" map="{myMap}" respectCurrentMapScale="true"/> </mx:Panel> </mx:VBox> </mx:HDividedBox> </s:Application>
<esri:Legend id="myLegend" width="100%" height="100%" map="{myMap}" respectCurrentMapScale="true" skinClass="MyLegendSkin"/>
private function visibleLayersChangeHandler(event:CollectionEvent):void { const mapLayers:ArrayCollection = ArrayCollection(hostComponent.map.layers); for (var i:int = 0; i < mapLayers.length; ) { if (mapLayers.getItemAt(i) is ArcGISDynamicMapServiceLayer && ArcGISDynamicMapServiceLayer(mapLayers.getItemAt(i)).visible && ArcGISDynamicMapServiceLayer(mapLayers.getItemAt(i)).visibleLayers === event.target) { visibleLayersChanged(ArcGISDynamicMapServiceLayer(mapLayers.getItemAt(i))); break; } else { i++; } } }
TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@87e04c1 to com.esri.ags.layers.ArcGISDynamicMapServiceLayer. at com.esri.ags.skins::LegendSkin/visibleLayersChangeHandler() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ListCollectionView/dispatchEvent() at mx.collections::ListCollectionView/removeItemsFromView() at mx.collections::ListCollectionView/listChangeHandler() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ArrayList/internalDispatchEvent() at mx.collections::ArrayList/removeItemAt() at mx.collections::ListCollectionView/removeItemAt() at com::LayerTOC/hideLayer() at com::LayerVizRenderer/cb_clickHandler() at com::LayerVizRenderer/__cb_click()
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.