AnsweredAssumed Answered

Buffer runs multiple times

Question asked by timw1984 Champion on Oct 9, 2014
Latest reply on Oct 9, 2014 by timw1984

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

Outcomes