Select to view content in your preferred language

Best Practice for Saving ViewPoint

445
2
01-05-2026 03:19 PM
RTC
by
Regular Contributor

Hello,

I am looking for techniques that anyone has used for saving the last viewpoint of a map so it can be recalled later when reloading the map. In a particular, when do you save the viewpoint, what observable are you watching, etc.  Just looking to see if there is a better/best way to do this. Any feedback would be much appreciated. Thanks!

 

0 Kudos
2 Replies
Ting
by Esri Regular Contributor
Esri Regular Contributor

2 cents from a few folks collective ideas, not an official best practice:

- Viewpoint is Codable, so serialize it and save it somewhere you like (for example, AppStorage, or UserDefaults.standard).

- If the web map has an initial viewpoint, use it to initialize the viewpoint you want to save.

- When the map view draw status becomes complete for the first time, save the viewpoint. The draw status is reported by onDrawStatusChanged(perform:) modifier on the map view.

- When the map view stops navigating, save the viewpoint. The navigation status is reported by onNavigatingChanged(perform:) modifier on the map view. Specifically, when the old value is true (the map view was navigating) and the new value is false (the map view stops navigating).

onViewpointChanged(kind:perform:) modifier to get the current viewpoint.

RTC
by
Regular Contributor

Thanks Ting, That it very similar to what our app does now. Good to know!