delete markers on button click

667
11
Jump to solution
03-30-2020 05:38 AM
rsharma
Occasional Contributor III

Hi i want to delete markers individual markers from my graphics layer on button click

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Rajni,

   That delete button is inside the popup right? The popup is associated with a specific feature (graphic) so you can call view.popup.selectedFeature.attributes.xyz to get the graphics xyz attribute.

View solution in original post

11 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Rajni,

   You need to loop (map) through the graphicsLayer.graphics and look for the graphic that has the attribute you which to delete and call remove.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GraphicsLayer.html#remove 

0 Kudos
rsharma
Occasional Contributor III

How to look for that exact marker which i want to delete on which i have clicked and delete button is on its popup.

I loop through marker layer and get all markers object in console, how to get exact current marker which is clicked

     jQuery('#main').on('click','.delete',function(){
            markerGL.graphics.map(function(gra){
              console.log(gra.geometry);
            });
        });

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Assign each graphic a unique id attribute when it is placed.

rsharma
Occasional Contributor III

Ok if i assign unique id to each marker, how to use .remove function  on trash btn of each marker popup.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Loop through the graphics and check each graphics attribute for the one you are looking for and call markerGL.remove(graphic);

rsharma
Occasional Contributor III

How do i know , i am looking for that graphics as i just clicked on it and try t delete it.

how to find that marker which is clicked

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Rajni,

   That delete button is inside the popup right? The popup is associated with a specific feature (graphic) so you can call view.popup.selectedFeature.attributes.xyz to get the graphics xyz attribute.

rsharma
Occasional Contributor III

The same problem arise here that i have to click outside of editablepolygon first then only my marker is clickable??

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

This is behavior as designed.

0 Kudos