diff --git a/lib/services/map_data_provider.dart b/lib/services/map_data_provider.dart index 8f76a91..6a7f620 100644 --- a/lib/services/map_data_provider.dart +++ b/lib/services/map_data_provider.dart @@ -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."); } } diff --git a/lib/services/offline_areas/offline_area_downloader.dart b/lib/services/offline_areas/offline_area_downloader.dart index 0480358..42d7f30 100644 --- a/lib/services/offline_areas/offline_area_downloader.dart +++ b/lib/services/offline_areas/offline_area_downloader.dart @@ -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 diff --git a/lib/services/simple_tile_service.dart b/lib/services/simple_tile_service.dart index d297046..5774abe 100644 --- a/lib/services/simple_tile_service.dart +++ b/lib/services/simple_tile_service.dart @@ -48,11 +48,18 @@ class SimpleTileHttpClient extends http.BaseClient { } Future _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 diff --git a/lib/widgets/map_view.dart b/lib/widgets/map_view.dart index a852d3e..8616831 100644 --- a/lib/widgets/map_view.dart +++ b/lib/widgets/map_view.dart @@ -213,6 +213,8 @@ class MapViewState extends State { _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