Skip to content

Learn how to calculate the area that can be reached in a given drive time from a location .

Click on the map to generate a drive time service area.

A service area , also known as an isochrone, is a polygon that represents the area that can be reached when driving or walking on a street network . The area that can be reached is restricted by either time or distance. To calculate service areas, you can use the Service area service . You provide a start location (facilities), one or more time or distance values, and a spatial reference . Once processed, the service returns the service areas that can be reached.

In this tutorial, you will create and display five, ten, and fifteen minute drive time service areas when the map is clicked.

To learn how to find a route and directions to different locations, visit the Get a route and directions tutorial.

Prerequisites

Steps

Create a new pen

  1. To get started, either complete the Display a map tutorial or .

Get an access token

You need an access token with the correct privileges to access the location services used in this tutorial.

  1. Go to the Create an API key tutorial and create an API key with the following privilege(s) :
    • Privileges
      • Location services > Basemaps
      • Location services > Routing
  2. In CodePen, set the apiKey property on the global esriConfig variable to your access token.
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };

To learn about other ways to get an access token, go to Types of authentication.

Update the map

A streets basemap layer is typically used in routing applications. Update the basemap attribute to use the arcgis/navigation basemap layer and change the position of the map to center on Osaka.

  1. Update the basemap attribute from arcgis/topographic to arcgis/navigation. Then change the zoom and center attributes to center on Osaka.
    29 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    5 collapsed lines
    </body>
    </html>

Add modules and wait for the Map to be ready

  1. Add a <script> tag in the <body> following the <arcgis-map> component. Use $arcgis.import() to add the serviceArea, ServiceAreaParameters, FeatureSet, and Graphic modules.

    Use the document.querySelector() method to access the map component.

    35 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    </script>
    5 collapsed lines
    </body>
    </html>
  2. Wait for the viewOnReady method to resolve to ensure the Map component is loaded and ready to use.

    35 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    </script>
    5 collapsed lines
    </body>
    </html>

Define the service url

The serviceArea module makes a request to a service and returns the results. Use the serviceArea class to access the Service area service.

  1. Define a property, serviceAreaUrl, to reference the service url.
    48 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    6 collapsed lines
    </script>
    </body>
    </html>

Add a point graphic

Use a point graphic to display the location (facility) for the service area starting point.

  1. Add an arcgisViewClick event handler to add a point graphic to the map.

    48 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    });
    7 collapsed lines
    </script>
    </body>
    </html>
  2. Create a createGraphic function that takes a point as a parameter and returns a white Graphic. It should remove all graphics each time.

    55 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  3. Update the arcgisViewClick handler to call the createGraphic function and store the graphic in locationGraphic.

    51 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    });
    23 collapsed lines
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    </script>
    </body>
    </html>
  4. Click on the map to see a point graphic .

Create service area parameters

A serviceArea uses drive times (cutoffs) and spatial reference parameters to calculate the service area . It also uses a FeatureSet to set the facilities (location) from where the service area polygon will be drawn. Use an arcgisViewClick event handler to set the parameters required to create the service area.

  1. Create a createServiceAreaParams function that takes point graphic , drive time, and spatial reference parameters.

    69 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, outSpatialReference) {
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  2. Create a FeatureSet to set the features property with the point graphic .

    73 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, outSpatialReference) {
    // Create one or more locations (facilities) to solve for
    const featureSet = new FeatureSet({
    features: [locationGraphic],
    });
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  3. Create a ServiceAreaParams and return the taskParameters element.

    73 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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 taskParameters = new ServiceAreaParams({
    facilities: featureSet,
    defaultBreaks: driveTimeCutoffs,
    trimOuterPolygon: true,
    outSpatialReference: outSpatialReference,
    });
    return taskParameters;
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  4. Update the arcgisViewClick handler to add drive time cutoffs of 5, 10, and 15 minutes and to call the createServiceAreaParams function.

    51 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    const driveTimeCutoffs = [5, 10, 15]; // Minutes
    const serviceAreaParams = createServiceAreaParams(
    locationGraphic,
    driveTimeCutoffs,
    viewElement.spatialReference,
    );
    });
    41 collapsed lines
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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 taskParameters = new ServiceAreaParams({
    facilities: featureSet,
    defaultBreaks: driveTimeCutoffs,
    trimOuterPolygon: true,
    outSpatialReference: outSpatialReference,
    });
    return taskParameters;
    }
    </script>
    </body>
    </html>

Solve the service area

