目的:
1.ArcGIS API for Flex用GeoprocessingServices实现网络分析中的服务区分析,本例子根据driveTimes值分析出在指定时间内的区域范围情况,效果图中有内到外分别是1分钟、2分钟、3分钟的行车区域范围情况
准备工作:
1.本来例子采用的数据是SanFrancisco数据(ArcTutor\GP Service Examples\DriveTimePolygons),在ArcGIS.Server.9.3发布一个叫SanFranciscoBasemap的Map Service(SanFranciscoBasemap.mxd)
2.在ArcGIS.Server.9.3发布一个叫DriveTimePolygonsService的Geoprocessing Service,关于Geoprocessing模型的制作以及Geoprocessing Service的发布设置请参考http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#geoprocessing/guide_-1963186772.htm页面中的Example了,讲述的很详细了。
完成后的效果图:

ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)
开始:
1.首先对Geoprocessing Service进行一下介绍,从ags9.2开始可以将ArcTool 做为GeoProcessing service发布,在ArcGIS Server中使用,这样就能借助ArcTool为ags提供非常强大简单好用的功能,如buffer分析、网络分析、数据裁剪....等等。Geoprocessing Service发布后可以提供给不同的客户端使用如Web Mapping Applications, ArcGIS Explorer, and ArcGIS Desktop,在ags9.3中GeoProcessing service也同时通过rest api的方式提供给客户端进行编程使用,在flex api、javascript api中由于不能直接像Web Mapping Applications一样直接通过调用Ao的方法实现复杂的功能,这样GeoProcessing service就显得非常的有用了,它为flex api、javascript api提供了实现复杂功能的途径如buffer分析、网络分析等,当然buffer分析可以还可以用GeometryService实现了前几篇中有详细的讲解了。
2.介绍完启动GeoProcessing service的概念接下来用GeoProcessing service实现网络分析中的服务区分析为实例来讲解GeoProcessing service在flex api中的应用。
3.启动Flex Builder3新建工程以及引入1.0正式版ArcGIS API for Flex library的开发包
4.新建ServiceAreaGP.mxml页面,添加Map、ArcGISDynamicMapServiceLayer、GraphicsLayer等并且设置相应的属性。具体代码如下:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)<mx:Canvas width="482" height="426" borderStyle="solid" borderThickness="3" verticalCenter="16" left="10">
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
<esri:Map id="myMap" logoVisible="false">
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<esri:ArcGISDynamicMapServiceLayer url="http://jh-53a435fbc0e8/ArcGIS/rest/services/SanFranciscoBasemap/MapServer" />
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<esri:GraphicsLayer id="myGraphicsLayer" symbolFunction="mySymbolFunction" />
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
</esri:Map>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
</mx:Canvas>
5.接下来添加ToggleButtonBar用来进行地图漫游和点点击服务器分析功能之间的切换:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)<mx:ToggleButtonBar verticalCenter="-215" itemClick="itemClickHandler(event)" left="10">
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<mx:dataProvider>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<mx:Array>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<mx:Object icon="{Pan}" />
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
<mx:Object icon="{point}" />
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
</mx:Array>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)        
</mx:dataProvider>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
</mx:ToggleButtonBar>
6.添加图形显示样式定义,包括点样式以及3种颜色不同的面样式:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)<esri:SimpleMarkerSymbol id="sms" style="diamond" color="0x000000" size="10" alpha="0.7"/>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
<esri:SimpleFillSymbol id="rFill" alpha="0.8" color="0xFF0000"/>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
<esri:SimpleFillSymbol id="gFill" alpha="0.8" color="0x00FF00"/>
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)    
<esri:SimpleFillSymbol id="bFill" alpha="0.8" color="0x0000FF"/>
7.当然还需添加esri:Draw控件了,进行服务区分析时先在地图上画一个点用的:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)<esri:Draw id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawStart="drawStartHandler(event)" drawEnd="drawEndHandler(event)" />
8.最后当然是本例子的主角esri:Geoprocessor控件了,它的url值填写我们上面发布的DriveTimePolygonsService的Geoprocessing Service的rest地址:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)<esri:Geoprocessor id="gp" url="http://jh-53a435fbc0e8/ArcGIS/rest/services/DriveTimePolygonsService/GPServer/CalcDriveTimePolygons" />
9.在完成界面的显示代码后开始在mx:Script中编写功能代码,首先是GraphicsLayer的symbolFunction="mySymbolFunction",这个是对添加到GraphicsLayer的元素进行样式设置的方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)private function mySymbolFunction(graphic:Graphic):Symbol
            }
10.接下来按照事件执行顺序说明代码,ToggleButtonBar控件的itemClick事件的itemClickHandler(event)方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)private function itemClickHandler(event:ItemClickEvent):void
            }
11.然后是Draw控件的drawStart事件的drawStartHandler(event)方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)private function drawStartHandler(event:DrawEvent):void
            }
12.然后是Draw控件的drawEnd事件的drawEndHandler(event)方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)private function drawEndHandler(event:DrawEvent):void
            }
13.然后是serviceArea方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)//进行服务区分析
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)
            private function serviceArea(mapPoint:MapPoint ):void
            }
14.在上面的serviceArea方法执行后最终根据成功与否分别调用onResult和onFault方法:
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)//Geoprocessor成功把结果添加到myGraphicsLayer进行显示
ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)
            private function onResult(gpResult:ExecuteResult,token:Object = null):void
            }
15.这样通过Geoprocessing Service相当简单的完成了一个服务区分析的例子。

相关文章:

  • 2022-01-12
  • 2021-07-28
  • 2021-11-24
  • 2021-10-25
  • 2021-09-11
  • 2021-05-26
  • 2021-09-28
  • 2021-08-13
猜你喜欢
  • 2021-09-28
  • 2021-08-25
  • 2021-06-01
  • 2021-07-03
  • 2021-08-15
  • 2021-09-14
  • 2021-12-27
相关资源
相似解决方案