AnsweredAssumed Answered

gsvc.buffer(params, showBuffer) issue

Question asked by EdwardGao on Sep 18, 2014

Hi,

 

I try do a buffer around selected one polygon, but no buffer shows up. here is some code if anyone can find out why. this is a html page.

 

function doBuffer(evt) {

           

            var geometry = evt[0].geometry;

            map = theMap;

            symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,

            new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,

            new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));

            var gsvc;

 

 

            gsvc = new esri.tasks.GeometryService("https://xxx.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");

            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(SimpleLineSymbol.STYLE_DASH, new Color([255, 0, 0]), 1);

                    break;

                case "polygon":

                    //var symbol = new esri.symbols.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 esri.Graphic(geometry, symbol);

            //theMap.graphics.clear();

 

 

            //setup the buffer parameters

            var params = new esri.tasks.BufferParameters();

            params.distances = 500;

            params.bufferSpatialReference = new esri.SpatialReference({ wkid: 32612});

            params.outSpatialReference = theMap.spatialReference;

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

            //polygon = new esri.geometry.Polygon(theMap.spatialReference);

            //polygon.addRing(theMap.graphics.graphics[0].geometry.rings);

 

 

//            params.geometries = [evt[0].geometry];

//           gsvc.buffer(params, showBuffer);

 

 

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

                });

            } else {

                params.geometries = [geometry];

                gsvc.buffer(params, showBuffer);

            }

 

 

        }

 

 

        function showBuffer(bufferedGeometries) {

            symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,

            new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,

            new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));

 

 

            dojo.forEach(bufferedGeometries, function(geometry) {

                var graphic = new esri.Graphic(geometry, symbol);

                theMap.graphics.add(graphic);

            });

          

        }

      

        //end for buffer.

Outcomes