SetViewpointCenterAsync isn't actually in the center only on iOS

538
5
04-29-2022 05:51 AM
MatthiasPorges
New Contributor

The method SetViewpointCenterAsync doesn't actually set the view point to the center of the control on iOS but slightly above it. This does not happen on Android.

You can easily see this, if you have an active location source displayed and use this to center like this:

 

MapView.SetViewpointCenterAsync(MapView.LocationDisplay.Location.Position);

 

Unbenannt.png

The first screenshot includes a cursor image, where the correct center should be using a Xamarin AbsoluteLayout like this:

 

<AbsoluteLayout>
    <esriUI:MapView x:Name="MapView"
                    AbsoluteLayout.LayoutFlags="All"
                    AbsoluteLayout.LayoutBounds="0,0,1,1"/>
    <!-- Cursor -->
    <ffimageloadingsvg:SvgCachedImage x:Name="Cursor"
                                      AbsoluteLayout.LayoutFlags="PositionProportional"
                                      AbsoluteLayout.LayoutBounds="0.5,0.5,AutoSize,AutoSize"
                                      WidthRequest="25" HeightRequest="25"/>
</AbsoluteLayout>

 

My guess is, that the MapView somehow included the screen dead zone / area insets in it's center point calculation. I haven't found any property to disable this though.

Esri ArcGIS Runtime version 100.12.0. Screenshots taken on iPhone X.

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor

I'm looking at your screenshots and it appears to me that we can't actually see the bottom of the mapview, since the attribution area isn't visible. Is the mapview extending below those two bottom layouts you have?

Also note the center isn't based on the middle between the bottom and the top, but between the top and the top of the attribution.

If you do have the map being overlayed by other UI and want to take this into account for the center calculation, you can set the ViewInsets property to take this bit into account. For example: mapView.ViewInsets = new Thickness(0,0,0,height_of_overlay);

0 Kudos
MatthiasPorges
New Contributor

I set the IsAttributionTextVisible property to True so you can see that there is no other UI element above it. I also included a second screenshot where I wrap the element in a Xamarin-Frame control with a red Border and a Padding of 0 so that it makes sure, the whole control is visible.

Also keep in mind that this problem is only on iOS. It works fine on Android and this is a Xamarin-Forms application so the UI page should be the same.

0 Kudos
MatthiasPorges
New Contributor

I did some further testing, and it seems the MapView controls thinks the center is exactly 48 pixel off. I can "fix" this issue by actually adding a negative ViewInsets.Top value:

 

 

MapView.ViewInsets = new Thickness(0, -48, 0, 0);

 

 

48 pixel happens  to be exactly the height of the top safe area inset (aka the "notch") of the iPhone 11 simulator I'm testing on.

So this seems to further my suspicion: The control might somehow have a "hidden" Viewinset that takes the iPhones notch into account for the center calculation. I have to test this on multiple devices though to make sure.

I think this is a bug in the ArcGis runtime on iOS, because this does NOT happen on Android devices with a notch.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Yes you are right - I should have caught that earlier. It is indeed taking the safe area into account on iOS (this is by design / on purpose btw)

0 Kudos
MatthiasPorges
New Contributor

If it's by design, it should behave the same on Android devices with safe areas (at least on Xamarin Forms). There should also be a proper way to disable/adjust this that doesn't involve creating a negative value ViewInset with a self-calculated value.

Please consider changing this in the future.

0 Kudos