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