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.
Solved! Go to Solution.
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);
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);
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.
Daniel,
for that you just need to set the unionResults to true for the BufferParameters
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.