how to clear one by one selected feature from map layers

250
2
02-02-2021 12:08 AM
gorusivakumar
New Contributor

Hi All,

Im able to select the features in the map using multi selection widget, But how I can show the selected features and how can I give access to user to deselect/remove particular feature.

ex: user by mistake selected 4 features instead of 3,  later he wants to clear/remove the one feature from the list and can save only desired 3 features in map

0 Kudos
2 Replies
JeffK
by MVP Regular Contributor
MVP Regular Contributor

I don't know if this will help because I don't know what your code looks like, but I think you can use the remove() method on the highlight.  Check if the feature being clicked on is already highlighted and remove it if it is.

Take a look at the solution posted here, which looks like it uses a combination of ctrl key and mouse clicks to deselect.

Hope this helps.

Edit: looks like its a little more complicated now that I brought that solution into codepen.  I think the logic under it would be to get the current selection, check if it is in the array of selected features and if it is, pop it out.  The couple examples I've found and tried either remove all, or select only one item and deselects the previous.

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

I worked through that solution I posted above in a codepen, but instead of using the right mouse button to deselect, you hold down the cntrol key. Maybe it can help you,  deselct with ctrl+mouseclick 

0 Kudos