Buffer around all geometries

1418
4
Jump to solution
08-22-2014 04:58 PM
DanielWebb2
New Contributor III

I’m looking to create one buffer around multiple graphics.

The user clicks the desired polygons, which creates graphics matching the geometry of the polygons. After certain ones are picked I want to buffer around all of those with the same shape they all have together.  Below is the code I’m trying for the buffer.

It always break on gsvc.buffer(params, showBuffer); which makes me think there’s a problem with the params.

var geom = new Graphic();

geom = graphicsLayer.graphics;

var selectedGeom = graphicsUtils.getGeometries(geom);

var bufferDist = Math.floor(dom.byId("txtBufferDist").value);

var params = new BufferParameters();

params.geometries = [selectedGeom];

params.distances = [bufferDist];

params.unit = GeometryService.UNIT_FOOT;

params.outSpatialReference = bcMap.spatialReference;

gsvc.buffer(params, showBuffer);

function showBuffer(){

     //Code

}

HOWEVER, if I use graphicsUtils.graphicsExtent instead of graphicsUtils.getGeometries it works. But I don’t want a square every time. I want the buffer to follow the outline shape as seen in yellow.

Thanks for any help.

BufferExtent.PNG

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  So it looks like your issue is that graphicUtil.getGeometries returns an array and you then are putting that array inside another array here:

params.geometries = [selectedGeom];

Try:

params.geometries = selectedGeom;

You also are start the geom var as a Graphics and then overwrite it with an array of Graphics:

var geom = new Graphic();

geom = graphicsLayer.graphics;

This is no big deal as you are overwriting it but there is no need to start it as a Graphic and then set it to an Array. This would make more sense:

var graphics = graphicsLayer.graphics;

var selectedGeoms = graphicsUtils.getGeometries(graphics);

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  So it looks like your issue is that graphicUtil.getGeometries returns an array and you then are putting that array inside another array here:

params.geometries = [selectedGeom];

Try:

params.geometries = selectedGeom;

You also are start the geom var as a Graphics and then overwrite it with an array of Graphics:

var geom = new Graphic();

geom = graphicsLayer.graphics;

This is no big deal as you are overwriting it but there is no need to start it as a Graphic and then set it to an Array. This would make more sense:

var graphics = graphicsLayer.graphics;

var selectedGeoms = graphicsUtils.getGeometries(graphics);

0 Kudos
DanielWebb2
New Contributor III

Thanks a ton! That basically got it.  Now it makes a graphic around each polygon.  This at least gets past my wall gives me something else to look into.  I’m hoping to get one single graphic as a buffer.

Thanks again.

BufferExtent2.PNG

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  for that you just need to set the unionResults to true for the BufferParameters

0 Kudos
DanielWebb2
New Contributor III

You rock!  It was so simple!  Now I feel dumb for missing that property.  I was trying to figure how to make esri/dijit/editing/Union or esri/dijit/analysis/MergeLayers work.

Thanks for your help.

0 Kudos