AnsweredAssumed Answered

How to remove all graphics from only one function at a time

Question asked by AlexSabrina on Oct 1, 2014
Latest reply on Oct 2, 2014 by AlexSabrina

Hi all,

I am trying to figure out how to remove graphics from only one function at a time. I have two sets of graphics: the one for drawing polygons and the one to add marker to map when coordinates are added. I always use:

 map.graphics.clear();

 

but it clears ALL the graphs from both functions. Is there a way to keep them separated?

 

My map is here.

 

function coordinates() {
                         console.log("Coordinates");
                         var lat = document.getElementById("sel_lat").value;
                         var longitude = document.getElementById("sel_long").value;
                         var mp = new Point(longitude, lat);
                         var graphic = new Graphic(mp, symbol);
                         map.graphics.add(graphic);
                         map.centerAndZoom(mp, 9);


                     }


                     function clear() {
                         console.log("Clearing")
                         map.graphics.clear();
                     }


                     //Button to select features and deactivate select toolbar


                     on(dom.byId("polygon"), "click", function () {
                         activateTool(this.id);
                     });


                     on(dom.byId("freehandpolygon"), "click", function () {
                         activateTool(this.id);
                     });


                     on(dom.byId("stop"), "click", function () {
                         map.graphics.clear();
                         selectionToolbar.deactivate();
                     });


                     //Initiate Select Draw tool on map load dojo.connect


                     dojo.connect(map, "onLoad", function () {
                        
                         selectionToolbar = new Draw(map);
                         selectionToolbar.on("draw-end", function (e) {
                             selectionToolbar.deactivate();


                             var symbol3 = new SimpleFillSymbol(
                                "solid",
                                "solid",
                                new SimpleLineSymbol("dash", new Color([255, 0, 0]), 2),
                                new Color([255, 255, 0, 0.25])
                             );


                             var graphic = new Graphic(e.geometry, symbol3);
                             map.graphics.add(graphic);
                         });




                     });


                     function activateTool(tool) {
                         map.graphics.clear();
                         // The draw.activate expects a string like "polygon" or "freehand_polygon".
                         selectionToolbar.activate(tool);
                     }

 

Thank you,

Alex

Outcomes