方法一:完全自定义infowindows方法:
MyInfoPopup.mxml
- private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
- {
- trace("results:"+results);
- if (results && results.length > 0)
- {
- var result:IdentifyResult = results[0];
- var resultGraphic:Graphic = result.feature;
- resultGraphic.symbol = smsIdentify;
- //resultGraphic.infoWindowRenderer=myInfoWindowRenderer;
- graphicsLayer.clear();
- graphicsLayer.add(resultGraphic);
- lastIdentifyResultGraphic = resultGraphic;
- var mapPoint:MapPoint = resultGraphic.geometry as MapPoint;
- var myInfoPopup:MyInfoPopup = new MyInfoPopup;
- myInfoPopup.MRID = resultGraphic.attributes.MRID;
- myInfoPopup.NAME = resultGraphic.attributes.NAME;
- myInfoPopup.ALIASNAME = resultGraphic.attributes.ALIASNAME;
- myInfoPopup.LONGITUDE = resultGraphic.attributes.LONGITUDE;
- myInfoPopup.LATITUDE = resultGraphic.attributes.LATITUDE;
- myMap.infoWindow.label = resultGraphic.attributes.ALIASNAME;
- myMap.infoWindow.content = myInfoPopup;//这个是关键,这个content可以赋值任何一个控件或者容器。
- myMap.infoWindow.show( mapPoint );
- trace("clickGraphic:"+clickGraphic);
- //clickGraphic.symbol = new InfoSymbol(); // use default renderer
- // clickGraphic.symbol=smsIdentify;
- // clickGraphic.infoWindowRenderer = myInfoWindowRenderer;
- // clickGraphic.attributes = resultGraphic.attributes;
- }
- }
- private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
- {
- trace("results:"+results);
- if (results && results.length > 0)
- {
- var result:IdentifyResult = results[0];
- var resultGraphic:Graphic = result.feature;
- resultGraphic.symbol = smsIdentify;
- //resultGraphic.infoWindowRenderer=myInfoWindowRenderer;
- graphicsLayer.clear();
- graphicsLayer.add(resultGraphic);
- lastIdentifyResultGraphic = resultGraphic;
- var mapPoint:MapPoint = resultGraphic.geometry as MapPoint;
- var myInfoPopup:MyInfoPopup = new MyInfoPopup;
- myInfoPopup.MRID = resultGraphic.attributes.MRID;
- myInfoPopup.NAME = resultGraphic.attributes.NAME;
- myInfoPopup.ALIASNAME = resultGraphic.attributes.ALIASNAME;
- myInfoPopup.LONGITUDE = resultGraphic.attributes.LONGITUDE;
- myInfoPopup.LATITUDE = resultGraphic.attributes.LATITUDE;
- myMap.infoWindow.label = resultGraphic.attributes.ALIASNAME;
- myMap.infoWindow.content = myInfoPopup;
- myMap.infoWindow.show( mapPoint );
- trace("clickGraphic:"+clickGraphic);
- //clickGraphic.symbol = new InfoSymbol(); // use default renderer
- // clickGraphic.symbol=smsIdentify;
- // clickGraphic.infoWindowRenderer = myInfoWindowRenderer;
- // clickGraphic.attributes = resultGraphic.attributes;
- }
- }
MyInfoPopup.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
- <mx:Script>
- <![CDATA[
- [Bindable]
- public var MRID:String;
- [Bindable]
- public var NAME:String;
- [Bindable]
- public var ALIASNAME:String;
- [Bindable]
- public var LONGITUDE:String;
- [Bindable]
- public var LATITUDE:String;
- ]]>
- </mx:Script>
- <mx:VBox backgroundColor="0xEEEEEE" >
- <mx:Label text="MRID : {MRID}"/>
- <mx:Label text="编码: {NAME}"/>
- <mx:Label text="名称: {ALIASNAME}"/>
- <mx:Label text="经度: {LONGITUDE}"/>
- <mx:Label text="纬度: {LATITUDE}"/>
- </mx:VBox>
- </mx:Canvas>
方法二:完全自定义infowindows方法:
InfoWindow.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
<fx:Style>
@namespace esri "http://www.esri.com/2008/ags";
@namespace s "library://ns.adobe.com/flex/spark";
@namespace samples "InfoWindowRenderer.*";
.styles
{
fills:#81C3FB blue green;
border-color:green;
border-thickness: 1;
background-color: #81C3FB;
font-size: 14;
upper-left-radius: 15;
lower-right-radius:15;
info-placement: top;
}
</fx:Style>
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.GraphicEvent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polyline;
private function graphicAddHandler(event:GraphicEvent):void
{
event.graphic.toolTip = "工程编号:"+event.graphic.attributes.Id+"\n"
+ "工程名:"+event.graphic.attributes.NAME ;
event.graphic.addEventListener(MouseEvent.CLICK, onMouseCLickHandler);
}
private function onMouseCLickHandler(event:MouseEvent):void
{
const graphic:Graphic = event.target as Graphic;
if (graphic)
{
const mapPoint:MapPoint = (Polyline(graphic.geometry)).paths[0][0] as MapPoint;
var infoContent:InfowindowContent = new InfowindowContent();
infoContent.data = graphic.attributes;
map.infoWindowContent = infoContent;
map.infoWindow.styleName = "styles";
const point:Point = map.toScreen(mapPoint);
map.infoWindow.label = graphic.attributes.NAME;
map.infoWindow.show(map.toMap(point));
}
}
]]>
</fx:Script>
<fx:Declarations>
<esri:SimpleLineSymbol id="sls" width="3" color="0x00FF00"/>
</fx:Declarations>
<esri:Map id="map" openHandCursorVisible="false">
<esri:ArcGISDynamicMapServiceL ayer url="http://localhost:8399/arcgis/rest/services/GEOSWNMap/MapServer"/>
<esri:FeatureLayer id="citiesFeatureLayer"
</esri:FeatureLayer>
</esri:Map>
</s:Application>
InfowindowContent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas styleName="canvans" xmlns:fx="http://ns.adobe.com/mxml/2009"
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
.canvans{
background-color:white;
horizontal-align:center;
}
.linkButton{
font-size: 14;
font-weight: bold;
color:green;
roll-over-color:green;
background-color:green;
}
</fx:Style>
<s:VGroup width="100%" height="100%" paddingTop="20" horizontalAlign="center" >
<s:Label text="{data.NAME}" height="25"/>
<s:HGroup horizontalAlign="center" width="100%">
<mx:LinkButton label="查看单元数据" styleName="linkButton" />
<mx:LinkButton label="查看单元对比数据" styleName="linkButton" />
</s:HGroup>
</s:VGroup>
</mx:Canvas>