postit: debounce rdv reverse geocoding
This commit is contained in:
parent
5d502fd6a7
commit
82c479434e
2 changed files with 27 additions and 1 deletions
|
|
@ -133,6 +133,22 @@ public partial class RdvViewModel : BillingCommandPageViewModel
|
||||||
this.SetInfoStatus("Position sélectionnée sur la carte.");
|
this.SetInfoStatus("Position sélectionnée sur la carte.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void NotifyReverseGeocodingStarted()
|
||||||
|
{
|
||||||
|
this.SetInfoStatus(string.IsNullOrWhiteSpace(Address)
|
||||||
|
? "Recherche de l'adresse depuis la carte..."
|
||||||
|
: "Recherche d'une adresse suggérée..."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NotifyReverseGeocodingUnavailable()
|
||||||
|
{
|
||||||
|
if (HasSuggestedAddress || !string.IsNullOrWhiteSpace(Address))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.SetInfoStatus("Position sélectionnée sur la carte. Complétez l'adresse puis envoyez la commande.");
|
||||||
|
}
|
||||||
|
|
||||||
public void ApplyResolvedAddress(string address)
|
public void ApplyResolvedAddress(string address)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(address))
|
if (string.IsNullOrWhiteSpace(address))
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public partial class RdvPage : ContentPage
|
||||||
private const double DefaultLongitude = 2.3522;
|
private const double DefaultLongitude = 2.3522;
|
||||||
private const int DefaultZoomLevel = 4;
|
private const int DefaultZoomLevel = 4;
|
||||||
private const int SelectedZoomLevel = 13;
|
private const int SelectedZoomLevel = 13;
|
||||||
|
private static readonly TimeSpan ReverseGeocodingDebounce = TimeSpan.FromMilliseconds(350);
|
||||||
|
|
||||||
private MapControl? _locationMap;
|
private MapControl? _locationMap;
|
||||||
private MemoryLayer? _selectionLayer;
|
private MemoryLayer? _selectionLayer;
|
||||||
|
|
@ -182,15 +183,24 @@ public partial class RdvPage : ContentPage
|
||||||
_reverseGeocodeCts?.Cancel();
|
_reverseGeocodeCts?.Cancel();
|
||||||
_reverseGeocodeCts?.Dispose();
|
_reverseGeocodeCts?.Dispose();
|
||||||
_reverseGeocodeCts = new CancellationTokenSource();
|
_reverseGeocodeCts = new CancellationTokenSource();
|
||||||
|
var cancellationToken = _reverseGeocodeCts.Token;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
vm.NotifyReverseGeocodingStarted();
|
||||||
|
await Task.Delay(ReverseGeocodingDebounce, cancellationToken).ConfigureAwait(true);
|
||||||
|
|
||||||
var resolved = await _reverseGeocodingService
|
var resolved = await _reverseGeocodingService
|
||||||
.TryResolveAddressAsync(latitude, longitude, _reverseGeocodeCts.Token)
|
.TryResolveAddressAsync(latitude, longitude, cancellationToken)
|
||||||
.ConfigureAwait(true);
|
.ConfigureAwait(true);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(resolved))
|
if (!string.IsNullOrWhiteSpace(resolved))
|
||||||
|
{
|
||||||
vm.ApplyResolvedAddress(resolved);
|
vm.ApplyResolvedAddress(resolved);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.NotifyReverseGeocodingUnavailable();
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue