I've been banging on this one for a few weeks now, any help/suggestions/comments are greatly appreciated!
-Tom Klempay (Senior Software Engineer, AnglerLabs)
Hi Tom,
Thanks for the write-up and video showing the issue. A couple questions:
1) Once the basemap is shown at full extent, if you back out of the map and reopen again, does it honor the initial viewpoint? Just curious if once the viewpoint is not honored, it remains so.
2) If you use a basemap that does not require an API Key, do you see the same issue? This is just for testing, not for production.
3) Are you creating a new MapView and Map each time you open a trip - or just a new Map?
Thanks
-Rex
1) for iOS, it does seem that once it shows the global map, its stuck on it until I restart the app. Android does not behave that way but I think it's because on Android, a new instance of the Map is created each time you enter the page.
2) Not sure, I'll have to try that and get back to you.
3) For Android, yes, a new Map/MapView is created each time. For iOS, only one instance of a Map/MapView is created.
Let me know if you need any other info. Thanks!
Hi,
I’m sorry to hear you’re seeing problems with Map display. It is hard to tell for certain what is going on without seeing the full code, but I do have some ideas based on what you’ve shared.
I see in the video that the map appears to be moving in the cases where the viewpoint successfully loads. Are you using a LocationDisplay or LocationDataSource to navigate the map based on device location after the map is displayed?
Thanks,
Nathan
Nathan,
re: your bullet points
Thanks much for your suggestions!
Regards,
-Tom
Tom,
Yes, ideally viewpoint should be set after the map is added to the MapView. That may require a small amount of refactoring to break this code into two parts, one to create the map, another to call `mapView.SetViewpoint` or `mapView.SetViewpointAsync`. Alternatively, you might be able to follow the pattern in `AddGraphicsOverlays` to interact with the MapView.
Since the GetMap is already an async Task, you should be able to insert `await _map.LoadAsync` before returning the map. That will ensure the map is loaded before it is added to the map. If you explicitly load the map by calling `_map.LoadAsync` before returning, you can then check `_map.LoadStatus` rather than setting up an event. Although if you are already making the change to calling SetViewpoint on the MapView, then you should only need the explicit loading step if you want to do error handling.
Updated code might look something like the following:
try
{
var basemap = await _currentMapStyle.ToEsri();
_map = new Map(basemap);
await _map.LoadAsync();
_mapView.Map = _map; // Or alternatively do this in a separate method
AddGraphicsOverlays();
await _mapView.SetViewpointAsync(initialLatitude, initialLongitude, _defaultZoom);
}
catch //... error handling - explicit loading of map should throw exceptions that you can catch
Hi Nathan,
Want to give you a quick update. I was able to incorporate much of what you suggested and in my dev testing, things are really looking good on both iOS and Android. Our next step is to push my changes into our test environment. We're rolling that out today. I'll let you know how it goes.
-Tom