AnsweredAssumed Answered

Web AppBuilder buffer widget

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

Hello

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("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

   

 

startup: function() {

            this.inherited(arguments);

            this.toolbar = new Draw(this.map);

            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]));

                   break;

                 case "polyline":

                   var symbol = new SimpleLineSymbol();

                   break;

                 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]));

                   break;

            }

            var graphic = new Graphic(geometry, symbol);

            this.map.graphics.add(graphic);

 

            //setup the buffer parameters

            var params = new BufferParameters();

            params.distances = [ 5 ];

            params.bufferSpatialReference = this.map.spatialReference;

            params.outSpatialReference = this.map.spatialReference;

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

           console.log("test");

          var symbol = new SimpleFillSymbol(

            SimpleFillSymbol.STYLE_SOLID,

            new SimpleLineSymbol(

              SimpleLineSymbol.STYLE_SOLID,

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

            this.map.graphics.add(graphic);

          });

          this.toolbar.deactivate();

          //app.map.showZoomSlider();

        },

 

I would really appreciate if someone can help me.

Thanks

Qazi

Outcomes