To solve the service area, pass the serviceAreaParams to the solve method. Use a solveServiceArea function to find the service area polygon and add the resulting graphic to the map.

  1. Create a solveServiceArea function.

    89 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    const driveTimeCutoffs = [5, 10, 15]; // Minutes
    const serviceAreaParams = createServiceAreaParams(
    locationGraphic,
    driveTimeCutoffs,
    viewElement.spatialReference,
    );
    solveServiceArea(serviceAreaUrl, serviceAreaParams);
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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 taskParameters = new ServiceAreaParams({
    facilities: featureSet,
    defaultBreaks: driveTimeCutoffs,
    trimOuterPolygon: true,
    outSpatialReference: outSpatialReference,
    });
    return taskParameters;
    }
    function solveServiceArea(url, serviceAreaParams) {
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  2. Call the solve method to find the service area and add the results to the map.

    100 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    const driveTimeCutoffs = [5, 10, 15]; // Minutes
    const serviceAreaParams = createServiceAreaParams(
    locationGraphic,
    driveTimeCutoffs,
    viewElement.spatialReference,
    );
    solveServiceArea(serviceAreaUrl, serviceAreaParams);
    });
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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 taskParameters = new ServiceAreaParams({
    facilities: featureSet,
    defaultBreaks: driveTimeCutoffs,
    trimOuterPolygon: true,
    outSpatialReference: outSpatialReference,
    });
    return taskParameters;
    }
    function solveServiceArea(url, serviceAreaParams) {
    return serviceArea.solve(url, serviceAreaParams).then(
    (result) => {
    if (result.serviceAreaPolygons.features.length) {
    // Draw each service area polygon
    result.serviceAreaPolygons.features.forEach((graphic) => {
    graphic.symbol = {
    type: "simple-fill",
    color: "rgba(255,50,50,.25)",
    };
    viewElement.graphics.add(graphic, 0);
    });
    }
    },
    (error) => {
    console.log(error);
    },
    );
    }
    7 collapsed lines
    </script>
    </body>
    </html>
  3. Update the arcgisViewClick handler to call the solveServiceArea function.

    51 collapsed lines
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>ArcGIS Maps SDK for JavaScript Tutorials: Find service areas</title>
    <style>
    html,
    body {
    height: 100%;
    margin: 0;
    }
    </style>
    <script>
    var esriConfig = {
    apiKey: "YOUR_ACCESS_TOKEN",
    };
    </script>
    <!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
    <script type="module" src="https://js.arcgis.com/5.0/"></script>
    </head>
    <body>
    <arcgis-map basemap="arcgis/navigation" center="135.5023,34.6937" zoom="11">
    <arcgis-zoom slot="top-left"></arcgis-zoom>
    </arcgis-map>
    <script type="module">
    const [serviceArea, ServiceAreaParams, FeatureSet, Graphic] = await $arcgis.import([
    "@arcgis/core/rest/serviceArea.js",
    "@arcgis/core/rest/support/ServiceAreaParameters.js",
    "@arcgis/core/rest/support/FeatureSet.js",
    "@arcgis/core/Graphic.js",
    ]);
    const viewElement = document.querySelector("arcgis-map");
    await viewElement.viewOnReady();
    const serviceAreaUrl =
    "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    viewElement.addEventListener("arcgisViewClick", (event) => {
    const locationGraphic = createGraphic(event.detail.mapPoint);
    const driveTimeCutoffs = [5, 10, 15]; // Minutes
    const serviceAreaParams = createServiceAreaParams(
    locationGraphic,
    driveTimeCutoffs,
    viewElement.spatialReference,
    );
    solveServiceArea(serviceAreaUrl, serviceAreaParams);
    });
    63 collapsed lines
    // Create the location graphic
    function createGraphic(point) {
    viewElement.graphics.removeAll();
    const graphic = new Graphic({
    geometry: point,
    symbol: {
    type: "simple-marker",
    color: "white",
    size: 8,
    },
    });
    viewElement.graphics.add(graphic);
    return graphic;
    }
    function createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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 taskParameters = new ServiceAreaParams({
    facilities: featureSet,
    defaultBreaks: driveTimeCutoffs,
    trimOuterPolygon: true,
    outSpatialReference: outSpatialReference,
    });
    return taskParameters;
    }
    function solveServiceArea(url, serviceAreaParams) {
    return serviceArea.solve(url, serviceAreaParams).then(
    (result) => {
    if (result.serviceAreaPolygons.features.length) {
    // Draw each service area polygon
    result.serviceAreaPolygons.features.forEach((graphic) => {
    graphic.symbol = {
    type: "simple-fill",
    color: "rgba(255,50,50,.25)",
    };
    viewElement.graphics.add(graphic, 0);
    });
    }
    },
    (error) => {
    console.log(error);
    },
    );
    }
    </script>
    </body>
    </html>

Run the app

In CodePen, run your code to display the map.

Click on the map to create service areas. When you click on the map, you will see a point graphic along with drive time service areas. The service areas represent the area that can be reached within 5, 10, and 15 minutes.

What’s next?

Learn how to use additional SDK features and ArcGIS services in these tutorials: