Hey everybody,
In my drawing app, I want to add the possibility of buffering a point. I got it to work, but I have one issue.
When I run it the first time everything goes ok. User checks the buffer checkbox, types in a buffer distance, selects the point button, clicks on the map and the buffer gets added to the map.
When I run it a 2nd time, it looks like it works again like it is supposed to, but this time two identical buffer get added. When I do it a third time 3 identical buffers get added and so on.
It seems that geometryService.on("buffer-complete") runs as often as I used the buffer before.
Here is the code snipped that is responsible for adding the buffer:
function addToMap(evt) {
Uni();
if ( evt === undefined){
console.log("undefined");
} else {
toolbar.deactivate();
var Testcolor = cp.value;
if (Testcolor == ""){
newColor = newColor;
} else {
docolor();
}
switch (evt.geometry.type) {
case "point":
case "multipoint":
symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, myNumber,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color(newColor), 1),
new Color(newColor));
break;
case "polyline":
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color(newColor), myNumber)
break;
default:
symbol = new SimpleFillSymbol(symbolfill, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color(newColor), myNumber), new Color(newColor));
break;
}
graphic = new Graphic(evt.geometry, symbol);
if (dijit.byId("BufferCheckBox").checked && evt.geometry.type == "point" ){
params = new BufferParameters();
params.geometries = [ evt.geometry ];
params.distances = [ dom.byId('BufferText').value ];
params.geodesic = true;
params.bufferSpatialReference = new SpatialReference({wkid: 102100});
params.outSpatialReference = map.spatialReference;
params.unit = Unit_Line;
geometryService.buffer(params);
geometryService.on("buffer-complete", function(evt) {
var Buffsymbol = new SimpleFillSymbol("none", new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color(newColor), 2), new Color(newColor));
Buffgraphic = new Graphic(evt.geometries[0], Buffsymbol);
map.graphics.add(Buffgraphic);
var operation2 = new CustomOperation.Add({
graphicsLayer: map.graphics,
addedGraphic: Buffgraphic
});
undoManager.add(operation2);
});
}
Any help is appreciated!
Thanks
Tim
Solved! Go to Solution.
The way it's currently written, every time you run the function addToMap, you add another listener for the geometryService's buffer-complete event. You have to either move that code outside your function or remove the listener once it's finished.
The way it's currently written, every time you run the function addToMap, you add another listener for the geometryService's buffer-complete event. You have to either move that code outside your function or remove the listener once it's finished.
Thanks Ken,
can't believe I missed that, especially since I already have listeners in my app!
Tim
Maybe the buffer is thinking that it is suppose to be using a multipoint?
- case "point":
- case "multipoint":
- symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, myNumber,
- new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
- new Color(newColor), 1),
- new Color(newColor));
- break;
Thanks Steven!
Ken's suggestions answered my question.