mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-07 01:06:39 +10:00
add OSM Auto Map
This commit is contained in:
@@ -147,8 +147,8 @@ class AppSettings {
|
||||
this.mapCacheBounds,
|
||||
this.mapCacheMinZoom = 10,
|
||||
this.mapCacheMaxZoom = 15,
|
||||
this.mapRasterSourceId = 'osm_standard',
|
||||
this.mapTileEndpointId = 'standard',
|
||||
this.mapRasterSourceId = 'osm_auto',
|
||||
this.mapTileEndpointId = 'standard_2x',
|
||||
this.mapTileApiKey,
|
||||
this.notificationsEnabled = true,
|
||||
this.notifyOnNewMessage = true,
|
||||
@@ -276,8 +276,7 @@ class AppSettings {
|
||||
),
|
||||
mapCacheMinZoom: json['map_cache_min_zoom'] as int? ?? 10,
|
||||
mapCacheMaxZoom: json['map_cache_max_zoom'] as int? ?? 15,
|
||||
mapRasterSourceId:
|
||||
json['map_raster_source_id'] as String? ?? 'osm_standard',
|
||||
mapRasterSourceId: json['map_raster_source_id'] as String? ?? 'osm_auto',
|
||||
mapTileEndpointId: json['map_tile_endpoint_id'] as String? ?? 'standard',
|
||||
mapTileApiKey: json['map_tile_api_key'] as String?,
|
||||
notificationsEnabled: json['notifications_enabled'] as bool? ?? true,
|
||||
|
||||
@@ -426,9 +426,7 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Text(
|
||||
_isLoadingCachedTiles
|
||||
? 'Loading cached tiles...'
|
||||
: 'Visible cached tiles at z${_overlayZoom.round()}: ${overlayPolygons.length}',
|
||||
'Z: ${_overlayZoom.round()}:',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../models/app_settings.dart';
|
||||
import 'app_settings_service.dart';
|
||||
|
||||
enum MapRasterSourcePreset {
|
||||
osmAuto('osm_auto'),
|
||||
osmStandard('osm_standard'),
|
||||
osmDark('osm_dark'),
|
||||
stamenTerrain('stamen_terrain'),
|
||||
@@ -24,7 +25,7 @@ enum MapRasterSourcePreset {
|
||||
for (final value in values) {
|
||||
if (value.id == id) return value;
|
||||
}
|
||||
return MapRasterSourcePreset.osmStandard;
|
||||
return MapRasterSourcePreset.osmAuto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +82,12 @@ class MapRasterEndpointDefinition {
|
||||
}
|
||||
|
||||
class MapRasterSourceCatalog {
|
||||
static const MapRasterSourceDefinition osmAuto = MapRasterSourceDefinition(
|
||||
id: 'osm_auto',
|
||||
label: 'OpenStreetMap Auto',
|
||||
description:
|
||||
'Automatically uses OpenStreetMap Standard or Dark from the app theme',
|
||||
);
|
||||
static const MapRasterSourceDefinition osmStandard =
|
||||
MapRasterSourceDefinition(
|
||||
id: 'osm_standard',
|
||||
@@ -124,6 +131,7 @@ class MapRasterSourceCatalog {
|
||||
);
|
||||
|
||||
static const List<MapRasterSourceDefinition> presets = [
|
||||
osmAuto,
|
||||
osmStandard,
|
||||
osmDark,
|
||||
stamenTerrain,
|
||||
@@ -135,6 +143,8 @@ class MapRasterSourceCatalog {
|
||||
static MapRasterSourceDefinition fromSettings(AppSettings settings) {
|
||||
final preset = MapRasterSourcePreset.fromId(settings.mapRasterSourceId);
|
||||
switch (preset) {
|
||||
case MapRasterSourcePreset.osmAuto:
|
||||
return osmAuto;
|
||||
case MapRasterSourcePreset.osmStandard:
|
||||
return osmStandard;
|
||||
case MapRasterSourcePreset.osmDark:
|
||||
@@ -149,6 +159,40 @@ class MapRasterSourceCatalog {
|
||||
return stamenTerrain;
|
||||
}
|
||||
}
|
||||
|
||||
static MapRasterSourceDefinition resolveFromSettings(
|
||||
AppSettings settings, {
|
||||
Brightness? platformBrightness,
|
||||
}) {
|
||||
final selected = fromSettings(settings);
|
||||
if (selected.id != osmAuto.id) return selected;
|
||||
|
||||
return _prefersDarkTheme(
|
||||
settings.themeMode,
|
||||
platformBrightness: platformBrightness,
|
||||
)
|
||||
? osmDark
|
||||
: osmStandard;
|
||||
}
|
||||
|
||||
static bool _prefersDarkTheme(
|
||||
String themeMode, {
|
||||
Brightness? platformBrightness,
|
||||
}) {
|
||||
switch (themeMode) {
|
||||
case 'dark':
|
||||
return true;
|
||||
case 'light':
|
||||
return false;
|
||||
default:
|
||||
return (platformBrightness ??
|
||||
WidgetsBinding
|
||||
.instance
|
||||
.platformDispatcher
|
||||
.platformBrightness) ==
|
||||
Brightness.dark;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MapRasterEndpointCatalog {
|
||||
@@ -281,7 +325,7 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
}
|
||||
|
||||
MapRasterSourceDefinition get source =>
|
||||
MapRasterSourceCatalog.fromSettings(appSettingsService.settings);
|
||||
MapRasterSourceCatalog.resolveFromSettings(appSettingsService.settings);
|
||||
|
||||
MapRasterEndpointDefinition get endpoint =>
|
||||
MapRasterEndpointCatalog.fromSettings(appSettingsService.settings);
|
||||
|
||||
Reference in New Issue
Block a user