Select to view content in your preferred language

Remove Locate Widget's graphic

571
2
Jump to solution
09-12-2023 06:54 PM
kprenesti
Emerging Contributor

Hello all! I have a project where one of the requirements is to toggle the My Location graphic on and off.  To Toggle the icon on, I am using the native Locate functionality, which zooms to my location and shows the graphic.  Toggling it off should mean simply removing the graphic, but I'm not sure how to do that.  Oh, and in case it matters, I'm working in Vue 3.

Any ideas? Thanks!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Sage_Wall
Esri Contributor

Hi @kprenesti The locate graphic is stored in the view's graphics collection.  I think you should be able to remove it like this

view.graphics.remove(locate.graphic);

 if you Locate widget was named "locate".

Wrote a quick codepen here: https://codepen.io/sagewall/pen/rNowYoN 

View solution in original post

0 Kudos
2 Replies
Sage_Wall
Esri Contributor

Hi @kprenesti The locate graphic is stored in the view's graphics collection.  I think you should be able to remove it like this

view.graphics.remove(locate.graphic);

 if you Locate widget was named "locate".

Wrote a quick codepen here: https://codepen.io/sagewall/pen/rNowYoN 

0 Kudos
kprenesti
Emerging Contributor

Thank you! Also, you need to cancel the locate so it doesn't show up again.  Thanks again!

0 Kudos