feat: Add support for offline vector maps using MBTiles

- Introduced new MapLayerType for vector MBTiles.
- Enhanced MapLayer class to handle vector-specific properties.
- Implemented MBTilesService for managing MBTiles files, including import and deletion functionalities.
- Updated MapManagementScreen to allow importing and managing MBTiles files.
- Added UI components for displaying and interacting with MBTiles layers.
- Integrated vector tile rendering in MapTab, supporting dynamic theme loading.
- Updated pubspec.yaml to include necessary dependencies for MBTiles and vector tiles.
This commit is contained in:
Janez T
2025-10-16 23:35:43 +02:00
parent 7f20e5ad36
commit 3a0bcabdea
26 changed files with 2042 additions and 74 deletions

View File

@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:flutter/material.dart';
import '../l10n/app_localizations.dart';
@@ -5,6 +6,7 @@ enum MapLayerType {
openStreetMap,
openTopoMap,
esriWorldImagery,
vectorMbtiles,
}
class MapLayer {
@@ -14,12 +16,24 @@ class MapLayer {
final String attribution;
final double maxZoom;
// Vector tile specific properties
final bool isVector;
final File? mbtilesFile;
final String? styleUrl;
final String? sourceName;
final bool? isGzipped;
const MapLayer({
required this.type,
required this.name,
required this.urlTemplate,
required this.attribution,
required this.maxZoom,
this.isVector = false,
this.mbtilesFile,
this.styleUrl,
this.sourceName,
this.isGzipped,
});
/// Get localized name for the layer
@@ -32,6 +46,9 @@ class MapLayer {
return localizations.openTopoMap;
case MapLayerType.esriWorldImagery:
return localizations.esriSatellite;
case MapLayerType.vectorMbtiles:
// For vector tiles, use the name from metadata
return name;
}
}
@@ -69,4 +86,28 @@ class MapLayer {
static MapLayer fromType(MapLayerType type) {
return allLayers.firstWhere((layer) => layer.type == type);
}
/// Create a MapLayer from an MBTiles file
static MapLayer fromMbtilesFile({
required String name,
required File mbtilesFile,
required String styleUrl,
required String sourceName,
required double maxZoom,
required bool isGzipped,
String? attribution,
}) {
return MapLayer(
type: MapLayerType.vectorMbtiles,
name: name,
urlTemplate: '', // Not used for vector tiles
attribution: attribution ?? 'MBTiles',
maxZoom: maxZoom,
isVector: true,
mbtilesFile: mbtilesFile,
styleUrl: styleUrl,
sourceName: sourceName,
isGzipped: isGzipped,
);
}
}