网络分析与网络数据集—功能调用REST API

ArcGIS 9.3实现了REST的架构,开始支持RIA(富英特网应用),包括ArcGIS API for Flex、ArcGIS API for Silverlight、ArcGIS JavaScript API。RIA是一种前端的开发方式,而与后台ArcGIS Server的交互是通过REST API实现的。


REST的架构,简单的说就是把所有的资源和功能都抽象为一个URL地址,通过一个URL地址就能访问ArcGIS Server提供的资源服务或者功能服务。ArcGIS Server 10 REST API实现了路径分析、最近设施查询、服务区域分析(10之前只支持路径分析)。ArcGIS API for Flex、ArcGIS API for Silverlight、ArcGIS JavaScript API都实现了相应的task来调用网络分析的功能,方法都差不多,我们看一下Flex的例子。

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Routing with the ArcGIS API for Flex"> <s:layout> <s:VerticalLayout paddingTop="10"/> </s:layout> <fx:Script> <!--[CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.events.RouteEvent; import com.esri.ags.tasks.supportClasses.RouteResult; import mx.controls.Alert; import mx.rpc.events.FaultEvent; private var lastRoute:Graphic; // Add stops to caculate route private function mapClickHandler(event:MapMouseEvent):void { var stop:Graphic = new Graphic(event.mapPoint, stopSymbol); graphicsLayer.add(stop); stops.push(stop); if (stops.length > 1) { routeTask.solve(routeParams); } } // Event handler after route solver excutes successfully private function solveCompleteHandler(event:RouteEvent):void { var routeResult:RouteResult = event.routeSolveResult.routeResults[0]; routeResult.route.symbol = routeSymbol; graphicsLayer.remove(lastRoute); lastResult = routeResult.route; graphicsLayer.add(lastRoute); } // Event handler after route solver excuetes unsuccessfully private function faultHandler(event:FaultEvent):void { Alert.show(event.fault.faultString + "/n/n" + event.fault.faultDetail, "Routing Error " + event.fault.faultCode); // remove last stop (or both stops if only two) if (stops.features.length <= 2) { graphicsLayer.clear(); } else { graphicsLayer.remove(stops.features.pop()); } } ]]--> </fx:Script> <!-- start declarations --> <fx:Declarations> <esri:RouteTask id="routeTask" concurrency="last" fault="faultHandler(event)" requestTimeout="30" showBusyCursor="true" solveComplete="solveCompleteHandler(event)" url="http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route"/> <esri:RouteParameters id="routeParams"> <esri:stops> <esri:FeatureSet> <esri:features> <fx:Array id="stops"/> </esri:features> </esri:FeatureSet> </esri:stops> </esri:RouteParameters> <esri:SimpleMarkerSymbol id="stopSymbol" size="15" style="triangle" mce_style="triangle"> <esri:SimpleLineSymbol width="4"/> </esri:SimpleMarkerSymbol> <esri:SimpleLineSymbol id="routeSymbol" alpha="0.5" color="0x0000FF" width="5"/> </fx:Declarations> <!-- end declarations --> <s:Label fontSize="12" text="Click on the map to add stops for your routing"/> <esri:Map mapClick="mapClickHandler(event)"> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> <esri:GraphicsLayer id="graphicsLayer"/> </esri:Map> </s:Application>

程序看得够多了,尽管是另一种开发方式,但是并不是那么陌生和不可理解。有两个地方特别指出,网络分析参数的设置比如U-Turn的类型、考虑哪些限制、是否考虑高速优先,包括stops、barriers都通过RouteParameters设置;计算的结果包括路径、方向提示通过RouteResult获取。

你可能感兴趣的:(网络,api,REST,Flex,import,silverlight)