mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-16 09:07:29 +02:00
Sorta working suspected locations
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math' as math;
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
/// A suspected surveillance location from the CSV data
|
||||
@@ -41,16 +42,39 @@ class SuspectedLocation {
|
||||
// Parse GeoJSON if available
|
||||
if (locationString != null && locationString.isNotEmpty) {
|
||||
try {
|
||||
print('[SuspectedLocation] Parsing GeoJSON for ticket ${row['ticket_no']}, length: ${locationString.length}');
|
||||
// Only log first few entries to avoid spam
|
||||
final ticketNo = row['ticket_no']?.toString() ?? 'unknown';
|
||||
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
|
||||
print('[SuspectedLocation] Raw location string for ticket $ticketNo: ${locationString.substring(0, math.min(100, locationString.length))}...');
|
||||
}
|
||||
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
|
||||
if (centroid.latitude != 0 || centroid.longitude != 0) {
|
||||
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
|
||||
} else {
|
||||
print('[SuspectedLocation] Parsed but got zero coordinates');
|
||||
}
|
||||
}
|
||||
geoJson = jsonDecode(locationString) as Map<String, dynamic>;
|
||||
final coordinates = _extractCoordinatesFromGeoJson(geoJson);
|
||||
centroid = coordinates.centroid;
|
||||
bounds = coordinates.bounds;
|
||||
print('[SuspectedLocation] Successfully parsed, centroid: $centroid, bounds count: ${bounds.length}');
|
||||
} catch (e, stackTrace) {
|
||||
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
|
||||
if (centroid.latitude != 0 || centroid.longitude != 0) {
|
||||
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
|
||||
} else {
|
||||
print('[SuspectedLocation] Parsed but got zero coordinates');
|
||||
}
|
||||
}
|
||||
if (ticketNo.endsWith('0') || ticketNo.endsWith('1') || ticketNo.endsWith('2')) {
|
||||
if (centroid.latitude != 0 || centroid.longitude != 0) {
|
||||
print('[SuspectedLocation] Successfully parsed centroid: $centroid');
|
||||
} else {
|
||||
print('[SuspectedLocation] Parsed but got zero coordinates');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// If GeoJSON parsing fails, use default coordinates
|
||||
print('[SuspectedLocation] Failed to parse GeoJSON for ticket ${row['ticket_no']}: $e');
|
||||
print('[SuspectedLocation] Stack trace: $stackTrace');
|
||||
print('[SuspectedLocation] Location string: $locationString');
|
||||
}
|
||||
}
|
||||
@@ -74,17 +98,17 @@ class SuspectedLocation {
|
||||
/// Extract coordinates from GeoJSON
|
||||
static ({LatLng centroid, List<LatLng> bounds}) _extractCoordinatesFromGeoJson(Map<String, dynamic> geoJson) {
|
||||
try {
|
||||
final geometry = geoJson['geometry'] as Map<String, dynamic>?;
|
||||
final coordinates = geometry?['coordinates'] as List?;
|
||||
|
||||
// The geoJson IS the geometry object (not wrapped in a 'geometry' property)
|
||||
final coordinates = geoJson['coordinates'] as List?;
|
||||
if (coordinates == null || coordinates.isEmpty) {
|
||||
print('[SuspectedLocation] No coordinates found in GeoJSON');
|
||||
return (centroid: const LatLng(0, 0), bounds: <LatLng>[]);
|
||||
}
|
||||
|
||||
final List<LatLng> points = [];
|
||||
|
||||
// Handle different geometry types
|
||||
final type = geometry?['type'] as String?;
|
||||
final type = geoJson['type'] as String?;
|
||||
switch (type) {
|
||||
case 'Point':
|
||||
if (coordinates.length >= 2) {
|
||||
|
||||
Reference in New Issue
Block a user