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