Skip to content

BugFix: Fixing BasemapGallery Sceneview appears blank sometimes. #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,34 @@ private async Task HandlePortalChanged()
await UpdateBasemaps();
}

private bool _pendingUpdateBasemaps;

public async Task UpdateBasemaps()
{
_pendingUpdateBasemaps = true;
if (IsLoading)
return;

IsLoading = true;
// Cancel any pending load before starting a new one
_loadCancellationTokenSource?.Cancel();
_loadCancellationTokenSource = new CancellationTokenSource();
try
{
_availableBasemaps = await PopulateBasemaps(_loadCancellationTokenSource.Token);
HandleAvailableBasemapsChanged();
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
while (_pendingUpdateBasemaps)
{
_pendingUpdateBasemaps = false;

_loadCancellationTokenSource?.Cancel();
_loadCancellationTokenSource = new CancellationTokenSource();
try
{
_availableBasemaps = await PopulateBasemaps(_loadCancellationTokenSource.Token);
HandleAvailableBasemapsChanged();
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
}
}
finally
{
Expand Down Expand Up @@ -284,18 +298,7 @@ private static bool BasemapIsActuallyNotABasemap(Basemap input)
return await LoadBasemapGalleryItems(Portal, cancellationToken);
}

private Task<ObservableCollection<BasemapGalleryItem>> LoadBasemapGalleryItems(ArcGISPortal portal, CancellationToken cancellationToken = default)
{
if (_loadBasemapGalleryItemsTask is null || _loadBasemapGalleryItemsTask.IsCompleted)
{
_loadBasemapGalleryItemsTask = LoadBasemapGalleryItemsInternal(portal, cancellationToken);
return _loadBasemapGalleryItemsTask;
}

return _loadBasemapGalleryItemsTask;
}

private async Task<ObservableCollection<BasemapGalleryItem>> LoadBasemapGalleryItemsInternal(ArcGISPortal portal, CancellationToken cancellationToken = default)
private async Task<ObservableCollection<BasemapGalleryItem>> LoadBasemapGalleryItems(ArcGISPortal portal, CancellationToken cancellationToken = default)
{
async Task<List<BasemapGalleryItem>> LoadBasemapsAsync(Func<CancellationToken, Task<IEnumerable<Basemap>>> getBasemapsFunc)
{
Expand Down
Loading