Navigating to bounding box in Mapsui.Maui not working correctly

162 views Asked by At

I am trying to use the ZoomToBox API to zoom the map showing two location pins. The code works on Windows when the initial windows is not resized. When the initial window is resized to be smaller, then the zoom is insufficient - the pins are not visible (although they are not that far away from the displayed map bunds). This behavior is the same on Android emulator and also a physical device (Zebra TC77). I have created a minimal repro on GitHub - all the relevant code is in the MainPage.xaml.cs.

This is the correct display on Windows: Windows - correct.

This is the resized display on windows: Windows - resized.

This is the Android emulator (Galaxy Nexus): Android Emulator.

And finally, this is the Zebra TC77:

Android Device.

Please note that a similar issue is discussed here using some old APIs that are no longer available and with the conclusion that "The Navigator code was rewritten. I assume this is not relevant anymore."

1

There are 1 answers

0
Palo Mraz On BEST ANSWER

Oops, my bad, TL;DR: I was passing the wrong MBoxFit enumeration value to the ZoomToBox API: was MBoxFit.Fill, should have been MBoxFit.Fit.

Fill uses the smaller viewport resolution, Fit uses the larger. In the case of portrait device orientation Fill uses smaller screen width, which results in the described behavior. Fit uses the larger one, which is screen heigh, correcting the results. Thanks to to beauty of OSS - FMI: ZoomToBox and the used ZoomHelper.CalculateResolutionForWorldSize.