AnsweredAssumed Answered

Web AppBuilder buffer widget

Question asked by qiqbal on Nov 5, 2015
Latest reply on Jun 26, 2017 by tbu100


I am trying to create a buffer tool widget and I saw couple of examples. The first example shows creating buffer on point and second is to create buffer on line and polygons. Here are the links.

Buffer a point | ArcGIS API for JavaScript

Geometry Service - Buffer | ArcGIS API for JavaScript


The buffer on point works fine with me, but I have an issue creating the buffer on line and polygon. Below is my code:



var gsvc = new esri.tasks.GeometryService("");



startup: function() {


            this.toolbar = new Draw(;

            this.toolbar.on("draw-end", this._doBuffer);    


_doBuffer: function(evtObj) {

            var geometry = evtObj.geometry;


   switch (geometry.type) {

                 case "point":

                   var symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,0,0]), 1), new Color([0,255,0,0.25]));


                 case "polyline":

                   var symbol = new SimpleLineSymbol();


                 case "polygon":

                   var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255,0,0]), 2), new Color([255,255,0,0.25]));



            var graphic = new Graphic(geometry, symbol);



            //setup the buffer parameters

            var params = new BufferParameters();

            params.distances = [ 5 ];

            params.bufferSpatialReference =;

            params.outSpatialReference =;

//**************BELOW I TRIED DIFFERENT  WAYS****************************

            //params.unit = GeometryService["UNIT_KILOMETER"];

            //params.unit = esri.tasks.GeometryService.UNIT_KILOMETER;

            params.unit = GeometryService["UNIT_KILOMETER"];

            //params.unit =eval("esri.tasks.GeometryService.UNIT_FOOT");



             if (geometry.type === "polygon") {

                //if geometry is a polygon then simplify polygon.  This will make the user drawn polygon topologically correct.

                gsvc.simplify([geometry], function(geometries) {

                    params.geometries = geometries;

                    gsvc.buffer(params, this._test);


            } else {

                console.log("The geometry is "+geometry.type);

                params.geometries = [geometry];

                lang.hitch(this, gsvc.buffer(params, this._test));

               //*********************THIS IS WHERE MY CODE BREAKS***************************

          //******************IF I USE EITHER OF BELOW CODE, IT DOES NOT DO ANYTHING***********************               

               gsvc.buffer(params, lang.hitch(this, _test));

               gsvc.buffer(params, lang.hitch(this, this._showBuffer));




_showBuffer: function(bufferedGeometries) {

          //************IT NEVER REACHES HERE TO SHOW BELOW MESSAGE IN CONSOLE **************************


          var symbol = new SimpleFillSymbol(


            new SimpleLineSymbol(


              new Color([255,0,0,0.65]), 2


            new Color([255,0,0,0.35])



          array.forEach(bufferedGeometries, function(geometry) {

            var graphic = new Graphic(geometry, symbol);







I would really appreciate if someone can help me.