bump ver, get rid of buggy north-lock

This commit is contained in:
stopflock
2025-10-22 17:36:34 -05:00
parent 728ec08ab0
commit c8e2727f69
8 changed files with 27 additions and 128 deletions
+16 -39
View File
@@ -6,7 +6,7 @@ import 'package:provider/provider.dart';
import '../app_state.dart';
/// A compass indicator widget that shows the current map rotation and allows tapping to enable/disable north lock.
/// A compass indicator widget that shows the current map rotation and allows tapping to animate to north.
/// The compass appears in the top-right corner of the map and is disabled (non-interactive) when in follow+rotate mode.
class CompassIndicator extends StatefulWidget {
final AnimatedMapController mapController;
@@ -21,8 +21,6 @@ class CompassIndicator extends StatefulWidget {
}
class _CompassIndicatorState extends State<CompassIndicator> {
double _lastRotation = 0.0;
@override
Widget build(BuildContext context) {
return Consumer<AppState>(
@@ -40,38 +38,23 @@ class _CompassIndicatorState extends State<CompassIndicator> {
// Check if we're in follow+rotate mode (compass should be disabled)
final isDisabled = appState.followMeMode == FollowMeMode.rotating;
final northLockEnabled = appState.northLockEnabled;
// Force rebuild when north lock changes by comparing rotation
if (northLockEnabled && rotationDegrees != _lastRotation) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) setState(() {});
});
}
_lastRotation = rotationDegrees;
return Positioned(
top: (appState.uploadMode == UploadMode.sandbox || appState.uploadMode == UploadMode.simulate) ? 60 : 18,
right: 16,
child: GestureDetector(
onTap: isDisabled ? null : () {
// Toggle north lock (but not when in follow+rotate mode)
final newNorthLockEnabled = !northLockEnabled;
appState.setNorthLockEnabled(newNorthLockEnabled);
// If enabling north lock, animate to north-up orientation
if (newNorthLockEnabled) {
try {
widget.mapController.animateTo(
dest: widget.mapController.mapController.camera.center,
zoom: widget.mapController.mapController.camera.zoom,
rotation: 0.0,
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut,
);
} catch (_) {
// Controller not ready, ignore
}
// Animate to north-up orientation
try {
widget.mapController.animateTo(
dest: widget.mapController.mapController.camera.center,
zoom: widget.mapController.mapController.camera.zoom,
rotation: 0.0,
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut,
);
} catch (_) {
// Controller not ready, ignore
}
},
child: Container(
@@ -85,10 +68,8 @@ class _CompassIndicatorState extends State<CompassIndicator> {
border: Border.all(
color: isDisabled
? Colors.grey.shade400
: (northLockEnabled
? Theme.of(context).colorScheme.primary
: Colors.grey.shade300),
width: northLockEnabled ? 3.0 : 2.0,
: Colors.grey.shade300,
width: 2.0,
),
boxShadow: [
BoxShadow(
@@ -128,9 +109,7 @@ class _CompassIndicatorState extends State<CompassIndicator> {
size: 20,
color: isDisabled
? Colors.grey.shade600
: (northLockEnabled
? Colors.red.shade700
: Colors.red.shade600),
: Colors.red.shade600,
),
),
// Small 'N' label
@@ -141,9 +120,7 @@ class _CompassIndicatorState extends State<CompassIndicator> {
fontWeight: FontWeight.bold,
color: isDisabled
? Colors.grey.shade600
: (northLockEnabled
? Colors.red.shade700
: Colors.red.shade600),
: Colors.red.shade600,
),
),
],
+4 -9
View File
@@ -89,8 +89,7 @@ class GpsController {
int proximityAlertDistance = 200,
List<OsmNode> nearbyNodes = const [],
List<NodeProfile> enabledProfiles = const [],
// Optional parameter for north lock functionality
bool northLockEnabled = false,
}) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
@@ -114,12 +113,11 @@ class GpsController {
WidgetsBinding.instance.addPostFrameCallback((_) {
try {
if (followMeMode == FollowMeMode.follow) {
// Follow position only, keep current rotation (unless north lock is enabled)
final rotation = northLockEnabled ? 0.0 : controller.mapController.camera.rotation;
// Follow position only, keep current rotation
controller.animateTo(
dest: latLng,
zoom: controller.mapController.camera.zoom,
rotation: rotation,
rotation: controller.mapController.camera.rotation,
duration: kFollowMeAnimationDuration,
curve: Curves.easeOut,
);
@@ -157,7 +155,7 @@ class GpsController {
required int Function() getProximityAlertDistance,
required List<OsmNode> Function() getNearbyNodes,
required List<NodeProfile> Function() getEnabledProfiles,
required bool Function() getNorthLockEnabled,
}) async {
final perm = await Geolocator.requestPermission();
if (perm == LocationPermission.denied ||
@@ -173,8 +171,6 @@ class GpsController {
final proximityAlertDistance = getProximityAlertDistance();
final nearbyNodes = getNearbyNodes();
final enabledProfiles = getEnabledProfiles();
final northLockEnabled = getNorthLockEnabled();
processPositionUpdate(
position: position,
followMeMode: currentFollowMeMode,
@@ -184,7 +180,6 @@ class GpsController {
proximityAlertDistance: proximityAlertDistance,
nearbyNodes: nearbyNodes,
enabledProfiles: enabledProfiles,
northLockEnabled: northLockEnabled,
);
});
}
+3 -48
View File
@@ -74,8 +74,7 @@ class MapViewState extends State<MapView> {
// Track map center to clear queue on significant panning
LatLng? _lastCenter;
// Track rotation to detect intentional vs accidental rotation
double? _lastRotation;
// State for proximity alert banner
bool _showProximityBanner = false;
@@ -181,17 +180,7 @@ class MapViewState extends State<MapView> {
}
return [];
},
getNorthLockEnabled: () {
if (mounted) {
try {
return context.read<AppState>().northLockEnabled;
} catch (e) {
debugPrint('[MapView] Could not read north lock enabled: $e');
return false;
}
}
return false;
},
);
// Fetch initial cameras
@@ -561,41 +550,7 @@ class MapViewState extends State<MapView> {
if (gesture) {
widget.onUserGesture();
// Handle north lock: prevent rotation or disable lock if user rotates significantly
if (appState.northLockEnabled) {
try {
final currentRotation = pos.rotation;
if (_lastRotation != null) {
// Calculate rotation change since last gesture
final rotationChange = (currentRotation - _lastRotation!).abs();
// If user tries to rotate significantly, disable north lock and allow it
if (rotationChange > kNorthLockDisableThresholdDegrees) {
appState.setNorthLockEnabled(false);
// Allow this rotation to proceed
} else {
// Small rotation or zoom gesture - force map back to north (0°)
if (currentRotation.abs() > 0.1) { // Only correct if actually rotated
WidgetsBinding.instance.addPostFrameCallback((_) {
try {
_controller.animateTo(
dest: pos.center,
zoom: pos.zoom,
rotation: 0.0,
duration: const Duration(milliseconds: 100), // Quick snap back
curve: Curves.easeOut,
);
} catch (_) {
// Controller not ready, ignore
}
});
}
}
}
_lastRotation = currentRotation;
} catch (_) {
// Controller not ready, ignore
}
}
}
if (session != null) {