From c9a7045212b87be932cba1d90b2bcdbd6706ca6b Mon Sep 17 00:00:00 2001 From: stopflock Date: Wed, 29 Oct 2025 12:53:56 -0500 Subject: [PATCH] Accept cardinal type directions in osm data --- lib/models/osm_node.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/models/osm_node.dart b/lib/models/osm_node.dart index b8ec9ce..613bd4f 100644 --- a/lib/models/osm_node.dart +++ b/lib/models/osm_node.dart @@ -38,15 +38,29 @@ class OsmNode { final raw = tags['direction'] ?? tags['camera:direction']; if (raw == null) return []; + // Compass direction to degree mapping + const compassDirections = { + 'N': 0.0, 'NNE': 22.5, 'NE': 45.0, 'ENE': 67.5, + 'E': 90.0, 'ESE': 112.5, 'SE': 135.0, 'SSE': 157.5, + 'S': 180.0, 'SSW': 202.5, 'SW': 225.0, 'WSW': 247.5, + 'W': 270.0, 'WNW': 292.5, 'NW': 315.0, 'NNW': 337.5, + }; + // Split on semicolons and parse each direction final directions = []; final parts = raw.split(';'); for (final part in parts) { - final trimmed = part.trim(); + final trimmed = part.trim().toUpperCase(); if (trimmed.isEmpty) continue; - // Keep digits, optional dot, optional leading sign + // First try compass direction lookup + if (compassDirections.containsKey(trimmed)) { + directions.add(compassDirections[trimmed]!); + continue; + } + + // Then try numeric parsing final match = RegExp(r'[-+]?\d*\.?\d+').firstMatch(trimmed); if (match == null) continue;