`

arcgis api for flex 弹出定制提示框

    博客分类:
  • Flex
阅读更多
问题的提出:
当我点击地图中的某个点时,会弹出一个提示框显示该点的相应信息。弹出的提示框可以由自己随意定制,包括图表,超连接等。
问题的解决:
首先我参照了esri官网上的samples
1.http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=QueryClickInfoWindow (点击某个州弹出可定制的提示框)
2.http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html?sample=IdentifySample (定位到某个点,弹出一个提示框,该提示框为infoSymbol)

第一个例子可能是我要的。但在做的过程中发现。例一中点击某个点必须非常精度的定位到某个坐标。当地图比例尺较小时(可见的地图面积很大),就点不到那个点。
第二个例子中有IdentifyParameters对象可以设置tolerance。表示点击的范围。因此就比较容易定位到我们要的点上。

剩下的办法就是怎么把例1中的弹出可定制的对话框移到例2中。
首先把例1中关于MyInfoWindowRenderer的东西全部移到例2中来。
然后再改myResultFunction这个最终回调方法:
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;
                
        trace("clickGraphic:"+clickGraphic);
        clickGraphic.symbol = new InfoSymbol(); // use default renderer
		clickGraphic.symbol=smsIdentify;
		clickGraphic.infoWindowRenderer = myInfoWindowRenderer;
        clickGraphic.attributes = resultGraphic.attributes;
        
    }
}

这个虽然可以弹出定制提示框,但需要点击两次。
后来在esri官网的user forums找到一个解决方案:
http://forums.esri.com/Thread.asp?c=158&f=2421&t=270117

把myResultFunction改成如下所示:
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>
分享到:
评论
1 楼 mineguai 2012-01-08  
如果是在widget中有一个按钮,点击按钮以后弹出一个框 要怎么响应这个事件呢。。。

相关推荐

Global site tag (gtag.js) - Google Analytics