方法一:完全自定义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>
其他的一些相关资料 1 首先如何设置 infowindow或infoWindowRenderer的边框背景色:
效果如图:
2 点击地图 任意位置 弹出一个信息窗:
设置信息泡的组件:
3 点击任意一个图元,弹出信息窗: 方式一: 最简单,直接在给图层的infoWindowRenderer 属性赋值:
方式二: 给graphic加 事件,在事件处理函数中弹出信息窗,所以当图元超过500时,效率很差。 <esri:GraphicsLayer id="roadLayer" graphicAdd="fLayer_graphicAddHandler" /> <!--当图层被加入图元时 触发事件--> protected function fLayer_graphicAddHandler(event:GraphicEvent):void
{
event.graphic.addEventListener(MouseEvent.MOUSE_CLICK, onMouseClkHandler);
}
pprivate function onMouseClkHandler(event:MouseEvent):void
{
var gr:Graphic = Graphic(event.target);
gr.symbol = mouseOverSymbol;
myMap.infoWindow.label = gr.attributes.NAME;
myMap.infoWindow.closeButtonVisible = false;
myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
} 或者: gra.infoWindowRenderer=new ClassFactory(weatherInfoWin); gra.symble=....; |

这篇博客介绍了如何在ARCGIS viewer中实现自定义infoWindow。通过创建一个名为MyInfoPopup的控件,并设置其属性来显示图形的详细信息,包括MRID、NAME、ALIASNAME、LONGITUDE和LATITUDE。关键步骤在于将content属性设置为自定义控件,以展示图形的属性信息。







1万+

被折叠的 条评论
为什么被折叠?



