[GIS] ArcGIS Server js API – buffer query against polygons and not points

arcgis-javascript-apibufferjavascript

I'm using the below sample and I want to change the queried results from points to polygons

http://help.arcgis.com/en/webapi/jav…ry_buffer.html

Probably very simple but can't get my head around where to change it.

I tried replacing the queryTask to http://sampleserver1.arcgisonline.co…SA/MapServer/1 and changing the symbol style to reflect this but it didn't seem to make much difference. I'm sure that somewhere and I can't see where, I need to make reference to the fact that we are now querying polygon and not point data.

Best Answer

The buffer user-defined graphics sample shows how to buffer points, line and polygons.

A graphic is added to the map for the user-defined geometry and then that geometry is sent to a geometry service be buffered:

function doBuffer(geometry) {
  switch (geometry.type) {
     case "point":
       var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,0,0.25]));
       break;
     case "polyline":
       var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255,0,0]), 1);
       break;
     case "polygon":
       var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
       break;
  }

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

  //setup the buffer parameters
  var params = new esri.tasks.BufferParameters();

  params.distances = [ dojo.byId("distance").value ];
  params.bufferSpatialReference = new esri.SpatialReference({wkid: dojo.byId("bufferSpatialReference").value});
  params.outSpatialReference = map.spatialReference;
  params.unit = eval("esri.tasks.GeometryService."+dojo.byId("unit").value);

  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);
  }
}
Related Question