Find service areas

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

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 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

You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.

Steps

Create a new pen

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

Set the API key

To access ArcGIS services, you need an API key.

  1. Go to your dashboard to get an API key.

  2. In CodePen, set the apiKey to your key, so it can be used to access basemap layer and location services.

    Change line
        
    1
    2
    3
    4
    esriConfig.apiKey = "YOUR_API_KEY";
    const map = new Map({
      basemap: "arcgis-topographic" // Basemap layer service
    });
    

Add modules

  1. In the require statement, add the serviceArea, ServiceAreaParameters, FeatureSet, and Graphic modules.

    The ArcGIS API for JavaScript uses AMD modules. The require function is used to load modules so they can be used in the main function. It's important to keep the module references and function parameters in the same order.

    Add line.Add line.Add line.Add line.Change line
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
    
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
    
          esriConfig.apiKey = "YOUR_API_KEY";
    
          const map = new Map({
            basemap: "arcgis-navigation"
          });
    
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          });
    
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    
          view.on("click", function(event){
    
            const locationGraphic = createGraphic(event.mapPoint);
    
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, 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, 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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                    graphic.symbol = {
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    }
                    view.graphics.add(graphic,0);
                  });
                }
              }, function(error){
                console.log(error);
              });
    
          }
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
    

Update the map

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

  1. Update the basemap property from arcgis-topographic to arcgis-navigation.

    Change line
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
    
          const map = new Map({
            basemap: "arcgis-navigation"
          });
    
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Change the zoom and center properties to center on Osaka.

    Change lineChange line
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
    
          const map = new Map({
            basemap: "arcgis-navigation"
          });
    
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          });
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </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.

    Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          });
    
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Add a point graphic

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

  1. Add a click handler to add a point graphic to the view.

    Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
    
          view.on("click", function(event){
    
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          });
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </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.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // 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, 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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  3. Update the click handler to call the createGraphic function and store the graphic in locationGraphic.

    Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
    
            const locationGraphic = createGraphic(event.mapPoint);
    
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          });
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </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 a click handler in the View 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.

    Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            view.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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Create a FeatureSet to set the features property with the point graphic.

    Add line.Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  3. Create a ServiceAreaParams and return the taskParameters element.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  4. Update the click handler to add drive time cutoffs of 5, 10, and 15 minutes and to call the createServiceAreaParams function.

    Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
    
            const locationGraphic = createGraphic(event.mapPoint);
    
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
    
          });
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </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 view.

  1. Create a solveServiceArea function.

    Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
          }
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  2. Call the solve method to find the service area and add the results to the view.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
            const locationGraphic = createGraphic(event.mapPoint);
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                    graphic.symbol = {
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    }
                    view.graphics.add(graphic,0);
                  });
                }
              }, function(error){
                console.log(error);
              });
    
          }
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  3. Update the click handler to call the solveServiceArea function.

    Add line.
                                                                                                                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Find service areas</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
      </style>
      <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.20/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/MapView",
          "esri/rest/serviceArea",
          "esri/rest/support/ServiceAreaParameters",
          "esri/rest/support/FeatureSet",
          "esri/Graphic"
        ], function(esriConfig,Map, MapView, serviceArea, ServiceAreaParams, FeatureSet, Graphic) {
          esriConfig.apiKey = "YOUR_API_KEY";
          const map = new Map({
            basemap: "arcgis-navigation"
          const view = new MapView({
            container: "viewDiv",
            map: map,
            center: [135.5023,34.6937], //Longitude, latitude
            zoom: 11
          const serviceAreaUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World/solveServiceArea";
          view.on("click", function(event){
    
            const locationGraphic = createGraphic(event.mapPoint);
    
            const driveTimeCutoffs = [5,10,15]; // Minutes
            const serviceAreaParams = createServiceAreaParams(locationGraphic, driveTimeCutoffs, view.spatialReference);
    
            solveServiceArea(serviceAreaUrl, serviceAreaParams);
    
          });
          // Create the location graphic
          function createGraphic(point) {
            const graphic = new Graphic({
              geometry: point,
              symbol: {
                type: "simple-marker",
                color: "white",
                size: 8
            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(function(result){
                if (result.serviceAreaPolygons.length) {
                  // Draw each service area polygon
                  result.serviceAreaPolygons.forEach(function(graphic){
                      type: "simple-fill",
                      color: "rgba(255,50,50,.25)"
                    view.graphics.add(graphic,0);
              }, function(error){
                console.log(error);
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </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 API features and ArcGIS services in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.