1、在mxml中引用mxml
InfoWindowRollOverContent.mxml文件
<?xml version="1.0" encoding="utf-8"?>
<!-- Used by InfoWindowRollOverSample.mxml -->
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Declarations>
<fx:String id="lat">0</fx:String>
<fx:String id="lon">0</fx:String>
</fx:Declarations>
<s:Label text="Latitude: {lat}"/>
<s:Label text="Longitude: {lon}"/>
</s:VGroup>
引用的文件,先定义一个命令空间
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:samples="com.esri.ags.samples.*" //定义的命令空间 pageTitle="InfoWindow as MapTips"> <!--
<esri:infoWindowContent> <samples:InfoWindowRollOverContent id="content"/> //引用的mxml类,在此API使用中,将给infoWindowContent赋值,然后整个的map中的InfoWindow都可以使用 </esri:infoWindowContent>
参考http://resources.arcgis.com/en/help/flex-api/samples/#/InfoWindow_as_MapTips/01nq0000003w0000002、mxml中使用as中的类
InfoRendererWithStates.mxml文件,在文件中继承了IDataRenderer接口,实现了方法
<?xml version="1.0" encoding="utf-8"?> <s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true" creationComplete="creationCompleteHandler()" implements="mx.core.IDataRenderer"> //继承了接口 <!-- This is used by the InfoSymbolWithStates sample. --> <fx:Script> <![CDATA[ private var _data:Object; [Bindable] // implement IDataRenderer public function get data():Object { return _data; } public function set data(value:Object):void { _data = value; } private function creationCompleteHandler():void { addEventListener(MouseEvent.ROLL_OVER, rollOverHandler); addEventListener(MouseEvent.ROLL_OUT, rollOutHandler); } private function rollOverHandler(event:MouseEvent):void { if (currentState == "normal") { currentState = "titleState"; } } private function rollOutHandler(event:MouseEvent):void { if (currentState == "titleState") { currentState = "normal"; } } private function expandButton_clickHandler():void { currentState = "detailState"; } private function closeButton_clickHandler():void { currentState = "normal"; } private function effectStartHandler():void { removeEventListener(MouseEvent.ROLL_OVER, rollOverHandler); } private function effectEndHandler():void { addEventListener(MouseEvent.ROLL_OVER, rollOverHandler); } ]]> </fx:Script> <s:states> <s:State name="normal"/> <s:State name="titleState"/> <s:State name="detailState"/> </s:states> <s:transitions> <s:Transition fromState="*" toState="*"> <s:Resize duration="250" effectEnd="effectEndHandler()" effectStart="effectStartHandler()" target="{this}"/> </s:Transition> </s:transitions> <s:HGroup id="titleBar" width="100%" verticalAlign="middle"> <s:Image width="18" height="18" source="@Embed(source='/assets/skins.swf', symbol='Icon_airport')"/> <s:Label id="titleLabel" fontWeight="bold" includeIn="titleState,detailState" rollOut="{Label(event.currentTarget).setStyle('textDecoration', 'none');}" rollOver="{Label(event.currentTarget).setStyle('textDecoration', 'underline');}" text="{data.theName}"/> <s:Button id="expandButton" width="18" height="18" click="expandButton_clickHandler()" includeIn="titleState" skinClass="com.esri.ags.samples.skins.InfoExpandButtonSkin"/> <s:Button id="closeButton" width="18" height="18" click="closeButton_clickHandler()" includeIn="detailState" skinClass="com.esri.ags.samples.skins.InfoCloseButtonSkin"/> </s:HGroup> <s:Label id="line1Label" includeIn="detailState" text="{data.thePlaceName}"/> </s:VGroup>
3、实现基类的子类
<?xml version="1.0" encoding="utf-8"?> <s:DataRenderer //继承的基类 xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" implements="mx.core.IFactory" xmlns:code="http://code.google.com/p/flex-iframe/" creationComplete="datarenderer1_creationCompleteHandler(event)" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:supportClasses="com.esri.ags.skins.supportClasses.*" xmlns:view="widgets.monitor2.view.*" xmlns:template="com.depth.viewer.widget.template.*" xmlns:widget="com.depth.viewer.widget.*"> <fx:Script> <![CDATA[ .... ... ...