Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32a36c98ec | ||
|
|
06050b05f5 |
No files matched your search
+141
-32
@@ -4,6 +4,7 @@
|
||||
@inject CadastralCatalogService CatalogService
|
||||
@inject OfficialCadastreService OfficialCadastreService
|
||||
@inject LocationSearchService LocationSearchService
|
||||
@inject NetworkLocationService NetworkLocationService
|
||||
@inject AzureMapsService AzureMapsService
|
||||
@inject ProjectStorageService ProjectStorageService
|
||||
@implements IAsyncDisposable
|
||||
@@ -11,7 +12,7 @@
|
||||
<PageTitle>LME Mappe Catastali</PageTitle>
|
||||
|
||||
<div class="map-app">
|
||||
<section class="map-stage">
|
||||
<section class="map-stage @(ActiveTab == "search" ? "search-active" : null)">
|
||||
<div id="map"></div>
|
||||
|
||||
<header class="map-toolbar">
|
||||
@@ -72,16 +73,6 @@
|
||||
<button class="gps-center" @onclick="CenterOnGps" aria-label="Centra posizione">Centra</button>
|
||||
</div>
|
||||
|
||||
@if ((ActiveTab is "map" or "search") && !LayerPanelOpen)
|
||||
{
|
||||
<div class="map-measure-tools @(ActiveTab == "search" ? "search-open" : null)" aria-label="Strumenti rapidi di misura">
|
||||
<span>Misura</span>
|
||||
<button title="Disegna e misura un'area" @onclick='() => StartMeasurementDrawing("area")'>Area</button>
|
||||
<button title="Disegna e misura una distanza" @onclick='() => StartMeasurementDrawing("distance")'>Distanza</button>
|
||||
<button title="Disegna e misura un cerchio" @onclick='() => StartMeasurementDrawing("circle")'>Cerchio</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (ActiveTab is not "map" and not "search")
|
||||
{
|
||||
<aside class="tool-sheet">
|
||||
@@ -177,6 +168,11 @@
|
||||
? "Attivato: importa foglio, particelle e altri elementi KML/KMZ."
|
||||
: "Disattivato: importa solo i poligoni delle particelle riconosciute.")
|
||||
</small>
|
||||
<label class="toggle-line project-save-option">
|
||||
<input type="checkbox" checked="@ShowImportedSheetLayer" @onchange="ToggleImportedSheetLayer" />
|
||||
<span>Mostra cornice/layer del foglio importato</span>
|
||||
</label>
|
||||
<small class="field-help">La cornice grande resta separata dalle particelle e puo essere nascosta anche nei progetti salvati.</small>
|
||||
<label class="toggle-line project-save-option">
|
||||
<input type="checkbox" checked="@ShowImportedMeasurements" @onchange="ToggleImportedMeasurements" />
|
||||
<span>Mostra misure dei file caricati</span>
|
||||
@@ -194,7 +190,7 @@
|
||||
<span>Mostra superficie, perimetro e lati</span>
|
||||
</label>
|
||||
<button class="secondary-command" aria-pressed="@DrawToolsVisible" @onclick="ToggleDrawTools">
|
||||
@(DrawToolsVisible ? "Nascondi barra completa" : "Mostra barra completa")
|
||||
@(DrawToolsVisible ? "Nascondi strumenti sulla mappa" : "Mostra strumenti sulla mappa")
|
||||
</button>
|
||||
<button class="danger-command" @onclick="ClearDrawings">Elimina disegni e POI</button>
|
||||
</section>
|
||||
@@ -267,7 +263,7 @@
|
||||
</label>
|
||||
<label>
|
||||
Trasparenza catasto
|
||||
<input type="range" min="0" max="1" step="0.05" value="0.75" @onchange="ChangeCadastreOpacity" />
|
||||
<input type="range" min="0" max="1" step="0.05" value="@CadastralOpacity.ToString(System.Globalization.CultureInfo.InvariantCulture)" @onchange="ChangeCadastreOpacity" />
|
||||
</label>
|
||||
</section>
|
||||
|
||||
@@ -365,6 +361,7 @@
|
||||
private string SelectedParcelNumber { get; set; } = string.Empty;
|
||||
private string CatalogMessage { get; set; } = string.Empty;
|
||||
private double? CatalogFraction { get; set; }
|
||||
private double CadastralOpacity { get; set; } = 0.75;
|
||||
private bool CatalogBusy { get; set; }
|
||||
private bool GpsActive { get; set; }
|
||||
private bool ShowGpsPosition { get; set; } = true;
|
||||
@@ -373,6 +370,7 @@
|
||||
private bool LayerPanelOpen { get; set; }
|
||||
private bool IncludeCadastralParcels { get; set; } = true;
|
||||
private bool IncludeKmlSheetLayer { get; set; }
|
||||
private bool ShowImportedSheetLayer { get; set; }
|
||||
private bool ShowImportedMeasurements { get; set; }
|
||||
private bool ShowDrawingMeasurements { get; set; } = true;
|
||||
private bool ProjectBusy { get; set; }
|
||||
@@ -463,15 +461,79 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CenterOnInitialLocationAsync()
|
||||
private async Task ConfigureProjectMapProviderAsync(string snapshot)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(12));
|
||||
string? baseLayer = null;
|
||||
try
|
||||
{
|
||||
var location = await LocationService.GetCurrentLocationAsync(timeout.Token);
|
||||
using var document = System.Text.Json.JsonDocument.Parse(snapshot);
|
||||
if (document.RootElement.TryGetProperty("displayOptions", out var displayOptions)
|
||||
&& displayOptions.TryGetProperty("baseLayer", out var baseLayerProperty))
|
||||
{
|
||||
baseLayer = baseLayerProperty.GetString();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (baseLayer?.StartsWith("google-", StringComparison.Ordinal) == true
|
||||
&& !string.IsNullOrWhiteSpace(GoogleMapsApiKey))
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.configureGoogleMaps", GoogleMapsApiKey.Trim());
|
||||
}
|
||||
|
||||
if (baseLayer?.StartsWith("azure-", StringComparison.Ordinal) == true
|
||||
&& !string.IsNullOrWhiteSpace(AzureMapsSubscriptionKey))
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.configureAzureMaps", AzureMapsSubscriptionKey.Trim());
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Loading continues with the default map if the saved provider is unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CenterOnInitialLocationAsync()
|
||||
{
|
||||
NetworkLocationSnapshot? networkLocation = null;
|
||||
try
|
||||
{
|
||||
using var networkTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(8));
|
||||
networkLocation = await NetworkLocationService.GetApproximateLocationAsync(networkTimeout.Token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// An unavailable IP service must not prevent the GPS fallback.
|
||||
}
|
||||
|
||||
if (networkLocation is not null)
|
||||
{
|
||||
await JS.InvokeVoidAsync(
|
||||
"lmeMap.showInitialPosition",
|
||||
networkLocation.Latitude,
|
||||
networkLocation.Longitude,
|
||||
true,
|
||||
networkLocation.Label);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var gpsTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(18));
|
||||
var location = await LocationService.GetCurrentLocationAsync(gpsTimeout.Token);
|
||||
if (location is not null)
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.showInitialPosition", location);
|
||||
await JS.InvokeVoidAsync(
|
||||
"lmeMap.showInitialPosition",
|
||||
location.Latitude,
|
||||
location.Longitude,
|
||||
false,
|
||||
string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -480,7 +542,7 @@
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", "Ricerca della posizione iniziale scaduta. Usa Avvia GPS per riprovare.");
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", "Posizione iniziale non disponibile. Usa Avvia GPS per riprovare.");
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
@@ -823,13 +885,25 @@
|
||||
}
|
||||
|
||||
private Task FitImportedLayers() => JS.InvokeVoidAsync("lmeMap.fitImported").AsTask();
|
||||
private Task ClearImportedLayers() => JS.InvokeVoidAsync("lmeMap.clearImported").AsTask();
|
||||
private async Task ClearImportedLayers()
|
||||
{
|
||||
ShowImportedSheetLayer = false;
|
||||
await JS.InvokeVoidAsync("lmeMap.clearImported");
|
||||
}
|
||||
private Task AddProjectMarker() => JS.InvokeVoidAsync("lmeMap.addProjectMarker", PoiName).AsTask();
|
||||
|
||||
private async Task ToggleKmlSheetLayer(ChangeEventArgs args)
|
||||
{
|
||||
IncludeKmlSheetLayer = (bool?)args.Value == true;
|
||||
ShowImportedSheetLayer = IncludeKmlSheetLayer;
|
||||
await JS.InvokeVoidAsync("lmeMap.setIncludeKmlSheetLayer", IncludeKmlSheetLayer);
|
||||
await JS.InvokeVoidAsync("lmeMap.setImportedSheetLayerVisible", ShowImportedSheetLayer);
|
||||
}
|
||||
|
||||
private async Task ToggleImportedSheetLayer(ChangeEventArgs args)
|
||||
{
|
||||
ShowImportedSheetLayer = (bool?)args.Value == true;
|
||||
await JS.InvokeVoidAsync("lmeMap.setImportedSheetLayerVisible", ShowImportedSheetLayer);
|
||||
}
|
||||
|
||||
private async Task ToggleImportedMeasurements(ChangeEventArgs args)
|
||||
@@ -844,17 +918,6 @@
|
||||
await JS.InvokeVoidAsync("lmeMap.setDrawingMeasurementsVisible", ShowDrawingMeasurements);
|
||||
}
|
||||
|
||||
private async Task StartMeasurementDrawing(string mode)
|
||||
{
|
||||
DrawToolsVisible = false;
|
||||
await JS.InvokeVoidAsync("lmeMap.setDrawToolsVisible", false);
|
||||
ActiveTab = "map";
|
||||
LayerPanelOpen = false;
|
||||
await Task.Delay(30);
|
||||
await JS.InvokeVoidAsync("lmeMap.resize");
|
||||
await JS.InvokeVoidAsync("lmeMap.startMeasurementDrawing", mode);
|
||||
}
|
||||
|
||||
private async Task ToggleDrawTools()
|
||||
{
|
||||
DrawToolsVisible = !DrawToolsVisible;
|
||||
@@ -951,7 +1014,9 @@
|
||||
try
|
||||
{
|
||||
var snapshot = await ProjectStorageService.LoadAsync(project.Id);
|
||||
await JS.InvokeVoidAsync("lmeMap.loadProjectSnapshot", snapshot, project.Name);
|
||||
await ConfigureProjectMapProviderAsync(snapshot);
|
||||
var displayOptions = await JS.InvokeAsync<ProjectDisplayOptions>("lmeMap.loadProjectSnapshot", snapshot, project.Name);
|
||||
ApplyProjectDisplayOptions(displayOptions);
|
||||
NewProjectName = project.Name;
|
||||
IncludeCadastralParcels = project.IncludesCadastralParcels;
|
||||
ActiveTab = "map";
|
||||
@@ -968,6 +1033,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyProjectDisplayOptions(ProjectDisplayOptions options)
|
||||
{
|
||||
SelectedBaseLayer = options.BaseLayer;
|
||||
CadastralOpacity = options.CadastreOpacity;
|
||||
IncludeKmlSheetLayer = options.IncludeKmlSheetLayer;
|
||||
ShowImportedSheetLayer = options.ImportedSheetsVisible;
|
||||
ShowImportedMeasurements = options.ShowImportedMeasurements;
|
||||
ShowDrawingMeasurements = options.ShowDrawingMeasurements;
|
||||
DrawToolsVisible = options.DrawToolsVisible;
|
||||
ShowGpsPosition = options.GpsPositionVisible;
|
||||
TrailEnabled = options.TrailEnabled;
|
||||
|
||||
var activeLayers = (options.CadastreLayers ?? []).ToHashSet(StringComparer.Ordinal);
|
||||
foreach (var layer in CadastralLayers)
|
||||
{
|
||||
layer.Enabled = activeLayers.Contains(layer.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteProject()
|
||||
{
|
||||
var project = Projects.FirstOrDefault(item => item.Id == SelectedProjectId);
|
||||
@@ -1089,7 +1173,18 @@
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Chiave Azure Maps non salvata: {error.GetBaseException().Message}");
|
||||
}
|
||||
}
|
||||
private Task ChangeCadastreOpacity(ChangeEventArgs args) => JS.InvokeVoidAsync("lmeMap.setCadastreOpacity", args.Value?.ToString()).AsTask();
|
||||
private async Task ChangeCadastreOpacity(ChangeEventArgs args)
|
||||
{
|
||||
var text = args.Value?.ToString();
|
||||
if (!double.TryParse(text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var value)
|
||||
&& !double.TryParse(text, out value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CadastralOpacity = Math.Clamp(value, 0, 1);
|
||||
await JS.InvokeVoidAsync("lmeMap.setCadastreOpacity", CadastralOpacity);
|
||||
}
|
||||
|
||||
private async Task ToggleCadastreLayer(CadastralLayer layer, ChangeEventArgs args)
|
||||
{
|
||||
@@ -1124,6 +1219,20 @@
|
||||
public string Detail { get; } = detail;
|
||||
}
|
||||
|
||||
private sealed class ProjectDisplayOptions
|
||||
{
|
||||
public string BaseLayer { get; init; } = "satellite";
|
||||
public double CadastreOpacity { get; init; } = 0.75;
|
||||
public string[] CadastreLayers { get; init; } = [];
|
||||
public bool IncludeKmlSheetLayer { get; init; }
|
||||
public bool ImportedSheetsVisible { get; init; }
|
||||
public bool ShowImportedMeasurements { get; init; }
|
||||
public bool ShowDrawingMeasurements { get; init; } = true;
|
||||
public bool DrawToolsVisible { get; init; }
|
||||
public bool GpsPositionVisible { get; init; } = true;
|
||||
public bool TrailEnabled { get; init; }
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
CancelCatalogWork();
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
<ApplicationId>com.companyname.lmemappecatastaliapp</ApplicationId>
|
||||
|
||||
<!-- Versions -->
|
||||
<ApplicationDisplayVersion>0.2.10</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>14</ApplicationVersion>
|
||||
<ApplicationDisplayVersion>0.2.12</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>16</ApplicationVersion>
|
||||
|
||||
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
|
||||
<WindowsPackageType>None</WindowsPackageType>
|
||||
|
||||
@@ -20,6 +20,7 @@ public static class MauiProgram
|
||||
builder.Services.AddSingleton<CadastralCatalogService>();
|
||||
builder.Services.AddSingleton<OfficialCadastreService>();
|
||||
builder.Services.AddSingleton<LocationSearchService>();
|
||||
builder.Services.AddSingleton<NetworkLocationService>();
|
||||
builder.Services.AddSingleton<AzureMapsService>();
|
||||
builder.Services.AddSingleton<ProjectStorageService>();
|
||||
|
||||
|
||||
@@ -10,16 +10,16 @@ App .NET MAUI Blazor Hybrid per Android, iOS, Mac Catalyst e Windows, pensata pe
|
||||
- Interrogazione WMS con click/tap sulla mappa.
|
||||
- Import di file KML, KMZ, GeoJSON e JSON.
|
||||
- Import GeoJSON compatibile con BOM, geometrie singole, array, FeatureCollection e coordinate Web Mercator EPSG:3857.
|
||||
- Filtro KML/KMZ `solo particelle` attivo per impostazione predefinita, con separazione dei MultiPolygon ed esclusione di GroundOverlay e perimetri del foglio; il layer foglio resta importabile tramite opzione.
|
||||
- Filtro KML/KMZ `solo particelle` attivo per impostazione predefinita, con separazione dei MultiPolygon ed esclusione di GroundOverlay e perimetri del foglio; il layer foglio resta importabile e puo essere mostrato o nascosto separatamente.
|
||||
- Inquadramento e pulizia dei layer importati.
|
||||
- Disegno di marker, linee, poligoni e rettangoli.
|
||||
- Modalita rapide Area, Distanza e Cerchio disponibili direttamente sulla mappa, con superficie, perimetro, raggio, circonferenza e lunghezza dei singoli lati.
|
||||
- Area, Distanza e Cerchio disponibili nella barra Leaflet laterale, nascosta all'avvio e controllata dal pulsante nel tab Dati insieme agli altri strumenti.
|
||||
- Misure permanenti attivabili anche sui layer importati da KML, KMZ e GeoJSON.
|
||||
- Toolbar di disegno completa di icone, modifica, eliminazione singola e pulizia di tutti i disegni/POI.
|
||||
- Archivio multiprogetto nella cartella privata dell'app, con nome, selezione da elenco, sovrascrittura ed eliminazione.
|
||||
- Ogni progetto salva file GIS, POI, disegni, traccia e inquadratura; l'inclusione delle particelle catastali rosse e' opzionale.
|
||||
- Ogni progetto salva file GIS, POI, disegni, traccia, inquadratura e tutte le opzioni di visualizzazione: sfondo, layer catastali, trasparenza, misure, foglio importato, barra strumenti e preferenze GPS.
|
||||
- GPS nativo MAUI ad alta precisione con permessi Android/iOS.
|
||||
- Centratura automatica una tantum sulla posizione attuale all'apertura, senza mostrare il punto o il cerchio e senza avviare il tracking GPS continuo.
|
||||
- Centratura automatica una tantum all'apertura: prima tramite posizione approssimativa della connessione Internet, poi tramite singola lettura GPS se la rete non restituisce una posizione; nessun punto o cerchio viene mostrato e il tracking continuo non viene avviato.
|
||||
- Punto e cerchio di precisione del GPS live possono essere mostrati o nascosti dalle impostazioni senza fermare il rilevamento.
|
||||
- Marker posizione, cerchio accuratezza in metri, tracciamento percorso.
|
||||
- Controllo se la posizione GPS cade dentro un poligono importato o disegnato.
|
||||
@@ -30,7 +30,7 @@ App .NET MAUI Blazor Hybrid per Android, iOS, Mac Catalyst e Windows, pensata pe
|
||||
- Ricerca di localita e indirizzi eseguita nativamente con fallback Esri e OpenStreetMap, senza richieste CORS dalla WebView.
|
||||
- Catalogo dei Comuni incluso nell'APK e cataloghi regionali OnData scaricati in cache solo quando servono.
|
||||
- Ricerca catastale eseguita dal codice .NET nativo, senza DuckDB WebAssembly nella WebView Android.
|
||||
- La registrazione della traccia GPS e' disattivata all'avvio; la toolbar di disegno puo' essere mostrata o nascosta dal tab Progetti.
|
||||
- La registrazione della traccia GPS e' disattivata all'avvio; la toolbar di disegno completa puo' essere mostrata o nascosta dal tab Dati.
|
||||
- Pannello `Layer` accessibile direttamente dalla mappa, con checkbox sincronizzati per confini, numeri particella, fogli, fabbricati, strade e acque.
|
||||
- Le particelle cercate possono essere aggiunte una dopo l'altra, mantenendo contemporaneamente sulla mappa tutti i confini selezionati.
|
||||
- Comandi separati per rimuovere le particelle selezionate o pulire importazioni, disegni, POI e traccia GPS.
|
||||
|
||||
@@ -13,7 +13,7 @@ public sealed class AzureMapsService
|
||||
|
||||
public AzureMapsService()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("LMEMappeCatastali/0.2.10");
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("LMEMappeCatastali/0.2.12");
|
||||
_httpClient.DefaultRequestHeaders.Accept.ParseAdd("application/json");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Maui.Networking;
|
||||
|
||||
namespace LMEMappeCatastaliApp.Services;
|
||||
|
||||
public sealed class NetworkLocationService
|
||||
{
|
||||
private readonly HttpClient httpClient = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(6)
|
||||
};
|
||||
|
||||
public NetworkLocationService()
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("LMEMappeCatastali/0.2.12");
|
||||
}
|
||||
|
||||
public async Task<NetworkLocationSnapshot?> GetApproximateLocationAsync(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (Connectivity.Current.NetworkAccess != NetworkAccess.Internet)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var response = await httpClient.GetAsync("https://ipapi.co/json/", cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<IpLocationResponse>(cancellationToken);
|
||||
if (result is null
|
||||
|| result.Error == true
|
||||
|| !result.Latitude.HasValue
|
||||
|| !result.Longitude.HasValue
|
||||
|| Math.Abs(result.Latitude.Value) > 90
|
||||
|| Math.Abs(result.Longitude.Value) > 180)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var labelParts = new[] { result.City, result.Region, result.CountryName }
|
||||
.Where(value => !string.IsNullOrWhiteSpace(value));
|
||||
return new NetworkLocationSnapshot(
|
||||
result.Latitude.Value,
|
||||
result.Longitude.Value,
|
||||
string.Join(", ", labelParts));
|
||||
}
|
||||
|
||||
private sealed class IpLocationResponse
|
||||
{
|
||||
[JsonPropertyName("latitude")]
|
||||
public double? Latitude { get; init; }
|
||||
|
||||
[JsonPropertyName("longitude")]
|
||||
public double? Longitude { get; init; }
|
||||
|
||||
[JsonPropertyName("city")]
|
||||
public string? City { get; init; }
|
||||
|
||||
[JsonPropertyName("region")]
|
||||
public string? Region { get; init; }
|
||||
|
||||
[JsonPropertyName("country_name")]
|
||||
public string? CountryName { get; init; }
|
||||
|
||||
[JsonPropertyName("error")]
|
||||
public bool? Error { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record NetworkLocationSnapshot(double Latitude, double Longitude, string Label);
|
||||
+13
-53
@@ -292,41 +292,18 @@ input[type="checkbox"] {
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.map-measure-tools {
|
||||
position: absolute;
|
||||
top: 72px;
|
||||
right: 12px;
|
||||
z-index: 860;
|
||||
display: grid;
|
||||
grid-template-columns: auto repeat(3, minmax(76px, auto));
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 7px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.7);
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
box-shadow: 0 3px 14px rgba(0, 0, 0, 0.2);
|
||||
transition: top 140ms ease;
|
||||
.leaflet-top.leaflet-right {
|
||||
top: 68px;
|
||||
right: 2px;
|
||||
}
|
||||
|
||||
.map-measure-tools > span {
|
||||
padding: 0 4px;
|
||||
color: var(--muted);
|
||||
font-size: 10px;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
.map-stage.search-active .leaflet-top.leaflet-right {
|
||||
top: 136px;
|
||||
}
|
||||
|
||||
.map-measure-tools button {
|
||||
min-height: 38px;
|
||||
padding: 0 10px;
|
||||
background: #fff3e8;
|
||||
color: #8a3a08;
|
||||
border: 1px solid #e4b58f;
|
||||
}
|
||||
|
||||
.map-measure-tools.search-open {
|
||||
top: 140px;
|
||||
.leaflet-touch .leaflet-draw-toolbar a {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
}
|
||||
|
||||
.tool-sheet {
|
||||
@@ -755,16 +732,6 @@ footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 701px) and (max-width: 900px) {
|
||||
.map-measure-tools {
|
||||
top: 126px;
|
||||
}
|
||||
|
||||
.map-measure-tools.search-open {
|
||||
top: 194px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.map-toolbar {
|
||||
top: 8px;
|
||||
@@ -808,20 +775,13 @@ footer {
|
||||
top: 136px;
|
||||
}
|
||||
|
||||
.map-measure-tools,
|
||||
.map-measure-tools.search-open {
|
||||
top: 126px;
|
||||
right: 8px;
|
||||
left: 8px;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
.leaflet-top.leaflet-right {
|
||||
top: 122px;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.map-measure-tools.search-open {
|
||||
top: 194px;
|
||||
}
|
||||
|
||||
.map-measure-tools > span {
|
||||
display: none;
|
||||
.map-stage.search-active .leaflet-top.leaflet-right {
|
||||
top: 190px;
|
||||
}
|
||||
|
||||
.gps-main,
|
||||
|
||||
+289
-68
@@ -7,6 +7,8 @@ const lmeState = {
|
||||
cadastreLayers: ["CP.CadastralParcel", "codice_plla", "CP.CadastralZoning", "fabbricati"],
|
||||
cadastreOpacity: 0.75,
|
||||
imported: null,
|
||||
importedSheets: null,
|
||||
importedSheetsVisible: false,
|
||||
importedMeasurements: null,
|
||||
drawings: null,
|
||||
drawingMeasurements: null,
|
||||
@@ -52,6 +54,7 @@ window.lmeMap = {
|
||||
fitImported,
|
||||
clearImported,
|
||||
setIncludeKmlSheetLayer,
|
||||
setImportedSheetLayerVisible,
|
||||
setImportedMeasurementsVisible,
|
||||
setDrawingMeasurementsVisible,
|
||||
addProjectMarker,
|
||||
@@ -129,6 +132,7 @@ function init() {
|
||||
|
||||
lmeState.currentBase = lmeState.baseLayers.satellite.addTo(lmeState.map);
|
||||
lmeState.imported = L.featureGroup().addTo(lmeState.map);
|
||||
lmeState.importedSheets = L.featureGroup();
|
||||
lmeState.drawings = L.featureGroup().addTo(lmeState.map);
|
||||
lmeState.importedMeasurements = L.layerGroup().addTo(lmeState.map);
|
||||
lmeState.drawingMeasurements = L.layerGroup().addTo(lmeState.map);
|
||||
@@ -138,6 +142,7 @@ function init() {
|
||||
|
||||
refreshCadastreLayer();
|
||||
bindFileImport();
|
||||
bindDrawingEvents();
|
||||
|
||||
if (!lmeState.resizeBound) {
|
||||
window.addEventListener("resize", resize);
|
||||
@@ -183,21 +188,27 @@ function showSearchResult(latitude, longitude, label) {
|
||||
setInfo(label || `${lat.toFixed(6)}, ${lon.toFixed(6)}`);
|
||||
}
|
||||
|
||||
function showInitialPosition(location) {
|
||||
const latitude = Number(location?.latitude);
|
||||
const longitude = Number(location?.longitude);
|
||||
const accuracy = Math.max(0, Number(location?.accuracy) || 0);
|
||||
function showInitialPosition(latitudeValue, longitudeValue, approximate, label) {
|
||||
const latitude = Number(latitudeValue);
|
||||
const longitude = Number(longitudeValue);
|
||||
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const latlng = [latitude, longitude];
|
||||
lmeState.lastPosition = latlng;
|
||||
lmeState.lastAccuracy = accuracy;
|
||||
lmeState.map.setView(latlng, accuracy > 80 ? 17 : 19);
|
||||
setText("gpsState", "Posizione iniziale acquisita - GPS non attivo");
|
||||
setInfo("Mappa centrata sulla posizione attuale. GPS continuo non attivo.");
|
||||
updateGpsInsideState();
|
||||
if (!approximate) {
|
||||
lmeState.lastPosition = latlng;
|
||||
}
|
||||
lmeState.map.setView(latlng, approximate ? 13 : 19);
|
||||
setText("gpsState", approximate
|
||||
? "Posizione approssimativa dalla connessione - GPS non attivo"
|
||||
: "Posizione iniziale acquisita - GPS non attivo");
|
||||
setInfo(approximate
|
||||
? `Mappa centrata in modo approssimativo su ${label || "questa zona"}.`
|
||||
: "Mappa centrata sulla posizione attuale. GPS continuo non attivo.");
|
||||
if (!approximate) {
|
||||
updateGpsInsideState();
|
||||
}
|
||||
}
|
||||
|
||||
function displayOfficialParcel(xmlText, latitude, longitude, parcel, label, shouldFit) {
|
||||
@@ -457,7 +468,7 @@ function bindFileImport() {
|
||||
try {
|
||||
const result = await readGisFile(file);
|
||||
const geojson = result.geojson;
|
||||
const layer = L.geoJSON(geojson, {
|
||||
const parcelLayer = L.geoJSON(geojson, {
|
||||
style: { color: "#22c55e", weight: 3, opacity: 0.95, fillOpacity: 0.18 },
|
||||
pointToLayer: (feature, latlng) => L.circleMarker(latlng, { radius: 7, color: "#22c55e", fillColor: "#ffffff", fillOpacity: 0.9 }),
|
||||
onEachFeature: (feature, layer) => {
|
||||
@@ -465,14 +476,28 @@ function bindFileImport() {
|
||||
layer.bindPopup(`<strong>${escapeHtml(name)}</strong>`);
|
||||
}
|
||||
}).addTo(lmeState.imported);
|
||||
fitLayer(layer);
|
||||
const sheetGeojson = result.sheetGeojson || emptyFeatureCollection();
|
||||
const sheetLayer = L.geoJSON(sheetGeojson, {
|
||||
style: { color: "#15803d", weight: 3, opacity: 0.85, fillOpacity: 0.04, dashArray: "9 7" },
|
||||
pointToLayer: (feature, latlng) => L.circleMarker(latlng, { radius: 6, color: "#15803d", fillOpacity: 0.25 }),
|
||||
onEachFeature: (feature, layer) => {
|
||||
const name = feature?.properties?.name || "Foglio catastale importato";
|
||||
layer.bindPopup(`<strong>${escapeHtml(name)}</strong>`);
|
||||
}
|
||||
}).addTo(lmeState.importedSheets);
|
||||
applyImportedSheetVisibility();
|
||||
fitLayer(geojson.features.length ? parcelLayer : sheetLayer);
|
||||
refreshImportedMeasurements();
|
||||
const featureCount = geojson.features.length;
|
||||
const sheetCount = sheetGeojson.features.length;
|
||||
const ignored = result.ignoredCount
|
||||
? `; esclusi ${result.ignoredCount} elementi del foglio o non particella`
|
||||
: "";
|
||||
const includedSheets = sheetCount
|
||||
? `; ${sheetCount} elementi foglio ${lmeState.importedSheetsVisible ? "visibili" : "nascosti"}`
|
||||
: "";
|
||||
const reprojected = result.reprojected ? "; coordinate Web Mercator convertite" : "";
|
||||
setInfo(`Caricato ${file.name}: ${featureCount} elementi${ignored}${reprojected}.`);
|
||||
setInfo(`Caricato ${file.name}: ${featureCount} particelle/elementi${includedSheets}${ignored}${reprojected}.`);
|
||||
updateGpsInsideState();
|
||||
} catch (error) {
|
||||
setInfo(`File non leggibile: ${error.message}`);
|
||||
@@ -597,7 +622,12 @@ function normalizeGeoJson(value, fileName) {
|
||||
}
|
||||
|
||||
delete root.crs;
|
||||
return { geojson: root, ignoredCount: 0, reprojected: webMercator };
|
||||
return {
|
||||
geojson: root,
|
||||
sheetGeojson: emptyFeatureCollection(),
|
||||
ignoredCount: 0,
|
||||
reprojected: webMercator
|
||||
};
|
||||
}
|
||||
|
||||
function isGeoJsonGeometry(value) {
|
||||
@@ -675,13 +705,21 @@ function normalizeKmlFiles(files) {
|
||||
}
|
||||
|
||||
const polygonParts = splitKmlPolygonFeatures(features);
|
||||
const selected = lmeState.includeKmlSheetLayer ? features : filterKmlParcelFeatures(polygonParts);
|
||||
if (!selected.length) {
|
||||
throw new Error("nessuna particella trovata; attiva 'includi layer del foglio' per importare tutti gli elementi");
|
||||
const parcels = filterKmlParcelFeatures(polygonParts);
|
||||
const parcelSet = new Set(parcels);
|
||||
const sheetParts = polygonParts.filter(feature => !parcelSet.has(feature));
|
||||
const nonPolygonFeatures = features.filter(feature => geometryPolygons(feature.geometry).length === 0);
|
||||
const optionalFeatures = [...sheetParts, ...nonPolygonFeatures];
|
||||
if (!parcels.length && !(lmeState.includeKmlSheetLayer && optionalFeatures.length)) {
|
||||
throw new Error("nessuna particella trovata; attiva 'includi layer del foglio' per importare gli altri elementi");
|
||||
}
|
||||
return {
|
||||
geojson: { type: "FeatureCollection", features: selected },
|
||||
ignoredCount: lmeState.includeKmlSheetLayer ? 0 : Math.max(0, polygonParts.length - selected.length),
|
||||
geojson: { type: "FeatureCollection", features: parcels },
|
||||
sheetGeojson: {
|
||||
type: "FeatureCollection",
|
||||
features: lmeState.includeKmlSheetLayer ? optionalFeatures : []
|
||||
},
|
||||
ignoredCount: lmeState.includeKmlSheetLayer ? 0 : optionalFeatures.length,
|
||||
reprojected: false
|
||||
};
|
||||
}
|
||||
@@ -724,10 +762,10 @@ function filterKmlParcelFeatures(features) {
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
const folder = String(properties._lmeFolder || "").toLowerCase();
|
||||
const isParcel = /particell|mappal|parcel/.test(`${identity} ${folder}`)
|
||||
|| /^[a-z]?\s*\d+[a-z]?(?:[\/. -]\d+[a-z]?)?$/i.test(name);
|
||||
const isSheet = /\bfoglio\b|\bsheet\b|quadro[ _-]?d[' ]?unione|(?:perimetro|bordo|limite|contorno)[ _-]?(?:del[ _-]?)?foglio|sheet[ _-]?boundary/.test(identity);
|
||||
return isParcel || !isSheet;
|
||||
const context = `${identity} ${folder}`;
|
||||
const hasParcelNumber = /^[a-z]?\s*\d+[a-z]?(?:[\/. -]\d+[a-z]?)?$/i.test(name);
|
||||
const isSheet = /\bfoglio\b|\bsheet\b|quadro[ _-]?d[' ]?unione|(?:perimetro|bordo|limite|contorno)[ _-]?(?:del[ _-]?)?foglio|sheet[ _-]?boundary/.test(context);
|
||||
return !isSheet || hasParcelNumber;
|
||||
});
|
||||
return removeLikelySheetOutlines(filtered);
|
||||
}
|
||||
@@ -837,6 +875,32 @@ function setIncludeKmlSheetLayer(enabled) {
|
||||
: "Importazione KML/KMZ: verranno caricate solo le particelle riconosciute.");
|
||||
}
|
||||
|
||||
function setImportedSheetLayerVisible(enabled) {
|
||||
lmeState.importedSheetsVisible = Boolean(enabled);
|
||||
applyImportedSheetVisibility();
|
||||
const count = lmeState.importedSheets?.toGeoJSON()?.features?.length || 0;
|
||||
setInfo(lmeState.importedSheetsVisible
|
||||
? (count ? `Layer del foglio importato visibile (${count} elementi).` : "Il layer del foglio sara visibile quando verra importato.")
|
||||
: "Layer del foglio importato nascosto; le particelle restano visibili.");
|
||||
}
|
||||
|
||||
function applyImportedSheetVisibility() {
|
||||
if (!lmeState.map || !lmeState.importedSheets) {
|
||||
return;
|
||||
}
|
||||
if (lmeState.importedSheetsVisible) {
|
||||
if (!lmeState.map.hasLayer(lmeState.importedSheets)) {
|
||||
lmeState.importedSheets.addTo(lmeState.map);
|
||||
}
|
||||
lmeState.importedSheets.bringToBack();
|
||||
lmeState.imported.bringToFront();
|
||||
return;
|
||||
}
|
||||
if (lmeState.map.hasLayer(lmeState.importedSheets)) {
|
||||
lmeState.map.removeLayer(lmeState.importedSheets);
|
||||
}
|
||||
}
|
||||
|
||||
function setImportedMeasurementsVisible(enabled) {
|
||||
lmeState.showImportedMeasurements = Boolean(enabled);
|
||||
refreshImportedMeasurements();
|
||||
@@ -854,11 +918,18 @@ function setDrawingMeasurementsVisible(enabled) {
|
||||
}
|
||||
|
||||
function fitImported() {
|
||||
fitLayer(lmeState.imported);
|
||||
const layers = [lmeState.imported];
|
||||
if (lmeState.importedSheetsVisible) {
|
||||
layers.push(lmeState.importedSheets);
|
||||
}
|
||||
fitLayer(L.featureGroup(layers));
|
||||
}
|
||||
|
||||
function clearImported() {
|
||||
lmeState.imported.clearLayers();
|
||||
lmeState.importedSheets.clearLayers();
|
||||
lmeState.importedSheetsVisible = false;
|
||||
applyImportedSheetVisibility();
|
||||
lmeState.importedMeasurements.clearLayers();
|
||||
setInfo("File GIS rimossi.");
|
||||
updateGpsInsideState();
|
||||
@@ -877,65 +948,97 @@ function addProjectMarker(name) {
|
||||
setInfo(`POI aggiunto: ${label}`);
|
||||
}
|
||||
|
||||
function configureDrawLabels() {
|
||||
L.drawLocal.draw.toolbar.buttons.polygon = "Misura area";
|
||||
L.drawLocal.draw.toolbar.buttons.polyline = "Misura distanza";
|
||||
L.drawLocal.draw.toolbar.buttons.circle = "Misura cerchio";
|
||||
L.drawLocal.draw.toolbar.buttons.rectangle = "Disegna rettangolo";
|
||||
L.drawLocal.draw.toolbar.buttons.marker = "Aggiungi POI";
|
||||
L.drawLocal.edit.toolbar.buttons.edit = "Modifica disegni";
|
||||
L.drawLocal.edit.toolbar.buttons.remove = "Elimina disegni";
|
||||
L.drawLocal.draw.handlers.polygon.tooltip.start = "Tocca il primo vertice dell'area.";
|
||||
L.drawLocal.draw.handlers.polygon.tooltip.cont = "Tocca per aggiungere un vertice.";
|
||||
L.drawLocal.draw.handlers.polygon.tooltip.end = "Tocca il primo punto per chiudere l'area.";
|
||||
L.drawLocal.draw.handlers.polyline.tooltip.start = "Tocca il primo punto della distanza.";
|
||||
L.drawLocal.draw.handlers.polyline.tooltip.cont = "Tocca per aggiungere un tratto.";
|
||||
L.drawLocal.draw.handlers.polyline.tooltip.end = "Tocca l'ultimo punto per terminare.";
|
||||
L.drawLocal.draw.handlers.circle.tooltip.start = "Tocca il centro e trascina per il raggio.";
|
||||
}
|
||||
|
||||
function bindDrawingEvents() {
|
||||
if (!lmeState.map || lmeState.drawEventsBound) {
|
||||
return;
|
||||
}
|
||||
lmeState.map.on(L.Draw.Event.CREATED, event => {
|
||||
annotateDrawingLayer(event.layer, event.layerType);
|
||||
lmeState.drawings.addLayer(event.layer);
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
const completedLabels = {
|
||||
polygon: "Area completata: superficie, perimetro e lati aggiornati.",
|
||||
rectangle: "Rettangolo completato: superficie, perimetro e lati aggiornati.",
|
||||
polyline: "Distanza completata: lunghezza totale e tratti aggiornati.",
|
||||
circle: "Cerchio completato: superficie, raggio e circonferenza aggiornati.",
|
||||
marker: "Punto aggiunto alla mappa."
|
||||
};
|
||||
setInfo(completedLabels[event.layerType] || "Disegno completato.");
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.EDITED, event => {
|
||||
event.layers.eachLayer(layer => annotateDrawingLayer(layer));
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.DELETED, () => {
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.DRAWSTOP, () => {
|
||||
lmeState.activeDrawHandler = null;
|
||||
});
|
||||
lmeState.drawEventsBound = true;
|
||||
}
|
||||
|
||||
function enableDrawTools() {
|
||||
if (lmeState.drawControl) {
|
||||
setInfo("Strumenti di disegno gia attivi.");
|
||||
return;
|
||||
}
|
||||
|
||||
configureDrawLabels();
|
||||
const orangeArea = { color: "#f97316", weight: 4, fillColor: "#fb923c", fillOpacity: 0.2 };
|
||||
lmeState.drawControl = new L.Control.Draw({
|
||||
position: "topright",
|
||||
edit: { featureGroup: lmeState.drawings },
|
||||
draw: {
|
||||
circle: { metric: true, feet: false },
|
||||
circle: { metric: true, feet: false, showRadius: true, shapeOptions: orangeArea },
|
||||
circlemarker: false,
|
||||
marker: true,
|
||||
polygon: { metric: true, feet: false, showArea: true, allowIntersection: false },
|
||||
polyline: { metric: true, feet: false, showLength: true },
|
||||
rectangle: true
|
||||
polygon: {
|
||||
metric: true,
|
||||
feet: false,
|
||||
showArea: true,
|
||||
allowIntersection: false,
|
||||
shapeOptions: orangeArea
|
||||
},
|
||||
polyline: {
|
||||
metric: true,
|
||||
feet: false,
|
||||
showLength: true,
|
||||
shapeOptions: { color: "#f97316", weight: 4, opacity: 0.95 }
|
||||
},
|
||||
rectangle: { metric: true, shapeOptions: orangeArea }
|
||||
}
|
||||
});
|
||||
lmeState.map.addControl(lmeState.drawControl);
|
||||
if (!lmeState.drawEventsBound) {
|
||||
lmeState.map.on(L.Draw.Event.CREATED, event => {
|
||||
annotateDrawingLayer(event.layer, event.layerType);
|
||||
lmeState.drawings.addLayer(event.layer);
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
const completedLabels = {
|
||||
polygon: "Area completata: superficie, perimetro e lati aggiornati.",
|
||||
rectangle: "Rettangolo completato: superficie, perimetro e lati aggiornati.",
|
||||
polyline: "Distanza completata: lunghezza totale e tratti aggiornati.",
|
||||
circle: "Cerchio completato: superficie, raggio e circonferenza aggiornati.",
|
||||
marker: "Punto aggiunto alla mappa."
|
||||
};
|
||||
setInfo(completedLabels[event.layerType] || "Disegno completato.");
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.EDITED, event => {
|
||||
event.layers.eachLayer(layer => annotateDrawingLayer(layer));
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.DELETED, () => {
|
||||
refreshDrawingMeasurements();
|
||||
updateGpsInsideState();
|
||||
});
|
||||
lmeState.map.on(L.Draw.Event.DRAWSTOP, () => {
|
||||
lmeState.activeDrawHandler = null;
|
||||
});
|
||||
lmeState.drawEventsBound = true;
|
||||
}
|
||||
setInfo("Disegno attivo: crea POI, linee e aree sulla mappa.");
|
||||
bindDrawingEvents();
|
||||
setInfo("Barra strumenti attiva: misure, disegni, POI, modifica e cancellazione.");
|
||||
}
|
||||
|
||||
function startMeasurementDrawing(mode) {
|
||||
if (!lmeState.map) {
|
||||
return;
|
||||
}
|
||||
if (!lmeState.drawEventsBound) {
|
||||
enableDrawTools();
|
||||
setDrawToolsVisible(false);
|
||||
}
|
||||
bindDrawingEvents();
|
||||
if (lmeState.activeDrawHandler) {
|
||||
lmeState.activeDrawHandler.disable();
|
||||
}
|
||||
@@ -1255,7 +1358,7 @@ function formatNumber(value, digits) {
|
||||
function createProjectSnapshot(includeCadastralParcels) {
|
||||
const center = lmeState.map.getCenter();
|
||||
return JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
schemaVersion: 3,
|
||||
view: {
|
||||
latitude: center.lat,
|
||||
longitude: center.lng,
|
||||
@@ -1263,6 +1366,9 @@ function createProjectSnapshot(includeCadastralParcels) {
|
||||
},
|
||||
drawings: lmeState.drawings.toGeoJSON(),
|
||||
imported: lmeState.imported.toGeoJSON(),
|
||||
importedSheets: lmeState.importedSheets.toGeoJSON(),
|
||||
importedSheetsVisible: lmeState.importedSheetsVisible,
|
||||
displayOptions: captureDisplayOptions(),
|
||||
selectedParcels: includeCadastralParcels
|
||||
? lmeState.selectedParcelsLayer.toGeoJSON()
|
||||
: { type: "FeatureCollection", features: [] },
|
||||
@@ -1290,6 +1396,7 @@ function loadProjectSnapshot(raw, projectName) {
|
||||
|
||||
lmeState.drawings.clearLayers();
|
||||
lmeState.imported.clearLayers();
|
||||
lmeState.importedSheets.clearLayers();
|
||||
lmeState.drawingMeasurements.clearLayers();
|
||||
lmeState.importedMeasurements.clearLayers();
|
||||
lmeState.selectedParcelsLayer.clearLayers();
|
||||
@@ -1313,7 +1420,10 @@ function loadProjectSnapshot(raw, projectName) {
|
||||
onEachFeature: bindStoredFeaturePopup
|
||||
});
|
||||
restoredDrawings.eachLayer(layer => lmeState.drawings.addLayer(layer));
|
||||
L.geoJSON(data.imported || emptyFeatureCollection(), {
|
||||
const importedParts = partitionStoredImportedFeatures(
|
||||
data.imported || emptyFeatureCollection(),
|
||||
data.importedSheets || emptyFeatureCollection());
|
||||
L.geoJSON(importedParts.parcels, {
|
||||
style: { color: "#22c55e", weight: 3, opacity: 0.95, fillOpacity: 0.18 },
|
||||
pointToLayer: (feature, latlng) => L.circleMarker(latlng, {
|
||||
radius: 7,
|
||||
@@ -1323,6 +1433,22 @@ function loadProjectSnapshot(raw, projectName) {
|
||||
}),
|
||||
onEachFeature: bindStoredFeaturePopup
|
||||
}).addTo(lmeState.imported);
|
||||
L.geoJSON(importedParts.sheets, {
|
||||
style: { color: "#15803d", weight: 3, opacity: 0.85, fillOpacity: 0.04, dashArray: "9 7" },
|
||||
pointToLayer: (feature, latlng) => L.circleMarker(latlng, {
|
||||
radius: 6,
|
||||
color: "#15803d",
|
||||
fillOpacity: 0.25
|
||||
}),
|
||||
onEachFeature: bindStoredFeaturePopup
|
||||
}).addTo(lmeState.importedSheets);
|
||||
const projectDisplayOptions = data.schemaVersion >= 3 && data.displayOptions
|
||||
? data.displayOptions
|
||||
: null;
|
||||
lmeState.importedSheetsVisible = projectDisplayOptions
|
||||
? Boolean(projectDisplayOptions.importedSheetsVisible)
|
||||
: data.schemaVersion >= 2 && Boolean(data.importedSheetsVisible);
|
||||
applyImportedSheetVisibility();
|
||||
L.geoJSON(data.selectedParcels || emptyFeatureCollection(), {
|
||||
style: { color: "#ef4444", weight: 4, opacity: 1, fillColor: "#fbbf24", fillOpacity: 0.26 },
|
||||
onEachFeature: (feature, layer) => {
|
||||
@@ -1338,15 +1464,22 @@ function loadProjectSnapshot(raw, projectName) {
|
||||
|
||||
lmeState.gpsTrailPoints = Array.isArray(data.trail) ? data.trail : [];
|
||||
lmeState.gpsTrail.setLatLngs(lmeState.gpsTrailPoints);
|
||||
if (projectDisplayOptions) {
|
||||
applyProjectDisplayOptions(projectDisplayOptions);
|
||||
}
|
||||
refreshImportedMeasurements();
|
||||
refreshDrawingMeasurements();
|
||||
|
||||
const projectLayers = L.featureGroup([
|
||||
const projectLayerList = [
|
||||
lmeState.drawings,
|
||||
lmeState.imported,
|
||||
lmeState.selectedParcelsLayer,
|
||||
lmeState.gpsTrail
|
||||
]);
|
||||
];
|
||||
if (lmeState.importedSheetsVisible) {
|
||||
projectLayerList.push(lmeState.importedSheets);
|
||||
}
|
||||
const projectLayers = L.featureGroup(projectLayerList);
|
||||
if (projectLayers.getBounds().isValid()) {
|
||||
fitLayer(projectLayers);
|
||||
} else if (Number.isFinite(data.view?.latitude)
|
||||
@@ -1360,13 +1493,95 @@ function loadProjectSnapshot(raw, projectName) {
|
||||
? `${parcelCount} particelle del progetto`
|
||||
: "Nessuna particella selezionata");
|
||||
updateGpsInsideState();
|
||||
setInfo(`Progetto caricato: ${projectName || "senza nome"}.`);
|
||||
const hiddenSheets = importedParts.sheets.features.length && !lmeState.importedSheetsVisible
|
||||
? ` ${importedParts.sheets.features.length} elementi del foglio sono nascosti.`
|
||||
: "";
|
||||
setInfo(`Progetto caricato: ${projectName || "senza nome"}.${hiddenSheets}`);
|
||||
return captureDisplayOptions();
|
||||
} catch (error) {
|
||||
setInfo(`Progetto non leggibile: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function captureDisplayOptions() {
|
||||
return {
|
||||
baseLayer: lmeState.currentBaseName,
|
||||
cadastreOpacity: lmeState.cadastreOpacity,
|
||||
cadastreLayers: [...lmeState.cadastreLayers],
|
||||
includeKmlSheetLayer: lmeState.includeKmlSheetLayer,
|
||||
importedSheetsVisible: lmeState.importedSheetsVisible,
|
||||
showImportedMeasurements: lmeState.showImportedMeasurements,
|
||||
showDrawingMeasurements: lmeState.showDrawingMeasurements,
|
||||
drawToolsVisible: Boolean(lmeState.drawControl),
|
||||
gpsPositionVisible: lmeState.gpsPositionVisible,
|
||||
trailEnabled: lmeState.gpsTrailEnabled
|
||||
};
|
||||
}
|
||||
|
||||
function applyProjectDisplayOptions(options) {
|
||||
const supportedCadastreLayers = new Set([
|
||||
"CP.CadastralParcel",
|
||||
"codice_plla",
|
||||
"CP.CadastralZoning",
|
||||
"fabbricati",
|
||||
"strade",
|
||||
"acque"
|
||||
]);
|
||||
if (Array.isArray(options.cadastreLayers)) {
|
||||
lmeState.cadastreLayers = options.cadastreLayers.filter(layer => supportedCadastreLayers.has(layer));
|
||||
}
|
||||
|
||||
const opacity = Number(options.cadastreOpacity);
|
||||
if (Number.isFinite(opacity)) {
|
||||
lmeState.cadastreOpacity = Math.max(0, Math.min(1, opacity));
|
||||
}
|
||||
lmeState.includeKmlSheetLayer = Boolean(options.includeKmlSheetLayer);
|
||||
lmeState.importedSheetsVisible = Boolean(options.importedSheetsVisible);
|
||||
lmeState.showImportedMeasurements = Boolean(options.showImportedMeasurements);
|
||||
lmeState.showDrawingMeasurements = options.showDrawingMeasurements !== false;
|
||||
applyImportedSheetVisibility();
|
||||
refreshCadastreLayer();
|
||||
|
||||
if (typeof options.baseLayer === "string") {
|
||||
setBaseLayer(options.baseLayer);
|
||||
}
|
||||
setGpsPositionVisible(options.gpsPositionVisible !== false);
|
||||
toggleTrail(Boolean(options.trailEnabled));
|
||||
setDrawToolsVisible(Boolean(options.drawToolsVisible));
|
||||
}
|
||||
|
||||
function partitionStoredImportedFeatures(imported, storedSheets) {
|
||||
const parcelFeatures = [];
|
||||
const sheetFeatures = [...(storedSheets?.features || [])];
|
||||
const sourceGroups = new Map();
|
||||
|
||||
(imported?.features || []).forEach(feature => {
|
||||
const source = String(feature?.properties?._lmeSource || "");
|
||||
if (!/\.(kml|kmz)$/i.test(source)) {
|
||||
parcelFeatures.push(feature);
|
||||
return;
|
||||
}
|
||||
const group = sourceGroups.get(source) || [];
|
||||
group.push(feature);
|
||||
sourceGroups.set(source, group);
|
||||
});
|
||||
|
||||
sourceGroups.forEach(features => {
|
||||
const polygonParts = splitKmlPolygonFeatures(features);
|
||||
const parcels = filterKmlParcelFeatures(polygonParts);
|
||||
const parcelSet = new Set(parcels);
|
||||
parcelFeatures.push(...parcels);
|
||||
sheetFeatures.push(...polygonParts.filter(feature => !parcelSet.has(feature)));
|
||||
sheetFeatures.push(...features.filter(feature => geometryPolygons(feature.geometry).length === 0));
|
||||
});
|
||||
|
||||
return {
|
||||
parcels: { type: "FeatureCollection", features: parcelFeatures },
|
||||
sheets: { type: "FeatureCollection", features: sheetFeatures }
|
||||
};
|
||||
}
|
||||
|
||||
function emptyFeatureCollection() {
|
||||
return { type: "FeatureCollection", features: [] };
|
||||
}
|
||||
@@ -1570,7 +1785,11 @@ function htmlToText(value) {
|
||||
}
|
||||
|
||||
function setCadastreOpacity(value) {
|
||||
lmeState.cadastreOpacity = Number(value || 0.75);
|
||||
const opacity = Number(value);
|
||||
if (!Number.isFinite(opacity)) {
|
||||
return;
|
||||
}
|
||||
lmeState.cadastreOpacity = Math.max(0, Math.min(1, opacity));
|
||||
if (lmeState.cadastre) {
|
||||
lmeState.cadastre.setOpacity(lmeState.cadastreOpacity);
|
||||
}
|
||||
@@ -1661,6 +1880,7 @@ function clearMapElements() {
|
||||
const count = lmeState.selectedParcelsLayer.getLayers().length
|
||||
+ lmeState.gpsParcelLayer.getLayers().length
|
||||
+ lmeState.imported.getLayers().length
|
||||
+ lmeState.importedSheets.getLayers().length
|
||||
+ lmeState.drawings.getLayers().length
|
||||
+ lmeState.gpsTrailPoints.length;
|
||||
if (!count) {
|
||||
@@ -1674,6 +1894,7 @@ function clearMapElements() {
|
||||
lmeState.selectedParcelsLayer.clearLayers();
|
||||
lmeState.gpsParcelLayer.clearLayers();
|
||||
lmeState.imported.clearLayers();
|
||||
lmeState.importedSheets.clearLayers();
|
||||
lmeState.drawings.clearLayers();
|
||||
lmeState.importedMeasurements.clearLayers();
|
||||
lmeState.drawingMeasurements.clearLayers();
|
||||
|
||||
Reference in new issue
Block a user