mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-06 08:46:40 +10:00
fix StadiaMaps Dark and add demo.
This commit is contained in:
@@ -76,6 +76,8 @@ class Cyr2LatProfile {
|
||||
|
||||
class AppSettings {
|
||||
static const Object _unset = Object();
|
||||
static const String stadiaDemo =
|
||||
'51bd0381-4685-4666-bae8-48940f6d77c0';
|
||||
|
||||
final bool clearPathOnMaxRetry;
|
||||
final bool mapShowRepeaters;
|
||||
@@ -125,6 +127,17 @@ class AppSettings {
|
||||
final List<Cyr2LatProfile> cyr2latProfiles;
|
||||
final String selectedCyr2latProfileId;
|
||||
|
||||
String get effectiveMapTileApiKey {
|
||||
final apiKey = mapTileApiKey?.trim();
|
||||
if (apiKey == null || apiKey.isEmpty) {
|
||||
return stadiaDemo;
|
||||
}
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
bool get usesstadiaDemo =>
|
||||
effectiveMapTileApiKey == stadiaDemo;
|
||||
|
||||
Map<String, String> get cyr2latCharMap {
|
||||
final profile = cyr2latProfiles.firstWhere(
|
||||
(p) => p.id == selectedCyr2latProfileId,
|
||||
|
||||
@@ -1019,11 +1019,9 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
String _mapApiKeySummary(BuildContext context, AppSettings settings) {
|
||||
final apiKey = settings.mapTileApiKey?.trim();
|
||||
if (apiKey == null || apiKey.isEmpty) {
|
||||
return context.l10n.appSettings_stadiaApiKeyRequired;
|
||||
}
|
||||
return context.l10n.appSettings_stadiaApiKeyConfigured(_maskApiKey(apiKey));
|
||||
return context.l10n.appSettings_stadiaApiKeyConfigured(
|
||||
_maskApiKey(settings.effectiveMapTileApiKey),
|
||||
);
|
||||
}
|
||||
|
||||
String _maskApiKey(String value) {
|
||||
@@ -1153,9 +1151,13 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
BuildContext context,
|
||||
AppSettingsService settingsService,
|
||||
) {
|
||||
final controller = TextEditingController(
|
||||
text: settingsService.settings.mapTileApiKey ?? '',
|
||||
final currentApiKey = settingsService.settings.mapTileApiKey?.trim() ?? '';
|
||||
final maskedApiKey = _maskApiKey(
|
||||
currentApiKey.isEmpty
|
||||
? AppSettings.stadiaDemo
|
||||
: currentApiKey,
|
||||
);
|
||||
final controller = TextEditingController(text: maskedApiKey);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
@@ -1173,6 +1175,7 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
autofocus: true,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
autofillHints: const [AutofillHints.password],
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
hintText: '4e1bf343-3d91-4d9c-a8e1-1234567890ab',
|
||||
@@ -1188,7 +1191,10 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await settingsService.setMapTileApiKey(controller.text);
|
||||
final apiKey = controller.text.trim();
|
||||
await settingsService.setMapTileApiKey(
|
||||
apiKey == maskedApiKey ? currentApiKey : apiKey,
|
||||
);
|
||||
if (!dialogContext.mounted) return;
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
|
||||
@@ -305,8 +305,22 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
appSettingsService.addListener(_handleSettingsChanged);
|
||||
}
|
||||
|
||||
MapRasterSourceDefinition get source =>
|
||||
MapRasterSourceCatalog.fromSettings(appSettingsService.settings);
|
||||
MapRasterSourceDefinition get source {
|
||||
final selectedSource = MapRasterSourceCatalog.fromSettings(
|
||||
appSettingsService.settings,
|
||||
);
|
||||
if (!selectedSource.allowsBulkDownload ||
|
||||
!appSettingsService.settings.usesstadiaDemo) {
|
||||
return selectedSource;
|
||||
}
|
||||
return MapRasterSourceDefinition(
|
||||
id: selectedSource.id,
|
||||
label: selectedSource.label,
|
||||
description: selectedSource.description,
|
||||
isStadia: selectedSource.isStadia,
|
||||
allowsBulkDownload: false, // Explicitly disable bulk download for demo.
|
||||
);
|
||||
}
|
||||
|
||||
MapRasterEndpointDefinition get endpoint =>
|
||||
MapRasterEndpointCatalog.fromSettings(appSettingsService.settings);
|
||||
@@ -315,6 +329,26 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
|
||||
TileBuilder? get tileBuilder => null;
|
||||
|
||||
static bool shouldApplyDarkFilterForSettings(
|
||||
AppSettings settings,
|
||||
Brightness brightness,
|
||||
) {
|
||||
switch (MapRasterSourcePreset.fromId(settings.mapRasterSourceId)) {
|
||||
case MapRasterSourcePreset.osmDark:
|
||||
case MapRasterSourcePreset.outdoorsDark:
|
||||
case MapRasterSourcePreset.osmBrightDark:
|
||||
return true;
|
||||
case MapRasterSourcePreset.osmAuto:
|
||||
return brightness == Brightness.dark;
|
||||
case MapRasterSourcePreset.osmStandard:
|
||||
case MapRasterSourcePreset.stamenTerrain:
|
||||
case MapRasterSourcePreset.alidadeSmoothDark:
|
||||
case MapRasterSourcePreset.outdoors:
|
||||
case MapRasterSourcePreset.osmBright:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static const ColorFilter _darkMapFilter = ColorFilter.matrix([
|
||||
-0.0850,
|
||||
-0.2861,
|
||||
@@ -345,7 +379,6 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
};
|
||||
|
||||
Widget buildTileLayer(BuildContext context, {double opacity = 1}) {
|
||||
final source = this.source;
|
||||
Widget layer = TileLayer(
|
||||
urlTemplate: urlTemplate,
|
||||
tileProvider: tileProvider,
|
||||
@@ -354,12 +387,10 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
maxZoom: 19,
|
||||
);
|
||||
|
||||
final shouldApplyDarkFilter =
|
||||
source == MapRasterSourceCatalog.osmDark ||
|
||||
source == MapRasterSourceCatalog.outdoorsDark ||
|
||||
source == MapRasterSourceCatalog.osmBrightDark ||
|
||||
(source == MapRasterSourceCatalog.osmAuto &&
|
||||
Theme.of(context).brightness == Brightness.dark);
|
||||
final shouldApplyDarkFilter = shouldApplyDarkFilterForSettings(
|
||||
appSettingsService.settings,
|
||||
Theme.of(context).brightness,
|
||||
);
|
||||
|
||||
if (shouldApplyDarkFilter) {
|
||||
layer = ColorFiltered(colorFilter: _darkMapFilter, child: layer);
|
||||
@@ -608,12 +639,9 @@ class MapTileCacheService extends ChangeNotifier {
|
||||
return 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
||||
}
|
||||
final endpoint = MapRasterEndpointCatalog.fromSettings(settings);
|
||||
final apiKey = settings.mapTileApiKey?.trim();
|
||||
final apiKey = settings.effectiveMapTileApiKey;
|
||||
final base =
|
||||
'https://${endpoint.host}/tiles/${source.id}/{z}/{x}/{y}${endpoint.scaleSuffix}.png';
|
||||
if (apiKey == null || apiKey.isEmpty) {
|
||||
return base;
|
||||
}
|
||||
final query = Uri(queryParameters: {'api_key': apiKey}).query;
|
||||
return '$base?$query';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user