Hide Table of Contents
View Select features within a two minute drive time sample in sandbox
Select features within a two minute drive time


Send input values to a GIS model on an ArcGIS Server and use the results to select features in your web application. The model calculates a two minute drive time polygon from a point that you click on the map.

This model is exposed through an ArcGIS Server geoprocessing service. To get an idea of what inputs and outputs are used in the model, see the services directory for the CalculateDriveTimePolygons service. Besides the default information, the model author has provided additional documentation that you can access by clicking the "Help URL" link on the page.

To access your models from ArcGIS Server, create a geoprocessing task. Use services directory to discover the URLs to your own geoprocessing services.

When you use a geoprocessing task, you'll typically configure a set of input parameters, then execute the task.

You can listen for the tasks's execute-complete event then add logic to work with the results. In this example the two minute drive time polygon generated by the task is used to select features from the feature layer.


<!DOCTYPE html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Selection with query geometry from another task (GP result)</title>

    <link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
    html, body {
    #mapDiv {
      height: 500px;

    <script src="https://js.arcgis.com/3.20/"></script>
      var map, censusBlockPointsLayer, query;
        "esri/map", "esri/InfoTemplate",
        "esri/graphic", "esri/layers/FeatureLayer",
        "esri/tasks/query", "esri/tasks/QueryTask",
        "esri/tasks/Geoprocessor", "esri/tasks/FeatureSet",
        "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleFillSymbol",
        "esri/symbols/SimpleLineSymbol", "esri/config",
        "esri/Color", "dojo/dom", "dojo/domReady!"
      ], function(
        Map, InfoTemplate,
        Graphic, FeatureLayer,
        Query, QueryTask,
        Geoprocessor, FeatureSet,
        SimpleMarkerSymbol, SimpleFillSymbol,
        SimpleLineSymbol, esriConfig,
        Color, dom
      ) {
        esriConfig.defaults.io.proxyUrl = "/proxy/";
        esriConfig.defaults.io.alwaysUseProxy = false;

        map = new Map("mapDiv", {
          basemap: "streets",
          center: [-95.249, 38.955],
          zoom: 14

        //listen for when map is loaded and then add query functionality
        map.on("load", initFunctionality);

        censusBlockPointsLayer = new FeatureLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0", {
          mode: FeatureLayer.MODE_SELECTION,
          infoTemplate: new InfoTemplate("Block: ${BLOCK}", "${*}"),
          outFields: ["POP2000","HOUSEHOLDS","HSE_UNITS", "TRACT", "BLOCK"]}

        var symbol = new SimpleMarkerSymbol();
        symbol.style = SimpleMarkerSymbol.STYLE_SQUARE;
        symbol.setColor(new Color([255,255,0,0.5]));


        censusBlockPointsLayer.on("selection-complete", function() {
          var totalPopulation = sumPopulation(censusBlockPointsLayer.getSelectedFeatures());
          var r = "";
          r = "<b>The total Census Block population within the drive time polygon is <i>" + totalPopulation + "</i>.</b>";
          dom.byId('messages').innerHTML = r;

        function initFunctionality() {
          query = new Query();
          //GP Service Endpoint
          var gp = new Geoprocessor("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons");

          // Listen for map onClick event
          map.on("click", function(evt) {
            var symbol = new SimpleMarkerSymbol();
            var graphic = new Graphic(evt.mapPoint, symbol);

            var features= [];
            var featureSet = new FeatureSet();
            featureSet.features = features;
            var params = { "Input_Location": featureSet, "Drive_Times": 2 };
            gp.outSpatialReference = map.spatialReference;
            dom.byId("messages").innerHTML = "<b>Executing GP Task...</b>";

          // Listen for GP execute-complete event
          gp.on("execute-complete", function(evt) {
            var feature = evt.results[0].value.features[0];
            var symbol = new SimpleFillSymbol(
              new SimpleLineSymbol(
                new Color([255,0,0]),
              new Color([255,255,0,0.25])

            query.geometry = feature.geometry;
            censusBlockPointsLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
            dom.byId("messages").innerHTML = "<b>Selecting Features...</b>";

        function sumPopulation(features) {
          var popTotal = 0;
          for (var x = 0; x < features.length; x++) {
            popTotal = popTotal + features[x].attributes["POP2000"];
          return popTotal;

  <body class="claro">
    Click the map to execute a 2 minute drive time and then use that result geometry as input into a query.
    <div id="mapDiv"></div>
    <span id="messages"></span>