Try to develop buffer widget but the issue is unionResults seems not working
var params = new BufferParameters();
params.distances = [dom.byId("distance").value];
params.bufferSpatialReference = new esri.SpatialReference({ wkid: dom.byId("bufferSpatialReference").value });
params.outSpatialReference = this.map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value];
params.unionResults = true;
The buffer cannot be dissolved.
Solved! Go to Solution.
Zhan,
Your method is working because to are manually merging the the polygons client side instead of allowing the Server to buffer all the geometries at once and then merge them server side as my code shows. Either way can you mark this thread as answered so that people can find the correct answer. Do this my clicking the "Correct Answer" link (with the little green star) on your reply or mine.
Zhan,
What kind of error are you getting? Have you simplified your input geometries using GeometryService.simplify before attempting to buffer?
Hi, Robert
there is no error, but buffer cannot dissolve.
here is the code.
params.distances = [dom.byId("distance").value];
params.bufferSpatialReference = new esri.SpatialReference({ wkid: dom.byId("bufferSpatialReference").value });
params.outSpatialReference = this.map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value];
params.unionResults = true;
params.geometries = [feature.geometry];
if (type === "polygon") {
require(["esri/tasks/AreasAndLengthsParameters", "esri/tasks/GeometryService",
], function(AreasAndLengthsParameters, GeometryService) {
var areasAndLengthParams = new AreasAndLengthsParameters();
areasAndLengthParams.lengthUnit = GeometryService.UNIT_FOOT;
areasAndLengthParams.areaUnit = GeometryService.UNIT_ACRES;
gsvc.simplify([feature.geometry], function (simplifiedGeometries) {
areasAndLengthParams.polygons = simplifiedGeometries;
gsvc.areasAndLengths(areasAndLengthParams);
});
});
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
Thanks
Hi Zhan,
I suspect the code you posted is within a for loop where you are iterating through your features.
If my suspicion is correct, you are actually hitting three individual buffer requests one for each feature. In this case there is nothing to union, as there is only one buffered geometry for each feature.
You may want to consolidate all your feature geometries within the loop as an array and call buffer from outside the loop.
Zhan,
I would have to see more of your code, but it appears that you are actually buffering each of your individual geometries separately and not giving the buffer params an array of all your geometries:
params.geometries = [feature.geometry];
Hi, Robert
here is whole module:
_drawResults: function (layerIndex, results) {
var currentLayer = this.resultLayers[layerIndex];
var features = results.features;
for (var i = 0, len = features.length; i < len; i++) {
var feature = features;
var listItem = this.list.items;
var type = feature.geometry.type;
var geometry, symbol, centerpoint;
switch (type) {
case "multipoint":
case "point":
if (this.config.symbols && this.config.symbols.simplemarkersymbol) {
symbol = new SimpleMarkerSymbol(this.config.symbols.simplemarkersymbol);
} else {
if (this.config.symbols && this.config.symbols.picturemarkersymbol) {
symbol = new PictureMarkerSymbol(this.config.symbols.picturemarkersymbol);
}
else {
symbol = new SimpleMarkerSymbol();
}
}
centerpoint = feature.geometry;
break;
case "polyline":
if (this.config.symbols && this.config.symbols.simplelinesymbol) {
symbol = new SimpleLineSymbol(this.config.symbols.simplelinesymbol);
} else {
symbol = new SimpleLineSymbol();
}
centerpoint = feature.geometry.getPoint(0, 0);
break;
case "extent":
case "polygon":
if (this.config.symbols && this.config.symbols.simplefillsymbol) {
symbol = new SimpleFillSymbol(this.config.symbols.simplefillsymbol);
} else {
symbol = new SimpleFillSymbol();
}
centerpoint = feature.geometry.getPoint(0, 0);
break;
default:
break;
}
listItem.centerpoint = centerpoint;
listItem.graphic = feature;
var title = listItem.title;
var content = listItem.content;
if (!feature.symbol) {
feature.setSymbol(symbol);
}
if (!feature.infoWindow) {
var it = new InfoTemplate(title, title + "<br>" + content);
feature.setInfoTemplate(it);
}
currentLayer.add(feature);
//Do buffer.
var gsvc, tb, poline;
gsvc = new GeometryService("https://xxxx.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
esriConfig.defaults.io.proxyUrl = "/proxy";
esriConfig.defaults.io.alwaysUseProxy = false;
switch (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 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 Graphic(feature.geometry, symbol)
this.map.graphics.add(graphic);
}
var params = new BufferParameters();
params.distances = [dom.byId("distance").value];
params.bufferSpatialReference = new esri.SpatialReference({ wkid: dom.byId("bufferSpatialReference").value });
params.outSpatialReference = this.map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value];
params.unionResults = true;
params.geometries = [feature.geometry];
if (type === "polygon") {
//if geometry is a polygon then simplify polygon. This will make the user drawn polygon topologically correct.
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
} else {
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
}
},
Thanks again.
Zhan,
Something more like this would be what you are after:
_drawResults: function (layerIndex, results) {
var currentLayer = this.resultLayers[layerIndex];
var features = results.features;
//added GeomArray
var GeomArray = [];
//end add
for (var i = 0, len = features.length; i < len; i++) {
var feature = features;
var listItem = this.list.items;
var type = feature.geometry.type;
var geometry, symbol, centerpoint;
switch (type) {
case "multipoint":
case "point":
if (this.config.symbols && this.config.symbols.simplemarkersymbol) {
symbol = new SimpleMarkerSymbol(this.config.symbols.simplemarkersymbol);
} else {
if (this.config.symbols && this.config.symbols.picturemarkersymbol) {
symbol = new PictureMarkerSymbol(this.config.symbols.picturemarkersymbol);
}
else {
symbol = new SimpleMarkerSymbol();
}
}
centerpoint = feature.geometry;
break;
case "polyline":
if (this.config.symbols && this.config.symbols.simplelinesymbol) {
symbol = new SimpleLineSymbol(this.config.symbols.simplelinesymbol);
} else {
symbol = new SimpleLineSymbol();
}
centerpoint = feature.geometry.getPoint(0, 0);
break;
case "extent":
case "polygon":
if (this.config.symbols && this.config.symbols.simplefillsymbol) {
symbol = new SimpleFillSymbol(this.config.symbols.simplefillsymbol);
} else {
symbol = new SimpleFillSymbol();
}
centerpoint = feature.geometry.getPoint(0, 0);
break;
default:
break;
}
listItem.centerpoint = centerpoint;
listItem.graphic = feature;
var title = listItem.title;
var content = listItem.content;
if (!feature.symbol) {
feature.setSymbol(symbol);
}
if (!feature.infoWindow) {
var it = new InfoTemplate(title, title + "<br>" + content);
feature.setInfoTemplate(it);
}
currentLayer.add(feature);
//Do buffer.
var gsvc, tb, poline;
gsvc = new GeometryService("https://xxxx.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
esriConfig.defaults.io.proxyUrl = "/proxy";
esriConfig.defaults.io.alwaysUseProxy = false;
switch (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 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 Graphic(feature.geometry, symbol);
//Add the features geometry to the array
GeomArray.push(feature.geometry);
//end add
this.map.graphics.add(graphic);
}
var params = new BufferParameters();
params.distances = [dom.byId("distance").value];
params.bufferSpatialReference = new esri.SpatialReference({ wkid: dom.byId("bufferSpatialReference").value });
params.outSpatialReference = this.map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value];
params.unionResults = true;
params.geometries = GeomArray; //set the buffer params geometries to the GeomArray
if (type === "polygon") {
//if geometry is a polygon then simplify polygon. This will make the user drawn polygon topologically correct.
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
} else {
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
}
},
Thanks Robert,
I figure out the solution, here the code I add to create polygon.
polygon = new Polygon(this.map.spatialReference);
for (i = 0; i < graphic._graphicsLayer.graphics.length; i++) {
ringsLength = graphic.geometry.rings.length;
if (this.map.graphics.graphics.geometry.type == "polygon") {
for (j = 0; j < ringsLength; j++) {
polygon.addRing(this.map.graphics.graphics.geometry.rings
}
}
}
var params = new BufferParameters();
params.distances = [dom.byId("distance").value];
params.bufferSpatialReference = new esri.SpatialReference({ wkid: dom.byId("bufferSpatialReference").value });
params.outSpatialReference = this.map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value];
params.unionResults = true;
params.geometries = [polygon]
if (type === "polygon") {
//if geometry is a polygon then simplify polygon. This will make the user drawn polygon topologically correct.
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
} else {
gsvc.buffer(params, lang.hitch(this, this._showBuffer),
function (err) {
alert("Query " + err);
});
}
Zhan,
Your method is working because to are manually merging the the polygons client side instead of allowing the Server to buffer all the geometries at once and then merge them server side as my code shows. Either way can you mark this thread as answered so that people can find the correct answer. Do this my clicking the "Correct Answer" link (with the little green star) on your reply or mine.
Hi Robert,
we need to check if geometry type is polygon then add feature geometry to the array.
if (feature.geometry.type == "polygon") {
bufferGeometry.push(feature.geometry)
}