ARCGIS viewer入门(10)自定义infowindow

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法一:完全自定义infowindows方法:
  1. private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
  2. {
  3. trace("results:"+results);
  4. if (results && results.length > 0)
  5. {
  6. var result:IdentifyResult = results[0];
  7. var resultGraphic:Graphic = result.feature;
  8. resultGraphic.symbol = smsIdentify;
  9. //resultGraphic.infoWindowRenderer=myInfoWindowRenderer;
  10. graphicsLayer.clear();
  11. graphicsLayer.add(resultGraphic);
  12. lastIdentifyResultGraphic = resultGraphic;
  13. var mapPoint:MapPoint = resultGraphic.geometry as MapPoint;
  14. var myInfoPopup:MyInfoPopup = new MyInfoPopup;
  15. myInfoPopup.MRID = resultGraphic.attributes.MRID;
  16. myInfoPopup.NAME = resultGraphic.attributes.NAME;
  17. myInfoPopup.ALIASNAME = resultGraphic.attributes.ALIASNAME;
  18. myInfoPopup.LONGITUDE = resultGraphic.attributes.LONGITUDE;
  19. myInfoPopup.LATITUDE = resultGraphic.attributes.LATITUDE;
  20. myMap.infoWindow.label = resultGraphic.attributes.ALIASNAME;
  21. myMap.infoWindow.content = myInfoPopup;//这个是关键,这个content可以赋值任何一个控件或者容器。
  22. myMap.infoWindow.show( mapPoint );
  23. trace("clickGraphic:"+clickGraphic);
  24. //clickGraphic.symbol = new InfoSymbol(); // use default renderer
  25. // clickGraphic.symbol=smsIdentify;
  26. // clickGraphic.infoWindowRenderer = myInfoWindowRenderer;
  27. // clickGraphic.attributes = resultGraphic.attributes;
  28. }
  29. }


MyInfoPopup.mxml
Js代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
  3. <mx:Script>
  4. <![CDATA[
  5. [Bindable]
  6. public var MRID:String;
  7. [Bindable]
  8. public var NAME:String;
  9. [Bindable]
  10. public var ALIASNAME:String;
  11. [Bindable]
  12. public var LONGITUDE:String;
  13. [Bindable]
  14. public var LATITUDE:String;
  15. ]]>
  16. </mx:Script>
  17. <mx:VBox backgroundColor="0xEEEEEE" >
  18. <mx:Label text="MRID : {MRID}"/>
  19. <mx:Label text="编码: {NAME}"/>
  20. <mx:Label text="名称: {ALIASNAME}"/>
  21. <mx:Label text="经度: {LONGITUDE}"/>
  22. <mx:Label text="纬度: {LATITUDE}"/>
  23. </mx:VBox>
  24. </mx:Canvas>  

方法二:完全自定义infowindows方法:
InfoWindow.mxml
<?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="InfoWindowRenderer.*" >
<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:ArcGISDynamicMapServiceLayer url="http://localhost:8399/arcgis/rest/services/GEOSWNMap/MapServer"/>
<esri:FeatureLayer id="citiesFeatureLayer"
graphicAdd="graphicAddHandler(event)"
mode="snapshot"
symbol="{sls}"
outFields="*"
url="http://localhost:8399/arcgis/rest/services/GEOSWNMap/MapServer/1">
</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"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minHeight="100" minWidth="300">
<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的边框背景色:

Java代码 复制代码 收藏代码
  1. <fx:Style> @namespace esri "http://www.esri.com/2008/ags";
  2. esri|InfoWindowLabel
  3. {
  4. color: white;
  5. font-size: 20;
  6. }
  7. esri|InfoWindow
  8. {
  9. border-thickness: 0;
  10. background-color: green;
  11. font-size: 16;
  12. upper-left-radius: 15;
  13. upper-right-radius: 0;
  14. info-placement: top;
  15. info-offset-y: 20;
  16. }
  17. </fx:Style>
