ArcGIS点击地图查询

来源:互联网 发布:炫酷导航页面源码 编辑:程序博客网 时间:2024/05/13 14:53
<?xml version="1.0" encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"xmlns:esri="http://www.esri.com/2008/ags"layout="absolute"pageTitle="Buffer using the Geometry Service"><!--This sample creates buffers around the center of the map. This example just draws the buffers,but the buffers could also be used to perform a task such as returning a list of addresses ofpeople who live within the buffered area.--><mx:Script><![CDATA[import com.esri.ags.tasks.FeatureSet;import com.esri.ags.events.QueryEvent;import com.esri.ags.geometry.Geometry;import com.esri.ags.events.MapMouseEvent;import com.esri.ags.SpatialReference;import com.esri.ags.events.GeometryServiceEvent;import com.esri.ags.tasks.BufferParameters;import com.esri.ags.Graphic;private var myInfoWindowRenderer:ClassFactory = new ClassFactory(MyInfoWindowRenderer);private function onMapClick(g:Geometry):void{query.geometry = g;queryTask.execute(query);}private function onQueryExecuteComplete(event:QueryEvent):void{var fset:FeatureSet = event.featureSet;for each (var graphic:Graphic in fset.features){graphic.symbol = symbol;graphic.infoWindowRenderer = myInfoWindowRenderer;myGraphicsLayer.add(graphic);}}private function myMapClick(event:MapMouseEvent):void{myGraphicsLayer.clear();var myMapCenterPoint:Graphic = new Graphic();//把当前点击的点赋予Grapic对象myMapCenterPoint.geometry = event.mapPoint;//定义一个BufferParameters对象var bufferParameters:BufferParameters = new BufferParameters();//设置BufferParameters的feature参数bufferParameters.features = [myMapCenterPoint];//设置当前的buffer的样式(内圆半径为0,外圆半径为1000)bufferParameters.distances = [0, 1000];//设置BufferParameters的单位bufferParameters.unit = BufferParameters.UNIT_METER;//设置BufferParameters的空间参考系bufferParameters.bufferSpatialReference = new SpatialReference(4326);//为GeometryService对象添加监听事件myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);//把buffer添加进入myGeometryServicemyGeometryService.buffer(bufferParameters);//GeometryService对象的监听function bufferCompleteHandler(event:GeometryServiceEvent):void{myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);//循环取出事件中所有的graphicfor each (var graphic:Graphic in event.graphics){//设置graphic的填充渲染graphic.symbol = sfs;//把graphic添加进入绘图层myGraphicsLayer.add(graphic);//调用GeometryService对象的查询事件://这种地图的查询是需要有GeometryService对象的//这个对象的url一般和查询对象的url差不多//如下http://localhost/arcgis/rest/services/Geometry/GeometryServer//http://localhost/arcgis/rest/services/test/MapServeronMapClick(graphic.geometry);}}}]]></mx:Script><esri:SimpleFillSymbol id="sfs" color="0xFF4444"><esri:SimpleLineSymbol color="0x000000"/></esri:SimpleFillSymbol><esri:GeometryService id="myGeometryService"  url="http://localhost/arcgis/rest/services/Geometry/GeometryServer"/><esri:QueryTask id="queryTask"  url="http://locahost/arcgis/rest/services/test/MapServer/0"executeComplete="onQueryExecuteComplete(event)"/><esri:Query id="query" returnGeometry="true"><esri:outFields><mx:String>SID</mx:String><mx:String>SNAME</mx:String></esri:outFields></esri:Query><esri:SimpleLineSymbol id="symbol" style="solid" color="0xFFFFFF" alpha="0.3"></esri:SimpleLineSymbol><mx:Component className="MyInfoWindowRenderer"><mx:VBox label="{data.SID}" backgroundColor="0xEEEEEE"><mx:Label text="State Fips: {data.SNAME}"/></mx:VBox></mx:Component><mx:Panel width="100%" height="100%"><esri:Map id="myMap" crosshairVisible="true" mapClick="myMapClick(event)"><esri:ArcGISDynamicMapServiceLayer url="http://localhost/arcgis/rest/services/test/MapServer"></esri:ArcGISDynamicMapServiceLayer><esri:GraphicsLayer id="myGraphicsLayer"/></esri:Map></mx:Panel></mx:Application>

原创粉丝点击