0){var result:IdentifyResult=results[0];var resultGraphic:Graphic=result.feature;switch (resultGraphic.geometry.type){case Geometry.MAPPOINT:{resultGraphic.symbol = SMS;break;}case Geometry.POLYLINE:{resultGraphic.symbol = SLS;break;}case Geometry.POLYGON:{resultGraphic.symbol = SFS;break;}}lastIdentifyResultGraphic=resultGraphic;clickGraphic.symbol=new InfoSymbol();clickGraphic.attributes=resultGraphic.attributes;}}private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void{Alert.show(String(error), "Identify Error");}]]>
该练习涉及到的知识点:
1 先定义了一个Identify Task对象,如下面代码:
<esri:IdentifyTask id="identifyTask"
identifyComplete="identifyCompleteHandler(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_States
CitiesRivers_USA/MapServer"/>
其中,identifyComplete事件绑定IdentifyCompleteHandler(event)函数,即IdentifyTask对象设置完成之后实现该函数,url指定IdentifyTask服务地址。但在练习中没有用到该绑定事件。
2 执行Identify,需要定义一个IdentifyParameters对象,把所需要的参数进行传递,其中tolerance是容差半径,geometry是用来做Identify的几何对象。此外还定义了clickGraphic用来设置鼠标点击出现的符号
identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
这句代码主要用来向REST请求Identify服务,并设置了请求服务成功则调用myResultFunction函数,失败则调用myFaultFunction函数(这就是前面定义IdentifyTask时不设置identifyComplete事件的原因)
3 接下来主要是编写myResultFunction函数
var result:IdentifyResult=results[0];var resultGraphic:Graphic=result.feature;
用IdentifyResult来获取feature并赋予resultGraphic对象,并根据该对象的几何性质赋予渲染符号;最后把resultGraphic的属性赋给clickGraphic并用InfoSymbol显示出来另外需要注意的是:lastIdentifyResultGraphic=resultGraphic;实验设置了一个全局变量作为GraphicLayer的数据源。