zoukankan      html  css  js  c++  java
  • 2010年8月21日周六_RoutingTasks_6.8

    /******************************************************************************************************************/

    //2010年8月21日周六

    //InsideTheApi_RoutingTasks_6.8

    /******************************************************************************************************************/

    Working with the RouteTask

    When you work with the RouteTask, you'll follow the general pattern(型、模式) of:

    creating the task,

    configuring the parameters,

    solving the route, and

    displaying the result.

    使用RouteTask一起工作

    当你和routTask一起工作,你将要按一般的模式

    创建一个任务,

    配置参数

    解决路线

    显示处理结果

    1. Creating the route task

    When you create an instance of RouteTask, you provide a URL that is the REST endpoint to an ArcGIS Server network analysis service. You can copy and paste this MXML code into your application:

    <esri:RouteTask

        id="routeTask"

        url="http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route"

    />

    The equivalent code with ActionScript:

    var routeTask:RouteTask = new RouteTask

    ("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route");

    1:创建线路任务

    当你创建线路任务的一个实例,你提供了一个URL,是一个ArcsGISServer网络分析服务的REST的终点。你可以拷贝和黏贴下面的MXML代码到你的应用程中。

    <esri:RouteTask

        id="routeTask"

        url="http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route"/>

    JavaScript代码方式表示:

    var routeTask:RouteTask = new RouteTask("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route");

    2. Configuring the route parameters

    In order to get the results you want from the route task, you need to specify the details of your routing problem such as stop locations, barrier locations, the impedance(阻抗) attribute, etc. You do this using RouteParameters. The example below shows how you'd use RouteParameters to define two stops for a route using ActionScript only. See the Route samples for a mix(混合) of MXML and ActionScript.

    var routeParams:RouteParameters = new RouteParameters();

    var stop1:Graphic = new Graphic(new MapPoint(-117.21,34.065);

    var stop2:Graphic = new Graphic(new MapPoint(-117.185,34.05);

    var stops:FeatureSet = new FeatureSet([ stop1, stop2]);

    routeParams.stops = stops;

    For a complete description of each route parameter, see the RouteParameters entry in the API reference.

    2:配置路线参数

    为了从路线任务中得到你想要的结果,你需要执行你的路线问题的详细信息,比如:停止的位置,障碍点,阻抗属性等等….你使用RoutingParameters。 下面的例子想你展示了如何仅仅适合ActionScript和RouteParameters为一个路线定义两个站点。查看由MXML和ActionScript混合写的RouteSample例子。

    var routeParams:RouteParameters = new RouteParameters();

    var stop1:Graphic = new Graphic(new MapPoint(-117.21,34.065);

    var stop2:Graphic = new Graphic(new MapPoint(-117.185,34.05);

    var stops:FeatureSet = new FeatureSet([ stop1, stop2]);

    routeParams.stops = stops;

    routeParameter的每一个参数的详细信息,请在API 引用中查看RouteParameters。

    3. Solving the route

    Once you've created the route task and configured its parameters, you can call RouteTask.solve() to solve the route.

    routeTask.solve(routeParams);

    In addition to calling the solve method, you need to handle the solveComplete and fault events on the RouteTask. These functions define what the application will do with the results, whether the result is a route or an error message.

    <esri:RouteParameters

        id="routeParams"

        solveComplete="solveCompleteHandler(event)"

        fault="faultHandler(event)"

    />

    3:结果线路问题

    一旦你创建了线路任务并配置了相应的参数,你应该调用RoutTask Solve()来解决线路问题。

    routeTask.solve(routeParams);

    为了调用解决方法,你需要处理RouteTask 中的solveComplete和fault事件。

    这个函数定义了应用程序如何处理Results,而不管结果是一个路线或者是一个错误的消息。

    <esri:RouteParameters

        id="routeParams"

        solveComplete="solveCompleteHandler(event)"

        fault="faultHandler(event)"

    />

    The equivalent code with ActionScript:

    //使用Javascript等效的代码

    routeTask.addEventListener(RouteEvent.SOLVE_COMPLETE, solveCompleteHandler);

    routeTask.addEventListener(FaultEvent.FAULT, faultHandler);

    Either way, you would usually create the actual functions as:

    //任何一种方式你都将要创如下所示的实际函数

    private function solveCompleteHandler(event:RouteEvent):void

    {

        var routeResult:RouteResult = event.routeSolveResult.routeResults[0];

        ...

    }

    private function faultHandler(event:FaultEvent):void

    {

        Alert.show(event.fault.faultString, "Routing Error");

    }

    Optimizing the route(s)

    The RouteTask can help you find the most efficient path for visiting a given list of stops. This is sometimes known as the traveling salesperson problem. To solve it, set RouteParameters.findBestSequence to true and the stops will be visited in the most efficient order. You can optionally designate whether the first and last stops on the list should remain fixed or not.

    //优化路线

    RouteTask可以帮助你找到最有效的路径访问所给出的站点列表。有些时候这个也称为:traveling salesperson problem. 为来解决这个问题,设置RouteParameters的findBestSequence属性为true并且站点将会以最高效的次序被访问。你可以选择设置,路线列表中的起始站点和终止站点是否保持固定。

    routeParams.findBestSequence = true;

    //routeParams.preserveFirstStop = true;

    //routeParams.preserveLastStop = true;

    Turn-by-turn directions

    The RouteTask can return turn-by-turn driving directions between stops. To get the directions, set RouteParameters.returnDirections to true.

    routeTask将会返回站点之间的turn-by-turn驾驶方向。 为了返回方向,设置RouteParameters.returnDirections属性为“true”;

    routeParams.returnDirections = true;

    Advanced options

    Batch routing, i.e. solving multiple routes in one request is also possible. Stops with same name will be grouped into sets for solving individual routes. For the batch routing result, you'll get an array of RouteResults containing each route.

    Constrain(限制、约束、克制、抑制) stop visits to certain times of day, or time windows - for in-depth information on how time windows work, see Routing with time windows in the ArcGIS Desktop Help.

    Live route samples

    Routing - basic routing example.

    Route Barriers - using barriers to avoid certain locations.

    Route Directions - showing turn-by-turn driving directions.

    高级选项:

    批量查找线路:

    在一个请求中查询多条线路也是可能的。名称相同的站点将会成组解决独立的线路。 对于批量线路结果,你将会得到一个RouteResults的数组,这个数组包含每一个路线。

    限制一天中的某些时间、或者时间窗口访问站点。 对于关于时间窗口是如何工作的的深入信息,在ArcGISServer桌面帮助文档中查询Routing with time windows

    相关例子

    Routing - basic routing example.  

    Route Barriers - using barriers to avoid certain locations.

    Route Directions - showing turn-by-turn driving directions.

    Routing-基本的路线查找例子

    RouteBarriers-使用障碍来避免确定的位置

    RouteDirections—显示驾驶路线的转动方向。

  • 相关阅读:
    django2.0+连接mysql数据库迁移时候报错
    微信小程序路由跳转
    洛谷P3144 [USACO16OPEN]关闭农场Closing the Farm
    洛谷P3143 [USACO16OPEN]钻石收藏家Diamond Collector
    洛谷P2677 超级书架 2
    洛谷P2676 超级书架
    洛谷P3146 [USACO16OPEN]248
    洛谷P1396 营救
    洛谷P1772 [ZJOI2006]物流运输
    P3102 [USACO14FEB]秘密代码Secret Code
  • 原文地址:https://www.cnblogs.com/xingchen/p/1805326.html
Copyright © 2011-2022 走看看