.NET MAUI, Android: Map is not shown when navigated back to map-page

2749
22
Jump to solution
06-27-2023 10:34 AM
Labels (3)
SokoFromNZ
Occasional Contributor

Hi,

Since day one I have basically the same issue as described here: https://community.esri.com/t5/net-maps-sdk-questions/net-maui-map-not-loading-for-the-second-time/m-...

The issue persits on Android (emulator and real device). On Windows it is OK. iOS I cannot test.

See the attached example solution for your convenience (I'm using latest VS v17.6.4). 

Please provide a valid license and Apikey in MauiProgram.cs before starting...

The app starts like this:

SokoFromNZ_0-1687886895825.png

 

Then use the lower tab buttons to switch to the "Note" page:

SokoFromNZ_1-1687886922979.png

 

Switching back to the "Map" page shows the watermark, but now map:

SokoFromNZ_3-1687886971583.png

 

If you just move the finger on the "empty" map, it appears again.

 

I reckon it is a Maui bug...as most of the issues we are having 😞

But I haven't found any workaround yet and my customer gets really annoyed by this bug now as it is in our app since day one and Maui does not seem to improve.

Would be great if you can give me a little insight on this behaviour and maybe let me know a workaround.

Thanks

Soko

0 Kudos
1 Solution

Accepted Solutions
SokoFromNZ
Occasional Contributor

@dotMorten_esri : While re-testing this bug with the latest versions of all I've found a _severe_ bug which I'd like to draw your attention to!

I've found the blank map is fixed  => your original workaround is not needed anymore. Although with active GPS the fatal crash above is still a no-go. 
To not stretch this bug too far lets continue on the new one and treat this one as closed

View solution in original post

0 Kudos
22 Replies
SokoFromNZ
Occasional Contributor

@MatveiStefarov : As you drew the attention of the developer  to the KML pixelation bug I would like to ask you to have a look here too as this bug is imho way more severe and nobody has had a look at it yet.

Thanks in advance.

0 Kudos
dotMorten_esri
Esri Notable Contributor

I'm able to reproduce your issue. Still investigating the root cause, but I was able to work around it with this bit of code in MainPage.xaml:

 

    protected override void OnAppearing()
    {
#if ANDROID
        if (MyMapView.GetCurrentViewpoint(ViewpointType.CenterAndScale) is Viewpoint vp)
            MyMapView.SetViewpoint(vp);
#endif
    }

 

SokoFromNZ
Occasional Contributor

Thanks @dotMorten_esri for taking the time!

I will give your workaround a try.

There has been related news though since I've opened this topic.

The workaround for the user was to just to move the finger a little over the map and it appeared again.

But now they experience a different (more severe) issue:
After a couple of page changes (back an forth) the "move-finger-fix" does not work anymore. But only if GPS tracking is active! Only a complete restart of the app brings it to life again.

Unfortunately I haven't found a reproducable workflow for this issue. But maybe your developers can have this in mind when looking for the issue above...

thx Soko

PS: By GPS tracking active i mean:

MapView.LocationDisplay.IsEnabled = true;
MapView.LocationDisplay.AutoPanMode = DefaultAutoPanMode;
await MapView.LocationDisplay.DataSource!.StartAsync();

 

0 Kudos
dotMorten_esri
Esri Notable Contributor

This workaround should no longer be needed with 200.3

0 Kudos
SokoFromNZ
Occasional Contributor

Hi again,

I've tried your workaround and it worked. So the users don't have to move the map a little with their finger anymore to see it again.

But the issue with GPS active is still there even with your code snipped in place 😞

0 Kudos
SokoFromNZ
Occasional Contributor

Hi again,

After a couple of days with try & error I was able to create a workaround for the disappearance of the map when GPS is active.

It seems that setting the ViewPoint as @dotMorten_esri suggested above is not enough.

Instead I have to resize a little the MapView like this:

// -1 means in .NET MAUI apparently "not set". So everytime the page comes into view I toggle between "not set" and the last height of "not set" + 0.1
MyMapView.HeightRequest = Math.Abs(MyMapView.HeightRequest - (-1)) < 0.001 && MyMapView.Height > 0 ? MyMapView.Height + 0.1d : -1;

 

I've also tried forcing a new Measure round and/or Layout with `IView.InvalidateMeasure()` or `Page.ForceLaout()` on the MyMapView, the Grid containing it, or the whole Page...but nothing helped...only the above.

I hope this helps somehow to find the root issue of this.

Ohh...and maybe it also has something to do with this other issue where the Map also stayed empty...

Soko

0 Kudos
esp1rl
by
New Contributor III

Hi, I'm experiencing this issue on Windows, iOS and Android. With both .NET 7 and .NET 8 RTM. I'm using Esri.ArcGISRuntime.Maui v200.2.0

I found this issue to be linked with the use of location tracking and the MAUI shell tab pages. I think something goes haywire when the user spend time on another tab (not having the map) and the location tracker is still updating the MapView which is out of view.

It is a very reproducible issue, but there is some randomness to it. I have not been able to make a step by step process to reproduce it.

 

0 Kudos
esp1rl
by
New Contributor III

After debugging for a while I managed to discover the nature of this issue. FYI @dotMorten_esri 

Listening to MapView.DrawStatusChanged I found that it would get stuck in InProgress when switching tabs. See code comments below.

 

protected override void OnDisappearing()
{
    /* This is a workaround for a bug in ArcGIS Maps SDK where the internal rendering engine freezes
     * if the map is not fully rendered when the page disappears.
     *
     * It is easier to reproduce when using LocationDisplay which is within view as that
     * will cause the map to be constantly re-rendered.
     */

    while (MapView.DrawStatus == DrawStatus.InProgress)
    {
        // occupy the UI thread for a while, waiting for the map to finish rendering
        Thread.Sleep(TimeSpan.FromMilliseconds(10));
    }
    base.OnDisappearing();
}

 

SokoFromNZ
Occasional Contributor

Looks like a great find, thanks! I will give it a try intead of my workaround once I find the time.

PS: This is the OnDisappearing() of the page, correct? Code is in the CodeBehind-CS-File of the page...

0 Kudos