mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-08-15 15:40:32 +02:00
helps with load speed and number of connection refused messages
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_map/flutter_map.dart'; // LatLngBounds
|
||||
import 'package:latlong2/latlong.dart'; // LatLng
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../models/camera_profile.dart';
|
||||
import '../models/osm_camera_node.dart';
|
||||
@@ -16,7 +15,7 @@ class OverpassService {
|
||||
) async {
|
||||
if (profiles.isEmpty) return [];
|
||||
|
||||
// Combine enabled profile types into a regex
|
||||
// Build regex of surveillance:type values from enabled profiles
|
||||
final types = profiles
|
||||
.map((p) => p.tags['surveillance:type'])
|
||||
.whereType<String>()
|
||||
@@ -35,20 +34,25 @@ class OverpassService {
|
||||
out body 100;
|
||||
''';
|
||||
|
||||
final resp =
|
||||
await http.post(Uri.parse(_endpoint), body: {'data': query.trim()});
|
||||
if (resp.statusCode != 200) return [];
|
||||
try {
|
||||
final resp =
|
||||
await http.post(Uri.parse(_endpoint), body: {'data': query.trim()});
|
||||
if (resp.statusCode != 200) return [];
|
||||
|
||||
final data = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
final elements = data['elements'] as List<dynamic>;
|
||||
final data = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
final elements = data['elements'] as List<dynamic>;
|
||||
|
||||
return elements.whereType<Map<String, dynamic>>().map((e) {
|
||||
return OsmCameraNode(
|
||||
id: e['id'],
|
||||
coord: LatLng(e['lat'], e['lon']),
|
||||
tags: Map<String, String>.from(e['tags'] ?? {}),
|
||||
);
|
||||
}).toList();
|
||||
return elements.whereType<Map<String, dynamic>>().map((e) {
|
||||
return OsmCameraNode(
|
||||
id: e['id'],
|
||||
coord: LatLng(e['lat'], e['lon']),
|
||||
tags: Map<String, String>.from(e['tags'] ?? {}),
|
||||
);
|
||||
}).toList();
|
||||
} catch (_) {
|
||||
// Network error – return empty list silently
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user