From 95df9764759f737407289a5a0eed6e583867058d Mon Sep 17 00:00:00 2001 From: stopflock Date: Fri, 18 Jul 2025 23:12:54 -0500 Subject: [PATCH] we have fov cones --- lib/models/osm_camera_node.dart | 16 ++++++++++++++-- lib/screens/home_screen.dart | 1 - lib/widgets/map_view.dart | 24 +++++++++++++++++++----- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/models/osm_camera_node.dart b/lib/models/osm_camera_node.dart index f2e17aa..7e994b4 100644 --- a/lib/models/osm_camera_node.dart +++ b/lib/models/osm_camera_node.dart @@ -15,8 +15,20 @@ class OsmCameraNode { tags.containsKey('direction') || tags.containsKey('camera:direction'); double? get directionDeg { - final val = tags['direction'] ?? tags['camera:direction']; - return double.tryParse(val ?? ''); + final raw = tags['direction'] ?? tags['camera:direction']; + if (raw == null) return null; + + // Keep digits, optional dot, optional leading sign. + final match = RegExp(r'[-+]?\d*\.?\d+').firstMatch(raw); + if (match == null) return null; + + final numStr = match.group(0); + final val = double.tryParse(numStr ?? ''); + if (val == null) return null; + + // Normalize: wrap negative or >360 into 0‑359 range. + final normalized = ((val % 360) + 360) % 360; + return normalized; } } diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 2f6ca4f..a6001bc 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -27,7 +27,6 @@ class _HomeScreenState extends State { builder: (_) => const AddCameraSheet(), ); - // null == closed via system back (treat as cancel) if (submitted == true) { appState.commitSession(); if (mounted) { diff --git a/lib/widgets/map_view.dart b/lib/widgets/map_view.dart index be23920..fc1d95a 100644 --- a/lib/widgets/map_view.dart +++ b/lib/widgets/map_view.dart @@ -95,6 +95,19 @@ class _MapViewState extends State { Widget build(BuildContext context) { final appState = context.watch(); final session = appState.session; + + // If we just entered add‑mode and no target yet, seed it with current map center. + if (session != null && session.target == null) { + try { + final center = _controller.camera.center; + WidgetsBinding.instance.addPostFrameCallback( + (_) => appState.updateSession(target: center), + ); + } catch (_) { + // controller not ready yet; will update onPositionChanged soon + } + } + final zoom = _safeZoom(); final markers = [ @@ -141,8 +154,7 @@ class _MapViewState extends State { ), children: [ TileLayer( - urlTemplate: - 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', + urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', userAgentPackageName: 'com.example.flock_map_app', ), PolygonLayer(polygons: overlays), @@ -161,7 +173,7 @@ class _MapViewState extends State { Polygon _buildCone(LatLng origin, double bearingDeg, double zoom) { const halfAngle = 15.0; - final length = 0.002 * math.pow(2, 15 - zoom); + final length = 0.002 * math.pow(2, 15 - zoom); // scale with zoom LatLng _project(double deg) { final rad = deg * math.pi / 180; @@ -175,9 +187,11 @@ class _MapViewState extends State { final right = _project(bearingDeg + halfAngle); return Polygon( - points: [origin, left, right], + points: [origin, left, right, origin], + isFilled: true, color: Colors.redAccent.withOpacity(0.25), - borderStrokeWidth: 0, + borderColor: Colors.redAccent, + borderStrokeWidth: 1, ); } }