Esri / arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
https://esri.github.io/arcgis-maps-sdk-dotnet-toolkit/
Apache License 2.0
217 stars 121 forks source link

Toolkit Basemap Gallery doesn't display the Thumbnails properly #530

Open LuisRguezEsriSpain opened 1 year ago

LuisRguezEsriSpain commented 1 year ago

I am developing an application with MAUI.

When I run de app by using "Samsung Galaxy Tab A SM-T510" and "Samsung Galaxy Tab A SM-T580", Toolkit Basemap Gallery widget doesn't display the Thumbnails properly.

BasemapGalleryThumbnails

After creating a Esri Case, Esri recommend me submit a new Issue.

dotMorten commented 1 year ago

@LuisRguezEsriSpain Would you be able to share a small sample that reproduces the issue?

LuisRguezEsriSpain commented 1 year ago

I share a small sample.

PoCDrones.zip

dotMorten commented 1 year ago

Thank you. Were you only seeing this on Android, or only on certain Android devices? I see the basemaps both on Windows and on my Android: image

LuisRguezEsriSpain commented 1 year ago

Hi Morten,

I only see Thumbnails on certain Android devices.

Por example:

dotMorten commented 1 year ago

It looks like it is hitting this fallback:

https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/8e5bc024f51beea413b3f11541ed662854e38323/src/Toolkit/Toolkit.Maui/BasemapGallery/ByteArrayToImageSourceConverter.cs#L34

That data should be coming from here: https://github.com/Esri/arcgis-maps-sdk-dotnet-toolkit/blob/8e5bc024f51beea413b3f11541ed662854e38323/src/Toolkit/Toolkit/UI/Controls/BasemapGallery/BasemapGalleryItem.cs#L100

Since I can't reproduce, would you be able to debug what is happening on your specific Android devices and see why the thumbnails fail to load?

LuisRguezEsriSpain commented 1 year ago

Hi Morten,

This is the debug's result.

at RuntimeCoreNet.GeneratedWrappers.CoreImage.GetEncodedBuffer() at Esri.ArcGISRuntime.UI.RuntimeImage.GetEncodedBufferAsync(CancellationToken cancellationToken) at PoCDrones.BasemapGallery.BasemapGalleryItem.LoadImage() in C:\LuisRodriguez\Proyectos\ENAIRE\200_2\Incidencia\PoCDrones\PoCDrones\BasemapGallery\BasemapGalleryItem.cs:line 107

BasemapGalleryThumbnailsDebug1

BasemapGalleryThumbnailsDebug2

this.Thumbnail.Source.AbsoluteUri: "https://www.arcgis.com/sharing/rest/content/items/983b312ebd9b4d15a02e00f50acdb1c1/info/thumbnail/thumbnail1607564423352.jpeg"

BasemapGalleryThumbnailsDebug3

dotMorten commented 1 year ago

Thank you for the detailed screenshots. InvalidProgramException sounds like something went wrong in .NET or the compilation: https://learn.microsoft.com/en-us/dotnet/api/system.invalidprogramexception?view=net-7.0 Is your .NET up to date? Any chance you could also try with the latest .NET 8?

LuisRguezEsriSpain commented 1 year ago

Hi Morten,

I don't see how to create a ArcGIS Maps SDK .NET MAUI project using .NET.

DotNet8_1

I also don't see a way to change an existing project's .NET Framework.

DotNet8_2

dotMorten commented 1 year ago

.NET 8 shipped as final yesterday. If you update your visual studio to latest, you should now see it in your dropdown (before this you needed the preview release)

LuisRguezEsriSpain commented 10 months ago

Hi Morten,

I've installed the latest versión of visual studio.

LatestVSVersion

I've also installed ArcGIS_Maps_SDK_DotNet_Templates_200_3_0.vsix.

In project propertiens I cannot choose either "Target Android Framework" or "Minimum Target Android Framework".

TargetAndoird FW

In addition to this issue I have others issues:

ManifestError

dotMorten commented 10 months ago

@LuisRguezEsriSpain are you able to build a normal .NET MAUI app targeting .NET 8? Most of the settings you refer too are easiest set in the .csproj file directly.

LuisRguezEsriSpain commented 10 months ago

@dotMorten I've done this workaround in BasemapGalleryItem class and work properly:

        private async Task LoadImage()
        {
            IsLoadingThumbnail = true;
            try
            {
                await (Thumbnail?.LoadAsync() ?? Task.CompletedTask);

                if (Thumbnail?.LoadStatus == LoadStatus.Loaded)
                {
                    var stream = await Thumbnail.GetEncodedBufferAsync();
                    var buffer = new byte[stream.Length];
                    await stream.ReadAsync(buffer, 0, (int)stream.Length);
                    ThumbnailData = buffer;
#if WINDOWS_XAML
                    ThumbnailBitmap = await Thumbnail.ToImageSourceAsync();
#endif
                }
                _hasLoaded = true;
            }
            catch (Exception ex)
            {
                await LoadImageAux();
            }
            finally
            {
                IsLoadingThumbnail = false;
            }
        }

        private async Task LoadImageAux()
        {
            try
            {
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Thumbnail.Source);
                HttpClient client = new HttpClient(new HttpClientHandler());
                var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
                var content = response.EnsureSuccessStatusCode();
                var streamRes = await content.Content.ReadAsStreamAsync();
                byte[] buffer = new byte[16 * 1024];
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = await streamRes.ReadAsync(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    ThumbnailData = ms.ToArray();
                }
            }
            catch (Exception ex2)
            {
            }
        }