AnsweredAssumed Answered

Remove graphics when popup visible is false ArcgIS API 4.X

Question asked by agole_waterboards on Oct 9, 2018
Latest reply on Oct 15, 2018 by agole_waterboards

Hi all,

 

I want to clear graphics and close popup on the close() button of the popup. I am using the watch method and it works great.

 

The issue I have with this method is that when I click to start the event listener, I want the function to clear all popups in the map previously opened by other functions.

 

 $("#clicking").click(function () {
                view.popup.close();
});

 

Since the watch event removes layers when view.popup.visible === false

 

 // Watch view's stationary property for becoming true.
            watchUtils.whenFalse(view.popup, "visible", function (visible) {
                // Get the new center of the view only when view is stationary.
                console.log(visible)
                view.graphics.removeAll();
                layerbuffer.removeAll();
            });

 

I can only add the layers once the popup is opened.

 

onclickhandler = view.on("click", function (event) {
                        var visible1 = view.popup.visible;
                        $('#viewDiv').css('cursor', 'pointer');
                        view.graphics.removeAll();
                        layerbuffer.removeAll();
                        geombuffer = view.toMap({
                            x: event.x,
                            y: event.y
                        });
                       
                        pointGraphic = new Graphic({
                            geometry: geombuffer,
                            symbol: symboltoclone
                        });
                        var buffer = geometryEngine.geodesicBuffer(geombuffer, 2000, "feet");
                        var graphicbuffer = new Graphic({
                            geometry: buffer,
                            symbol: fillSymbol
                        });
                        layerbuffer.graphics.add(graphicbuffer);
                        view.graphics.add(pointGraphic);
                        //Set up query for geom
                        var queryTask = new QueryTask({
                            url: nitratequeryurl
                        });
                        //Query to return California geometry
                        var query = new Query();
                        //Set the query
                        query.geometry = buffer;  // the point location of the pointer
                        query.outFields = ["OBJECTID "]
                        //return geometry
                        query.returnGeometry = true;
                        //Intersects
                        query.spatialRelationship = "intersects";
                        //Execute the query
                        queryTask.executeForCount(query).then(function (response) {
                           
                            view.popup.open({
                                title: "Search Results",
                                location: geombuffer,
                                content: "<br><center>Number of nitrate-impacted wells within 2000 feet of:<br><br><center>" + "<center>" + geombuffer.latitude.toFixed(3).toString() + "N &nbsp" + "," + Math.abs(geombuffer.longitude).toFixed(3).toString() + "W</center><br>" + "<center><b>" + response + " Wells</b><br><center><br><i>Drag marker to update location</i></center>"
                            })
                            layerbuffer.graphics.add(graphicbuffer);
                            view.graphics.add(pointGraphic);
                          
                            view.goTo({
                                target: pointGraphic,
                                zoom: 15
                            });
                           
                           
                        });
                    });

 

Is there a way to clear graphics only if you click on the "close" button of the popup instead of the watch? 

Outcomes