serviceArea

AMD: require(["geoscene/rest/serviceArea"], (serviceArea) => { /* code goes here */ });
ESM: import * as serviceArea from "@geoscene/core/rest/serviceArea";
类: geoscene/rest/serviceArea
起始版本:GeoScene Maps SDK for JavaScript 4.19

利用服务区服务,可以查找在给定行驶时间或行驶距离内可从输入位置到达的区域。服务区是指在给定距离或行驶时间之内可从一个或多个位置(即设施点)到达的所有街道所属的区域。服务区通常用于显示和测量设施点的可达性。例如,杂货店周围三分钟的行驶时间面可以确定能够在三分钟内到达的杂货店以及更有可能在此购物的居民。此服务还可以围绕一个或多个设施点创建多个同心服务区,这些设施点可显示可达性如何随行驶时间和行驶距离的增加而变化。例如,其可用于确定在距离学校分别为 5、10 和 15 分钟车程的范围内分别有多少家医院。在根据行驶时间创建服务区时,该服务可以利用交通流量数据,该数据会影响在一天中的不同时间段可到达的区域。

方法概述

名称 返回值类值 描述 对象
Promise<ServiceAreaSolveResult>

根据一组参数确定服务区域。

更多详情
serviceArea

方法详细说明

solve(url, params, requestOptions){Promise<ServiceAreaSolveResult>}

根据一组参数确定服务区域。

参数
url String

表示网络分析服务的 GeoScene Server REST 资源的 URL。

定义服务区域所需的参数。

requestOptions Object
optional

用于数据请求的附加选项(将覆盖构造期间定义的 requestOptions)。

返回
类型 描述
Promise<ServiceAreaSolveResult> 解析后,返回 ServiceAreaSolveResult 的实例 。
示例
require([
  "geoscene/config",
  "geoscene/Map",
  "geoscene/views/MapView",
  "geoscene/rest/serviceArea",
  "geoscene/rest/support/ServiceAreaParameters",
  "geoscene/rest/support/FeatureSet",
  "geoscene/Graphic",
  ...
], function(geosceneConfig, Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic, ...) {

  // API key from developer's account
   
  // authenticates for the basemap and the serviceArea request
  geosceneConfig.apiKey = "YOUR_API_KEY";

  const map = new Map({
    basemap: "arcgis-newspaper"
  });

  const view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-116.53818, 33.82586]
    zoom: 11
  });

  const serviceAreaUrl = "https://route-api.geoscene.cn/geoscene/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";

  view.on("click", function(event){
    const locationGraphic = createGraphic(event.mapPoint);
    const serviceAreaParams = createServiceAreaParams(locationGraphic, view.spatialReference);
    solveServiceArea(serviceAreaUrl, serviceAreaParams);
  });

  // Create the location graphic
  function createGraphic(point) {
    view.graphics.removeAll();
    const graphic = new Graphic({
      geometry: point,
      symbol: {
        type: "simple-marker",
        color: "white",
        size: 8
      }
    });
    view.graphics.add(graphic);
    return graphic;
  }

  function createServiceAreaParams(locationGraphic, outSpatialReference) {
    // Create one or more locations (facilities) to solve for
    const featureSet = new FeatureSet({
      features: [locationGraphic]
    });

    // Set all of the input parameters for the service
    const serviceAreaParameters = new ServiceAreaParams({
      facilities: featureSet,
      trimOuterPolygon: true,
      outSpatialReference: outSpatialReference
    });
    return serviceAreaParameters;
  }

  function solveServiceArea(url, serviceAreaParams) {
    return serviceArea.solve(url, serviceAreaParams)
      .then(function(result){
        if (result.serviceAreaPolygons.length) {
          // Draw each service area polygon
          result.serviceAreaPolygons.forEach(function(graphic){
            graphic.symbol = {
              type: "simple-fill",
              color: "rgba(62,13,94,.25)"
            }
            view.graphics.add(graphic,0);
          });
        }
      }, function(error){
           console.log(error);
         });
  }
});

您的浏览器不再受支持。请升级您的浏览器以获得最佳体验。请参阅浏览器弃用帖子以获取更多信息