mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-07 05:07:54 +02:00
fix camera caching and filtering from offline areas - in theory
This commit is contained in:
@@ -136,11 +136,15 @@ class MapDataProvider {
|
||||
|
||||
// AUTO (default): try local first, then remote if not offline
|
||||
try {
|
||||
debugPrint('[MapDataProvider] Trying local tile $z/$x/$y (offline: $offline)');
|
||||
return await fetchLocalTile(z: z, x: x, y: y);
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('[MapDataProvider] Local tile $z/$x/$y failed: $e');
|
||||
if (!offline) {
|
||||
debugPrint('[MapDataProvider] Falling back to remote for $z/$x/$y');
|
||||
return _fetchRemoteTileFromCurrentProvider(z, x, y);
|
||||
} else {
|
||||
debugPrint('[MapDataProvider] Offline mode - no fallback for $z/$x/$y');
|
||||
throw OfflineModeException("Tile $z/$x/$y not found in offline areas and offline mode is enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,11 +149,11 @@ class OfflineAreaDownloader {
|
||||
final cameraBounds = _calculateCameraBounds(bounds, minZoom);
|
||||
final cameras = await MapDataProvider().getAllCamerasForDownload(
|
||||
bounds: cameraBounds,
|
||||
profiles: AppState.instance.enabledProfiles,
|
||||
profiles: AppState.instance.profiles, // Use ALL profiles, not just enabled ones
|
||||
);
|
||||
area.cameras = cameras;
|
||||
await OfflineAreaDownloader.saveCameras(cameras, directory);
|
||||
debugPrint('Area ${area.id}: Downloaded ${cameras.length} cameras from expanded bounds');
|
||||
debugPrint('Area ${area.id}: Downloaded ${cameras.length} cameras from expanded bounds (all profiles)');
|
||||
}
|
||||
|
||||
/// Calculate expanded bounds that cover the entire tile area at minimum zoom
|
||||
|
||||
@@ -48,11 +48,18 @@ class SimpleTileHttpClient extends http.BaseClient {
|
||||
}
|
||||
|
||||
Future<http.StreamedResponse> _handleTileRequest(int z, int x, int y) async {
|
||||
final startTime = DateTime.now();
|
||||
final isOffline = AppState.instance.offlineMode;
|
||||
debugPrint('[SimpleTileService] Requesting tile $z/$x/$y (offline: $isOffline)');
|
||||
|
||||
try {
|
||||
// Always go through MapDataProvider - it handles offline/online routing
|
||||
// MapDataProvider will get current provider from AppState
|
||||
final tileBytes = await _mapDataProvider.getTile(z: z, x: x, y: y, source: MapSource.auto);
|
||||
|
||||
final duration = DateTime.now().difference(startTime);
|
||||
debugPrint('[SimpleTileService] SUCCESS tile $z/$x/$y in ${duration.inMilliseconds}ms');
|
||||
|
||||
// Clear waiting status - we got data
|
||||
NetworkStatus.instance.clearWaiting();
|
||||
|
||||
@@ -69,7 +76,8 @@ class SimpleTileHttpClient extends http.BaseClient {
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
debugPrint('[SimpleTileService] Could not get tile $z/$x/$y: $e');
|
||||
final duration = DateTime.now().difference(startTime);
|
||||
debugPrint('[SimpleTileService] FAILED tile $z/$x/$y in ${duration.inMilliseconds}ms: $e');
|
||||
|
||||
// 404 means no tiles available - clear waiting status
|
||||
// This is true whether we're online or offline
|
||||
|
||||
@@ -213,6 +213,8 @@ class MapViewState extends State<MapView> {
|
||||
_lastEnabledProfiles = List.from(currentEnabledProfiles);
|
||||
// Refresh cameras when profiles change
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// Clear camera cache to ensure fresh data for new profile combination
|
||||
_cameraProvider.clearCache();
|
||||
// Force display refresh first (for immediate UI update)
|
||||
_cameraProvider.refreshDisplay();
|
||||
// Then fetch new cameras for newly enabled profiles
|
||||
|
||||
Reference in New Issue
Block a user