Center map on startup location

This commit is contained in:
livio committed 2026-09-21 11:24:22 +02:00
1 parent 7933b2e86a
commit 0344227a1b
6 files changed
+155 -19

No files matched your search

+37
View File
@@ -291,6 +291,10 @@
<section class="panel-section">
<h2>GPS e percorso</h2>
<label class="toggle-line project-save-option">
<input type="checkbox" checked="@ShowGpsPosition" @onchange="ToggleGpsPosition" />
<span>Mostra punto e cerchio GPS</span>
</label>
<label class="toggle-line project-save-option">
<input type="checkbox" checked="@TrailEnabled" @onchange="ToggleTrail" />
<span>Registra la traccia mentre cammini</span>
@@ -363,6 +367,7 @@
private double? CatalogFraction { get; set; }
private bool CatalogBusy { get; set; }
private bool GpsActive { get; set; }
private bool ShowGpsPosition { get; set; } = true;
private bool DrawToolsVisible { get; set; }
private bool TrailEnabled { get; set; }
private bool LayerPanelOpen { get; set; }
@@ -453,10 +458,36 @@
if (firstRender)
{
await JS.InvokeVoidAsync("lmeMap.init");
await CenterOnInitialLocationAsync();
await MigrateLegacyProjectAsync();
}
}
private async Task CenterOnInitialLocationAsync()
{
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(12));
try
{
var location = await LocationService.GetCurrentLocationAsync(timeout.Token);
if (location is not null)
{
await JS.InvokeVoidAsync("lmeMap.showInitialPosition", location);
}
else
{
await JS.InvokeVoidAsync("lmeMap.showInfo", "Posizione iniziale non disponibile. La mappa resta utilizzabile normalmente.");
}
}
catch (OperationCanceledException)
{
await JS.InvokeVoidAsync("lmeMap.showInfo", "Ricerca della posizione iniziale scaduta. Usa Avvia GPS per riprovare.");
}
catch (Exception error)
{
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Posizione iniziale non disponibile: {error.GetBaseException().Message}");
}
}
private async Task MigrateLegacyProjectAsync()
{
try
@@ -680,6 +711,12 @@
}
}
private async Task ToggleGpsPosition(ChangeEventArgs args)
{
ShowGpsPosition = (bool?)args.Value == true;
await JS.InvokeVoidAsync("lmeMap.setGpsPositionVisible", ShowGpsPosition);
}
private async Task StartGps()
{
GpsActive = true;