mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-10-12 02:37:11 +02:00
tiles not working but new map data provider exists in theory
This commit is contained in:
1 parent
01e8ebfdbb
commit
3dca7d5751
9 files changed
+232
-16
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
|
||||
import '../models/camera_profile.dart';
|
||||
import '../models/osm_camera_node.dart';
|
||||
import '../app_state.dart';
|
||||
import 'map_data_submodules/cameras_from_overpass.dart';
|
||||
import 'map_data_submodules/tiles_from_osm.dart';
|
||||
|
||||
enum MapSource { local, remote, auto } // For future use
|
||||
|
||||
class OfflineModeException implements Exception {
|
||||
final String message;
|
||||
OfflineModeException(this.message);
|
||||
@override
|
||||
String toString() => 'OfflineModeException: $message';
|
||||
}
|
||||
|
||||
class MapDataProvider {
|
||||
static final MapDataProvider _instance = MapDataProvider._();
|
||||
factory MapDataProvider() => _instance;
|
||||
MapDataProvider._();
|
||||
|
||||
bool _offlineMode = false;
|
||||
bool get isOfflineMode => _offlineMode;
|
||||
void setOfflineMode(bool enabled) {
|
||||
_offlineMode = enabled;
|
||||
}
|
||||
|
||||
/// Fetch cameras from OSM/Overpass or local storage, depending on source/offline mode.
|
||||
Future<List<OsmCameraNode>> getCameras({
|
||||
required LatLngBounds bounds,
|
||||
required List<CameraProfile> profiles,
|
||||
UploadMode uploadMode = UploadMode.production,
|
||||
MapSource source = MapSource.auto,
|
||||
}) async {
|
||||
// Resolve source:
|
||||
if (_offlineMode && source != MapSource.local) {
|
||||
throw OfflineModeException("Cannot fetch remote cameras in offline mode.");
|
||||
}
|
||||
if (source == MapSource.local) {
|
||||
// TODO: implement local camera loading
|
||||
throw UnimplementedError('Local camera loading not yet implemented.');
|
||||
} else {
|
||||
// Use Overpass remote fetch, from submodule:
|
||||
return camerasFromOverpass(bounds: bounds, profiles: profiles, uploadMode: uploadMode);
|
||||
}
|
||||
}
|
||||
/// Fetch tile image bytes from OSM or local (future). Only fetches, does not save!
|
||||
Future<List<int>> getTile({
|
||||
required int z,
|
||||
required int x,
|
||||
required int y,
|
||||
MapSource source = MapSource.auto,
|
||||
}) async {
|
||||
if (_offlineMode && source != MapSource.local) {
|
||||
throw OfflineModeException("Cannot fetch remote tiles in offline mode.");
|
||||
}
|
||||
if (source == MapSource.local) {
|
||||
// TODO: implement local tile loading
|
||||
throw UnimplementedError('Local tile loading not yet implemented.');
|
||||
} else {
|
||||
// Use OSM remote fetch from submodule:
|
||||
return fetchOSMTile(z: z, x: x, y: y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user