Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0adc27cf5 | ||
|
|
3dfeef54ea |
No files matched your search
+101
-2
@@ -10,6 +10,7 @@
|
||||
@inject MapExportService MapExportService
|
||||
@inject CloudSyncService CloudSyncService
|
||||
@inject AppUpdateService AppUpdateService
|
||||
@inject IncomingFileService IncomingFiles
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<PageTitle>LME Mappe Catastali</PageTitle>
|
||||
@@ -697,6 +698,7 @@
|
||||
private bool SyncBusy { get; set; }
|
||||
private string SyncStatus { get; set; } = "Sincronizzazione non configurata.";
|
||||
private bool UpdateBusy { get; set; }
|
||||
private bool MapReady { get; set; }
|
||||
private string UpdateStatus { get; set; } = $"Versione installata: {AppUpdateService.CurrentVersion}";
|
||||
private string UpdateDownloadUrl { get; set; } = string.Empty;
|
||||
private string UpdateReleaseNotes { get; set; } = string.Empty;
|
||||
@@ -754,6 +756,7 @@
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
IncomingFiles.FileAvailable += OnIncomingFileAvailable;
|
||||
LoadFlagPreferences();
|
||||
|
||||
try
|
||||
@@ -797,12 +800,14 @@
|
||||
{
|
||||
MapCallbackReference = DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("lmeMap.init", MapCallbackReference);
|
||||
MapReady = true;
|
||||
await ApplyFlagPreferencesToMapAsync();
|
||||
await ApplyAdvancedOptions();
|
||||
await CenterOnInitialLocationAsync();
|
||||
await MigrateLegacyProjectAsync();
|
||||
var offlineCount = await JS.InvokeAsync<int>("lmeMap.getOfflineTileStats");
|
||||
OfflineStatus = offlineCount == 0 ? "Nessuna tessera salvata." : $"{offlineCount} tessere disponibili offline.";
|
||||
await ProcessIncomingFilesAsync();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1492,7 +1497,11 @@
|
||||
|
||||
private async Task RestoreBackup()
|
||||
{
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions { PickerTitle = "Scegli backup LME" });
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions
|
||||
{
|
||||
PickerTitle = "Scegli backup LME (.lmebackup.zip)",
|
||||
FileTypes = BackupPickerFileTypes
|
||||
});
|
||||
if (file is null) return;
|
||||
var path = await CopyPickedFileToCacheAsync(file);
|
||||
var count = await ProjectStorageService.RestoreBackupAsync(path);
|
||||
@@ -1502,7 +1511,11 @@
|
||||
|
||||
private async Task ImportProject()
|
||||
{
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions { PickerTitle = "Scegli progetto LME" });
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions
|
||||
{
|
||||
PickerTitle = "Scegli progetto LME (.lmeproject.json)",
|
||||
FileTypes = ProjectPickerFileTypes
|
||||
});
|
||||
if (file is null) return;
|
||||
var path = await CopyPickedFileToCacheAsync(file);
|
||||
var imported = await ProjectStorageService.ImportProjectAsync(path);
|
||||
@@ -1521,6 +1534,91 @@
|
||||
return path;
|
||||
}
|
||||
|
||||
private void OnIncomingFileAvailable()
|
||||
{
|
||||
if (MapReady) _ = InvokeAsync(ProcessIncomingFilesAsync);
|
||||
}
|
||||
|
||||
private async Task ProcessIncomingFilesAsync()
|
||||
{
|
||||
while (IncomingFiles.TryDequeue(out var incoming) && incoming is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerName = incoming.FileName.ToLowerInvariant();
|
||||
if (lowerName.EndsWith(".kml", StringComparison.Ordinal)
|
||||
|| lowerName.EndsWith(".kmz", StringComparison.Ordinal)
|
||||
|| lowerName.EndsWith(".geojson", StringComparison.Ordinal)
|
||||
|| await IsGeoJsonAsync(incoming.Path))
|
||||
{
|
||||
var content = Convert.ToBase64String(await File.ReadAllBytesAsync(incoming.Path));
|
||||
await JS.InvokeAsync<string>("lmeMap.importExternalGisFile", incoming.FileName, content, incoming.ContentType);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lowerName.EndsWith(".zip", StringComparison.Ordinal))
|
||||
{
|
||||
var count = await ProjectStorageService.RestoreBackupAsync(incoming.Path);
|
||||
await RefreshProjectsAsync();
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Backup aperto: {count} progetti ripristinati.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lowerName.EndsWith(".json", StringComparison.Ordinal))
|
||||
{
|
||||
var imported = await ProjectStorageService.ImportProjectAsync(incoming.Path);
|
||||
await RefreshProjectsAsync();
|
||||
SelectedProjectId = imported.Id;
|
||||
await RefreshProjectVersionsAsync(true);
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Progetto aperto: {imported.Name}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Formato non riconosciuto: {incoming.FileName}.");
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Impossibile aprire {incoming.FileName}: {error.GetBaseException().Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { File.Delete(incoming.Path); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> IsGeoJsonAsync(string path)
|
||||
{
|
||||
if (!Path.GetExtension(path).Equals(".json", StringComparison.OrdinalIgnoreCase)) return false;
|
||||
try
|
||||
{
|
||||
await using var stream = File.OpenRead(path);
|
||||
using var document = await System.Text.Json.JsonDocument.ParseAsync(stream);
|
||||
if (!document.RootElement.TryGetProperty("type", out var typeProperty)) return false;
|
||||
var type = typeProperty.GetString();
|
||||
return type is "Feature" or "FeatureCollection" or "Point" or "MultiPoint"
|
||||
or "LineString" or "MultiLineString" or "Polygon" or "MultiPolygon"
|
||||
or "GeometryCollection";
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
private static readonly FilePickerFileType ProjectPickerFileTypes = new(new Dictionary<DevicePlatform, IEnumerable<string>>
|
||||
{
|
||||
[DevicePlatform.Android] = ["application/json", "text/json", "text/plain", "application/octet-stream"],
|
||||
[DevicePlatform.WinUI] = [".json"],
|
||||
[DevicePlatform.iOS] = ["public.json", "public.data"],
|
||||
[DevicePlatform.macOS] = ["public.json", "public.data"]
|
||||
});
|
||||
|
||||
private static readonly FilePickerFileType BackupPickerFileTypes = new(new Dictionary<DevicePlatform, IEnumerable<string>>
|
||||
{
|
||||
[DevicePlatform.Android] = ["application/zip", "application/x-zip-compressed", "application/octet-stream"],
|
||||
[DevicePlatform.WinUI] = [".zip"],
|
||||
[DevicePlatform.iOS] = ["public.zip-archive", "public.data"],
|
||||
[DevicePlatform.macOS] = ["public.zip-archive", "public.data"]
|
||||
});
|
||||
|
||||
private async Task LoadProjectVersion()
|
||||
{
|
||||
if (SelectedProject is null || string.IsNullOrWhiteSpace(SelectedVersionId)) return;
|
||||
@@ -2121,6 +2219,7 @@
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
IncomingFiles.FileAvailable -= OnIncomingFileAvailable;
|
||||
CancelCatalogWork();
|
||||
LocationService.StopTracking();
|
||||
GpsLookupCancellation?.Cancel();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
|
||||
<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</TargetFrameworks>
|
||||
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
|
||||
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
<ApplicationId>com.companyname.lmemappecatastaliapp</ApplicationId>
|
||||
|
||||
<!-- Versions -->
|
||||
<ApplicationDisplayVersion>0.4.7</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>42</ApplicationVersion>
|
||||
<ApplicationDisplayVersion>0.4.8</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>43</ApplicationVersion>
|
||||
<Version>$(ApplicationDisplayVersion)</Version>
|
||||
|
||||
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
|
||||
@@ -43,6 +43,14 @@
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
|
||||
<AndroidTargetSdkVersion>36</AndroidTargetSdkVersion>
|
||||
<AndroidPackageFormat>aab</AndroidPackageFormat>
|
||||
<AndroidUseAapt2>true</AndroidUseAapt2>
|
||||
<AndroidCreatePackagePerAbi>false</AndroidCreatePackagePerAbi>
|
||||
<RunAOTCompilation>true</RunAOTCompilation>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- App Icon -->
|
||||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#075E54" />
|
||||
@@ -64,7 +72,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.12" />
|
||||
<PackageReference Include="Parquet.Net" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ public static class MauiProgram
|
||||
builder.Services.AddSingleton<MapExportService>();
|
||||
builder.Services.AddSingleton<CloudSyncService>();
|
||||
builder.Services.AddSingleton<AppUpdateService>();
|
||||
builder.Services.AddSingleton(IncomingFileService.Shared);
|
||||
|
||||
#if DEBUG
|
||||
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||
|
||||
@@ -1,10 +1,75 @@
|
||||
using Android.App;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Database;
|
||||
using Android.OS;
|
||||
using Android.Provider;
|
||||
using LMEMappeCatastaliApp.Services;
|
||||
|
||||
namespace LMEMappeCatastaliApp;
|
||||
|
||||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
||||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/json")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/geo+json")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/geojson")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/vnd.google-earth.kml+xml")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/vnd.google-earth.kmz")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/xml")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "text/xml")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/zip")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/x-zip-compressed")]
|
||||
[IntentFilter([Intent.ActionView], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "application/octet-stream")]
|
||||
public class MainActivity : MauiAppCompatActivity
|
||||
{
|
||||
protected override void OnCreate(Bundle? savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
QueueViewedFile(Intent);
|
||||
}
|
||||
|
||||
protected override void OnNewIntent(Intent? intent)
|
||||
{
|
||||
base.OnNewIntent(intent);
|
||||
Intent = intent;
|
||||
QueueViewedFile(intent);
|
||||
}
|
||||
|
||||
private void QueueViewedFile(Intent? intent)
|
||||
{
|
||||
if (intent?.Action == Android.Content.Intent.ActionView && intent.Data is not null)
|
||||
{
|
||||
_ = CopyViewedFileAsync(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CopyViewedFileAsync(Intent intent)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = intent.Data!;
|
||||
var fileName = ReadDisplayName(uri) ?? $"file-{Guid.NewGuid():N}";
|
||||
fileName = string.Concat(fileName.Select(character => Path.GetInvalidFileNameChars().Contains(character) ? '_' : character));
|
||||
var directory = Path.Combine(FileSystem.CacheDirectory, "Incoming");
|
||||
Directory.CreateDirectory(directory);
|
||||
var path = Path.Combine(directory, $"{Guid.NewGuid():N}-{fileName}");
|
||||
await using var input = ContentResolver!.OpenInputStream(uri)
|
||||
?? throw new IOException("Impossibile leggere il file selezionato.");
|
||||
await using var output = File.Create(path);
|
||||
await input.CopyToAsync(output);
|
||||
IncomingFileService.Shared.Enqueue(new IncomingFile(path, fileName, intent.Type));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Apertura file LME non riuscita: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
private string? ReadDisplayName(Android.Net.Uri uri)
|
||||
{
|
||||
if (uri.Scheme == ContentResolver.SchemeFile) return Path.GetFileName(uri.Path);
|
||||
using ICursor? cursor = ContentResolver?.Query(uri, [IOpenableColumns.DisplayName], null, null, null);
|
||||
if (cursor is null || !cursor.MoveToFirst()) return null;
|
||||
var index = cursor.GetColumnIndex(IOpenableColumns.DisplayName);
|
||||
return index >= 0 ? cursor.GetString(index) : null;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
App .NET MAUI Blazor Hybrid per Android, iOS, Mac Catalyst e Windows, pensata per consultare mappe catastali e lavorare sul campo con GPS.
|
||||
|
||||
## Versione 0.4.8
|
||||
|
||||
- Aggiornamento a .NET 10 e target Android API 36.
|
||||
- KML e KMZ generici conservano punti, linee e poligoni; il filtro particelle viene applicato soltanto ai file riconosciuti come catastali.
|
||||
- Android propone LME tra le app disponibili per aprire KML, KMZ, GeoJSON, progetti JSON e backup ZIP.
|
||||
- I selettori file Android mostrano correttamente progetti condivisi e backup con estensione composta.
|
||||
|
||||
## Versione 0.4.7
|
||||
|
||||
- La ricerca nel pannello Layer conserva correttamente posizione e selezione del cursore durante il filtraggio; digitando `pio` il testo non viene piu invertito in `oip`.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace LMEMappeCatastaliApp.Services;
|
||||
|
||||
public sealed class IncomingFileService
|
||||
{
|
||||
private readonly ConcurrentQueue<IncomingFile> _files = new();
|
||||
public static IncomingFileService Shared { get; } = new();
|
||||
public event Action? FileAvailable;
|
||||
|
||||
public void Enqueue(IncomingFile file)
|
||||
{
|
||||
_files.Enqueue(file);
|
||||
MainThread.BeginInvokeOnMainThread(() => FileAvailable?.Invoke());
|
||||
}
|
||||
|
||||
public bool TryDequeue(out IncomingFile? file) => _files.TryDequeue(out file);
|
||||
}
|
||||
|
||||
public sealed record IncomingFile(string Path, string FileName, string? ContentType);
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "10.0.401",
|
||||
"rollForward": "latestPatch"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
param([string]$Configuration = "Release")
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$projectRoot = Split-Path -Parent $PSScriptRoot
|
||||
$dotnet = Join-Path $env:USERPROFILE ".dotnet10\dotnet.exe"
|
||||
$androidSdk = Join-Path $env:LOCALAPPDATA "Android\Sdk"
|
||||
$keyStore = Join-Path $env:LOCALAPPDATA "Xamarin\Mono for Android\debug.keystore"
|
||||
$outputDirectory = Join-Path $projectRoot "artifacts\android-test"
|
||||
$projectPath = Join-Path $projectRoot "LMEMappeCatastaliApp.csproj"
|
||||
[xml]$projectXml = Get-Content -Raw -LiteralPath $projectPath
|
||||
$appVersion = ($projectXml.Project.PropertyGroup | Where-Object ApplicationDisplayVersion | Select-Object -First 1).ApplicationDisplayVersion
|
||||
|
||||
foreach ($requiredPath in @($dotnet, $androidSdk, $keyStore)) {
|
||||
if (-not (Test-Path -LiteralPath $requiredPath)) { throw "Componente richiesto non trovato: $requiredPath" }
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
|
||||
$packages = [System.Collections.Generic.List[System.IO.FileInfo]]::new()
|
||||
foreach ($format in @("apk", "aab")) {
|
||||
$publishArguments = @(
|
||||
"publish", $projectPath,
|
||||
"-f", "net10.0-android",
|
||||
"-c", $Configuration,
|
||||
"-p:AndroidSdkDirectory=$androidSdk",
|
||||
"-p:AndroidPackageFormat=$format",
|
||||
"-p:AndroidKeyStore=true",
|
||||
"-p:AndroidSigningKeyStore=$keyStore",
|
||||
"-p:AndroidSigningKeyAlias=androiddebugkey",
|
||||
"-p:AndroidSigningStorePass=android",
|
||||
"-p:AndroidSigningKeyPass=android"
|
||||
)
|
||||
& $dotnet @publishArguments
|
||||
if ($LASTEXITCODE -ne 0) { throw "Pubblicazione Android $format non riuscita." }
|
||||
|
||||
$publishDirectory = Join-Path $projectRoot "bin\$Configuration\net10.0-android\publish"
|
||||
$package = Get-ChildItem -LiteralPath $publishDirectory -Filter "*-Signed.$format" -File |
|
||||
Sort-Object LastWriteTime -Descending |
|
||||
Select-Object -First 1
|
||||
if ($null -eq $package) { throw "Nessun pacchetto $format firmato prodotto." }
|
||||
|
||||
$destination = Join-Path $outputDirectory "LME-Mappe-Catastali-$appVersion.$format"
|
||||
Copy-Item -LiteralPath $package.FullName -Destination $destination -Force
|
||||
$packages.Add((Get-Item -LiteralPath $destination))
|
||||
}
|
||||
|
||||
$packages | ForEach-Object {
|
||||
$hash = Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName
|
||||
"$($hash.Hash.ToLowerInvariant()) $($_.Name)"
|
||||
} | Set-Content -LiteralPath (Join-Path $outputDirectory "SHA256SUMS.txt") -Encoding ascii
|
||||
|
||||
$packages | Select-Object Name, Length, LastWriteTime
|
||||
+62
-23
@@ -167,6 +167,7 @@ window.lmeMap = {
|
||||
clearOfflineTiles,
|
||||
getOfflineTileStats,
|
||||
resize,
|
||||
importExternalGisFile,
|
||||
showInfo: setInfo
|
||||
};
|
||||
|
||||
@@ -737,29 +738,7 @@ function bindFileImport() {
|
||||
if (file.size > 100 * 1024 * 1024) throw new Error("file superiore a 100 MB; suddividilo prima dell'importazione");
|
||||
setInfo(`Analisi di ${file.name} (${(file.size / 1024 / 1024).toFixed(1)} MB)...`);
|
||||
await new Promise(resolve => window.setTimeout(resolve, 20));
|
||||
const result = await readGisFile(file);
|
||||
rememberMapChange();
|
||||
const geojson = result.geojson;
|
||||
const parcelLayer = addImportedFeatures(geojson);
|
||||
const sheetGeojson = result.sheetGeojson || emptyFeatureCollection();
|
||||
const sheetLayer = addImportedSheetFeatures(sheetGeojson);
|
||||
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" : "";
|
||||
const warnings = result.validationWarnings ? `; ${result.validationWarnings} geometrie da verificare` : "";
|
||||
setInfo(`Caricato ${file.name}: ${featureCount} particelle/elementi${includedSheets}${ignored}${reprojected}${warnings}.`);
|
||||
updateGpsInsideState();
|
||||
refreshLayerManager();
|
||||
finishMapChange();
|
||||
await importGisFile(file);
|
||||
} catch (error) {
|
||||
setInfo(`File non leggibile: ${error.message}`);
|
||||
} finally {
|
||||
@@ -769,6 +748,41 @@ function bindFileImport() {
|
||||
lmeState.fileImportBound = true;
|
||||
}
|
||||
|
||||
async function importExternalGisFile(fileName, base64Content, mimeType) {
|
||||
const binary = atob(base64Content);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
||||
const file = new File([bytes], fileName, { type: mimeType || "application/octet-stream" });
|
||||
if (file.size > 100 * 1024 * 1024) throw new Error("file superiore a 100 MB; suddividilo prima dell'importazione");
|
||||
setInfo(`Analisi di ${file.name} (${(file.size / 1024 / 1024).toFixed(1)} MB)...`);
|
||||
await new Promise(resolve => window.setTimeout(resolve, 20));
|
||||
return importGisFile(file);
|
||||
}
|
||||
|
||||
async function importGisFile(file) {
|
||||
const result = await readGisFile(file);
|
||||
rememberMapChange();
|
||||
const geojson = result.geojson;
|
||||
const parcelLayer = addImportedFeatures(geojson);
|
||||
const sheetGeojson = result.sheetGeojson || emptyFeatureCollection();
|
||||
const sheetLayer = addImportedSheetFeatures(sheetGeojson);
|
||||
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" : "";
|
||||
const warnings = result.validationWarnings ? `; ${result.validationWarnings} geometrie da verificare` : "";
|
||||
const message = `Caricato ${file.name}: ${featureCount} particelle/elementi${includedSheets}${ignored}${reprojected}${warnings}.`;
|
||||
setInfo(message);
|
||||
updateGpsInsideState();
|
||||
refreshLayerManager();
|
||||
finishMapChange();
|
||||
return message;
|
||||
}
|
||||
|
||||
async function readGisFile(file) {
|
||||
const lowerName = file.name.toLowerCase();
|
||||
|
||||
@@ -985,6 +999,15 @@ function normalizeKmlFiles(files) {
|
||||
throw new Error("KML senza geometrie utilizzabili");
|
||||
}
|
||||
|
||||
if (!looksLikeCadastralKml(features)) {
|
||||
return {
|
||||
geojson: { type: "FeatureCollection", features },
|
||||
sheetGeojson: emptyFeatureCollection(),
|
||||
ignoredCount: 0,
|
||||
reprojected: false
|
||||
};
|
||||
}
|
||||
|
||||
const polygonParts = splitKmlPolygonFeatures(features);
|
||||
const parcels = filterKmlParcelFeatures(polygonParts);
|
||||
const parcelSet = new Set(parcels);
|
||||
@@ -1005,6 +1028,22 @@ function normalizeKmlFiles(files) {
|
||||
};
|
||||
}
|
||||
|
||||
function looksLikeCadastralKml(features) {
|
||||
return features.some(feature => {
|
||||
const properties = feature?.properties || {};
|
||||
const name = String(properties.name || properties.Name || properties.LABEL || "").trim();
|
||||
const context = [
|
||||
name,
|
||||
properties.layer,
|
||||
properties.Layer,
|
||||
properties.type,
|
||||
properties.Tipo,
|
||||
properties._lmeFolder
|
||||
].filter(Boolean).join(" ").toLowerCase();
|
||||
return /\b(particell|mappal|catast|foglio|parcel|cadastral)\w*/i.test(context);
|
||||
});
|
||||
}
|
||||
|
||||
function kmlTextToGeoJson(text, sourceName) {
|
||||
const xml = new DOMParser().parseFromString(text, "text/xml");
|
||||
if (xml.getElementsByTagName("parsererror").length) {
|
||||
|
||||
Reference in new issue
Block a user