Delete clicked boundary

866
10
Jump to solution
04-30-2020 03:20 AM
rsharma
Occasional Contributor III

Hi,

I want to know how to delete that boundary or polygon which is doubleclicked.

I know we can do it like this, but how to know that which polygon got clicked so that i ll get its graphics.

My polygons coming from db and i am createing new polygons also. found this link,

But don't know how it works for 4.14

Selecting and removing graphic (by rings array) in ArcGIS JSapi 3.x  

Robert Scheitlin, GISP‌ u have answered the above question, is their any otherway, i can delete my editable polygons one at a time

graphicslayer.remove(gra);

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   This should not be difficult for you to figure out. Right now you have one or more view.on click listener functions. Just add a view on dbl click listener and then add the view.hit test logic there (just like you have in the on click event handler).

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#event-double-c... 

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   This should not be difficult for you to figure out. Right now you have one or more view.on click listener functions. Just add a view on dbl click listener and then add the view.hit test logic there (just like you have in the on click event handler).

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#event-double-c... 

rsharma
Occasional Contributor III

Hi Sir,

I tried your way, in console, i get that exact polygon clicked, but i could not able to remove that graphics from map

with graphicslayer.remove method

Am i missing something??

Do i have to use other function.

    view.on("double-click", function(event){
              view.hitTest(event).then(function(response) {
                var results = response.results;
               results.forEach(function(result) {
                if(result.graphic.geometry.type==='polygon'&&result.graphic.layer === sketchViewModel.layer && result.graphic.attributes && result.graphic.attributes.newDevelopment){
                    console.log(result.graphic);  
                    graphicslayer.remove(result.graphic);
                  }
                });
              });
           });

0 Kudos
rsharma
Occasional Contributor III

I tried 2 methods, both don't work out, while console return me the exact that polygon that i clicked, but still stucked to delete it.

I want to delete polygons of graphics layer only.

view.on("double-click", function(event){
              view.hitTest(event).then(function(response) {
                var results = response.results;
               results.forEach(function(result) {
                if(result.graphic.geometry.type==='polygon'&&result.graphic.layer === sketchViewModel.layer && result.graphic.attributes && result.graphic.attributes.newDevelopment){
                    console.log(result.graphic);  
                   /*graphicslayer.remove(result.graphic);
                  view.graphics.remove(result.graphic);*/
                  }
                });
              });
           });

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   As a developer you need to figure out if the fact that it is not working in your code is due to any of your other code. So make a simple NEW app that only have the double click delete event listener to test if it work for you there.

rsharma
Occasional Contributor III

sir my double click listener is running fine, i have consoled and get the boundary clicked as polygon , but i didn't get it how to delete it. Both of these method below not working to delete

/*graphicslayer.remove(result.graphic);
                  view.graphics.remove(result.graphic);*/

While my console in this code return my clicked polygon as graphic

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

I don't doubt that you are getting into the listener. But my reply still stands you need to test an app that is devoid of all your other listener events to rule out code overriding each other.

rsharma
Occasional Contributor III

is their any right click event?as double click bydefault zoom also while deleting.

I searched it, but didn't get any right-click event

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rajni,

   No there is no specific event for right click. You have to check the regular click events 

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#event-click 

Button property for the right click.

0 Kudos
rsharma
Occasional Contributor III

How to use this property with, no example given  with property specified 0,1,2

view.on("click", function(event) {
0 Kudos