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!
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.