99 lines
3.3 KiB
Dart
99 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'map_layer_settings.dart';
|
|
import 'map_provider_interface.dart';
|
|
import 'map_providers.dart';
|
|
|
|
class UnifiedMapView extends ConsumerWidget {
|
|
final AppLatLng center;
|
|
final double zoom;
|
|
final double bearing;
|
|
final List<AppMapMarker> markers;
|
|
final List<AppPolyline> polylines;
|
|
final ValueChanged<AppLatLng>? onPositionChanged;
|
|
final VoidCallback? onUserInteraction;
|
|
final MapConfig? configOverride;
|
|
final bool? isFollowModeOverride;
|
|
|
|
const UnifiedMapView({
|
|
super.key,
|
|
required this.center,
|
|
this.zoom = 16.0,
|
|
this.bearing = 0.0,
|
|
this.markers = const [],
|
|
this.polylines = const [],
|
|
this.onPositionChanged,
|
|
this.onUserInteraction,
|
|
this.configOverride,
|
|
this.isFollowModeOverride,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
AppMapProvider provider;
|
|
MapConfig activeConfig;
|
|
|
|
if (configOverride != null) {
|
|
provider = ref.watch(activeMapProvider);
|
|
if (provider.type == AppMapType.googleMaps) {
|
|
provider = ref.watch(openStreetMapProviderInstance);
|
|
}
|
|
activeConfig = configOverride!;
|
|
} else {
|
|
final layerSettings = ref.watch(mapLayerSettingsProvider);
|
|
switch (layerSettings.style) {
|
|
case TacticalMapStyle.tacticalDark:
|
|
provider = ref.watch(openStreetMapProviderInstance);
|
|
final isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
|
activeConfig = isDarkTheme
|
|
? MapConfig.tacticalDark(offlineOnly: layerSettings.offlineOnly)
|
|
: MapConfig(
|
|
isDarkMode: false,
|
|
offlineOnly: layerSettings.offlineOnly,
|
|
);
|
|
break;
|
|
case TacticalMapStyle.satellite4K:
|
|
final aws = ref.watch(awsMapProviderInstance);
|
|
provider = aws;
|
|
activeConfig = aws.apiKey.isNotEmpty
|
|
? MapConfig.awsLocation(
|
|
apiKey: aws.apiKey,
|
|
region: aws.region,
|
|
offlineOnly: layerSettings.offlineOnly,
|
|
)
|
|
: MapConfig.satellite4K(offlineOnly: layerSettings.offlineOnly);
|
|
break;
|
|
case TacticalMapStyle.elevation3D:
|
|
provider = ref.watch(openStreetMapProviderInstance);
|
|
activeConfig = MapConfig.elevation3D(offlineOnly: layerSettings.offlineOnly);
|
|
break;
|
|
}
|
|
|
|
// If user has explicitly selected Google Maps in developer / app settings, respect it
|
|
final selectedType = ref.watch(mapProviderTypeNotifierProvider);
|
|
if (selectedType == AppMapType.googleMaps) {
|
|
provider = ref.watch(googleMapProviderInstance);
|
|
activeConfig = ref.watch(mapConfigProvider);
|
|
}
|
|
}
|
|
|
|
final bool isFollowMode = isFollowModeOverride ?? ref.watch(mapFollowStateProvider);
|
|
|
|
return provider.buildMapView(
|
|
context: context,
|
|
center: center,
|
|
zoom: zoom,
|
|
bearing: bearing,
|
|
markers: markers,
|
|
polylines: polylines,
|
|
isFollowMode: isFollowMode,
|
|
config: activeConfig,
|
|
onPositionChanged: onPositionChanged,
|
|
onUserInteraction: () {
|
|
ref.read(mapFollowStateProvider.notifier).userInteracted();
|
|
onUserInteraction?.call();
|
|
},
|
|
);
|
|
}
|
|
}
|