<fx:Style> @namespace esri "http://www.esri.com/2008/ags";
		esri|InfoWindowLabel
		{
			color: white;
			font-size: 20;
		}
		esri|InfoWindow
		{
			border-thickness: 0;
			background-color: green;
			font-size: 16;
			upper-left-radius: 15;
			upper-right-radius: 0;
			info-placement: top;
			info-offset-y: 20;            
		}
	 
	</fx:Style>

效果如图:

2 点击地图 任意位置 弹出一个信息窗:

Java代码 复制代码 收藏代码
  1. private function onMouseCLK(event:MapMouseEvent):void
  2. {
  3. myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
  4. //设置里面的文字:
  5. myTextArea.text="asdfasf";
  6. }
private function onMouseCLK(event:MapMouseEvent):void
{
  myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
//设置里面的文字:
myTextArea.text="asdfasf";
}
 

设置信息泡的组件:

Html代码 复制代码 收藏代码
  1. <esri:Map id="myMap" mapClick="onMouseCLK(event)">
  2. <esri:infoWindowContent>
  3. <mx:TextArea id="myTextArea"
  4. width="250"height="75"/>
  5. </esri:infoWindowContent>
  6. </esri:Map>
<esri:Map id="myMap"   mapClick="onMouseCLK(event)">
 <esri:infoWindowContent>
            <mx:TextArea id="myTextArea"
                         width="250" height="75"/>
        </esri:infoWindowContent>
</esri:Map>

3 点击任意一个图元,弹出信息窗:

方式一: 最简单,直接在给图层的infoWindowRenderer 属性赋值:

Html代码 复制代码 收藏代码
  1. <esri:GraphicsLayer >
  2. <esri:infoWindowRenderer>
  3. <fx:Component>
  4. <mx:VBox backgroundColor="0xffffff"
  5. color="0x444444"
  6. label="Parcel {data.PARCELID}">
  7. <mx:Label text="Owner: {data.OWNERNME1}"/>
  8. <mx:Label text="Address: {data.SITEADDRESS}"/>
  9. <mx:Label text="Land Value: {data.LNDVALUE}"/>
  10. <mx:Label text="Landuse: {data.USECD}"/>
  11. </mx:VBox>
  12. </fx:Component>
  13. </esri:infoWindowRenderer>
  14. <esri:GraphicsLayer/>
<esri:GraphicsLayer > 
   <esri:infoWindowRenderer>
                <fx:Component>
                    <mx:VBox backgroundColor="0xffffff"
                             color="0x444444"
                             label="Parcel {data.PARCELID}">
                        <mx:Label text="Owner: {data.OWNERNME1}"/>
                        <mx:Label text="Address: {data.SITEADDRESS}"/>
                        <mx:Label text="Land Value: {data.LNDVALUE}"/>
                        <mx:Label text="Landuse: {data.USECD}"/>
                    </mx:VBox>
                </fx:Component>
            </esri:infoWindowRenderer>
<esri:GraphicsLayer/> 

方式二: 给graphic加 事件,在事件处理函数中弹出信息窗,所以当图元超过500时,效率很差。

<esri:GraphicsLayer id="roadLayer" graphicAdd="fLayer_graphicAddHandler" />

<!--当图层被加入图元时 触发事件-->

  protected function fLayer_graphicAddHandler(event:GraphicEvent):void
      {
                event.graphic.addEventListener(MouseEvent.MOUSE_CLICK, onMouseClkHandler);
     }

Js代码 复制代码 收藏代码
  1. pprivate function onMouseClkHandler(event:MouseEvent):void
  2. var gr:Graphic = Graphic(event.target);
  3. gr.symbol = mouseOverSymbol;
  4. myMap.infoWindow.label = gr.attributes.NAME;
  5. myMap.infoWindow.closeButtonVisible = false;
  6. myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
  7. }

或者:

gra.infoWindowRenderer=new ClassFactory(weatherInfoWin);

gra.symble=....;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值