Esri / arcgis-maps-sdk-swift

Swift Package Manager support for ArcGIS Maps SDK for Swift
https://developers.arcgis.com/swift
Other
18 stars 1 forks source link

Set map and viewpoint immediately one after the other #14

Closed mmoosbac94 closed 3 months ago

mmoosbac94 commented 3 months ago

Hello everybody,

we are currently facing the issue, that we want to set a map and immediately afterwards a viewpoint. If we do that, the map is set but the viewpoint is not. So the call "proxy.setViewPoint" fails with "false". Pseudo-Example to demonstrate:

@Published var map: Map

func setMapWithViewPoint() async {
map = Map(item: portalItem)
await proxy.setViewpoint(viewPoint)
}

Do you have an idea what is the issue or how to solve it?

Thank you guys Marvin

yo1995 commented 3 months ago

Thanks for reaching out. Next time, please ask the question on Esri Community. This repo is for publishing the Swift Package and questions related to the API should be asked on the forum instead.

In regard to your question, it is an expected behavior. When a new map is set on the map view, the map view doesn't update immediately (map loading, view rendering, etc.). So if you call the setViewpoint with animation immediately after the map is set, the async call can be interrupted.

The solution is to set the desired viewpoint as the initialViewpoint on the map property. Such as

map = Map(basemapStyle: .arcGISTopographic)
map.initialViewpoint = Viewpoint(latitude: 34.02700, longitude: -118.80500, scale: 72_000)

so that the map view will zoom to the initial viewpoint once loaded.

mmoosbac94 commented 3 months ago

Its working now! Thank you very much for your help. Next time I will refer to the Esri Community.