关于Arcgis的Identify功能

ArcMap中的Identify功能是有目的查看要素(Feature)属性信息经常使用的工具。ArcMap中的Identify功能有以下几个特征:

第一, 鼠标点击具有“穿透力”,可以同时对多个图层的要素实现选择;
第二, 同一图层可以选择多个要素;
第三, 被选中要素并不高亮显示,而是以绿色闪烁一次;
第四, 所有选中要素列于弹出的信息窗口中。

identify 是GIS中比较常用的工具之一,在arcgis api for flex中esri为我们提
供了一个Identify Task来轻松完成identify 的功能。
首先,还是使用<esri:IdentifyTask>标签来创建一个Identify Task。
 <!-- Identify Task -->
<esri:IdentifyTask id="identifyTask"
identifyComplete="identifyCompleteHandler(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Special
ty/ESRI_StatesCitiesRivers_USA/MapServer"/>
当identifyTask执行完毕的时候响应identifyComplete消息,我们就可以把
identify的结果做一些处理,比如添加到Graphic layer 上。
在执行identify之前,首先要对identify的参数设置一下,我们需要一个
IdentifyParameters对象。下面的代码是AS3脚本的代码,用来创建
IdentifyParameters和identify执行。
 var identifyParams : IdentifyParameters = new IdentifyParameters();
identifyParams.returnGeometry = true;
identifyParams.tolerance = 3;
identifyParams.width = 600;
identifyParams.height = 550;
identifyParams.geometry = geometry;
identifyParams.layerOption =
IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.mapExtent = map.extent;
identifyTask.execute( identifyParams );
其中tolerance是容差半径
width:Width of the map currently being viewed in pixels.
height : Height of the map currently being viewed in pixels
geometry 是用来做identify的几何,常用的有点选,矩形选择,多边形选择等
参数设置好了之后,直接调用identifyTask.execute( identifyParams );就ok了

那么我们用来做identify的几何怎么来呢,在什么时候去做Identify呢?
首先回答第一个问题,做identify的几何我们可以利用第四讲中draw控件使用鼠
标交互来获得,这也是RIA的特点之一。
那么在什么时候做identify呢?
就在做identify的几何画完之后做,嘿嘿,等于没说嘛,当然要在画完了就做:-D
现在我们就来完成上面的工作
定义一个draw控件
<esri:Draw id="drawToolbar" map="{map}"
graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)">

记得添加上drawEnd消息的响应函数drawEndHandler(event),这个事件会在draw
之后响应。
用as3脚本实现drawEndHandler和identifyCompleteHandler函数
 private function drawEndHandler(event:DrawEvent):void
{
var geometry : Geometry = event.geometry;
var identifyParams : IdentifyParameters = new
IdentifyParameters();
identifyParams.returnGeometry = true;
identifyParams.tolerance = 3;
identifyParams.width = 600;
identifyParams.height = 550;
identifyParams.geometry = geometry;
identifyParams.layerOption =
IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.mapExtent = map.extent;
identifyTask.execute( identifyParams );

private function identifyCompleteHandler
(event:IdentifyEvent):void
{
for each (var result:IdentifyResult in
event.identifyResults)
{
myGraphicsLayer.add(result.feature);
}
}
ok ,我们的工作大致就完成了,下面我们来看一下效果

Flash:demo
源代码:
 <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
layout="absolute"
pageTitle="Identify Features on the Map"
>
<mx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.DrawEvent;
import com.esri.ags.events.IdentifyEvent;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.symbol.Symbol;
import com.esri.ags.tasks.IdentifyParameters;
import com.esri.ags.tasks.IdentifyResult;
import com.esri.ags.toolbars.Draw;
private function drawEndHandler(event:DrawEvent):void
{
var geometry : Geometry = event.geometry;
var identifyParams : IdentifyParameters = new IdentifyParameters();
identifyParams.returnGeometry = true;
identifyParams.tolerance = 3;
identifyParams.width = 600;
identifyParams.height = 550;
identifyParams.geometry = geometry;
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.mapExtent = map.extent;

identifyTask.execute( identifyParams );
}

private function identifyCompleteHandler(event:IdentifyEvent):void
{
for each (var result:IdentifyResult in event.identifyResults)
{
myGraphicsLayer.add(result.feature);
}
}
]]>
</mx:Script>
<!-- Draw ToolBar -->
<esri:Draw id="drawToolbar" map="{map}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)">
</esri:Draw>
<!-- Identify Task -->
<esri:IdentifyTask id="identifyTask"
identifyComplete="identifyCompleteHandler(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
<mx:Panel width="100%" height="100%">
<mx:Button label="Identify" click="drawToolbar.activate(Draw.MAPPOINT)"/>
<esri:Map id="map" width="100%" height="100%">
<esri:ArcGISDynamicMapServiceLayer
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer" />
<esri:GraphicsLayer id="myGraphicsLayer"/>
</esri:Map>
</mx:Panel>
</mx:Application>



参考:
http://blog.csdn.net/suinon/archive/2008/05/27/2488129.aspx
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值