getCurrentCameraState method
Gets the current camera state
Implementation
Future<mapbox.CameraState> getCurrentCameraState() async {
try {
final state = await mapboxMap.getCameraState();
if (DebugSettings.showCameraLogs) {
// Use safer null checking and only log coordinates if available
final coordsStr = state.center.coordinates != null ?
"${state.center!.coordinates.lng.toDouble()},${state.center!.coordinates.lat.toDouble()}" : "unknown";
debugPrint("[CAMERA] Current camera state - center: $coordsStr zoom: ${state.zoom}, pitch: ${state.pitch}, bearing: ${state.bearing}", wrapWidth: 120);
}
return state;
} catch (e) {
print("Error getting camera state: $e");
// Create a minimal valid camera state as fallback
// We need to create a valid Point with coordinates for the center
final point = mapbox.Point(
coordinates: mapbox.Position(0, 0) // Default to 0,0 coordinates
);
return mapbox.CameraState(
center: point,
padding: mapbox.MbxEdgeInsets(top: 0, left: 0, right: 0, bottom: 0),
zoom: 15.0,
bearing: 0.0,
pitch: 0.0
);
}
}