AnsweredAssumed Answered

Run Service Area by button click!

Question asked by ilyass on Nov 26, 2014
Latest reply on Dec 10, 2014 by ilyass

Dear all,


I am working on the sample existing in ArcGIS API for JavaScript "Basic Service Area"

The drive time polygon is given by a map click and i would like to have the polygon after a button click.

Below the code if someone could give me any support:


var map, serviceAreaTask, params, clickpoint;


      "esri/map", "esri/config",

      "esri/tasks/ServiceAreaTask", "esri/tasks/ServiceAreaParameters", "esri/tasks/FeatureSet",

      "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",

      "esri/geometry/Point", "esri/graphic",

      "dojo/parser", "dojo/dom", "dijit/registry",

      "esri/Color", "dojo/_base/array",

      "dijit/layout/BorderContainer", "dijit/layout/ContentPane",

      "dijit/form/HorizontalRule", "dijit/form/HorizontalRuleLabels", "dijit/form/HorizontalSlider",









    ], function(

      Map, esriConfig,

      ServiceAreaTask, ServiceAreaParameters, FeatureSet,

      SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,

      Point, Graphic,

      parser, dom, registry,

      Color, arrayUtils,


   Extent, FeatureLayer, GraphicsLayer, SpatialReference,

      InfoTemplate, on


    ) {

      parser.parse(); = "/proxy/";   

      map = new Map("map", {

        basemap: "streets",

        center: [-122.447, 37.781],

        zoom: 15



     // map.on("click", mapClickHandler);

      params = new ServiceAreaParameters();

      params.defaultBreaks= [1];

      params.outSpatialReference = map.spatialReference;

      params.returnFacilities = false;


      serviceAreaTask = new ServiceAreaTask(" Area");


      registry.byId("hslider").on("change", updateHorizontalLabel);




      // Create function that updates label when changed

      function updateHorizontalLabel() {

        // Get access to nodes/widgets we need to get/set values

        var hSlider = registry.byId("hslider");

        var label = dom.byId("decValue");

        // Update label

        label.innerHTML = hSlider.get("value");

        params.defaultBreaks = [ hSlider.value / 60 ];

        if (clickpoint) {





      on(dojo.byId("AddDTP"), "click", function mapClickHandler(evt) {

        clickpoint = evt;; //clear existing graphics

        //define the symbology used to display the results and input point

        var pointSymbol = new SimpleMarkerSymbol(



          new SimpleLineSymbol(


            new Color([88,116,152]), 2


          new Color([88,116,152,0.45])


        var inPoint = new Point(evt.mapPoint.x, evt.mapPoint.y, map.spatialReference);

        var location = new Graphic(inPoint, pointSymbol);


        var features = [];


        var facilities = new FeatureSet();

        facilities.features = features;

        params.facilities = facilities;




          var polygonSymbol = new SimpleFillSymbol(


            new SimpleLineSymbol("solid", new Color([232,104,80]), 2),

            new Color([232,104,80,0.25])


          arrayUtils.forEach(solveResult.serviceAreaPolygons, function(serviceArea){





        }, function(err){






Thank you in advance.