chasing excess tile fetching and lack of correct cache clearing - NOT WORKING

This commit is contained in:
stopflock
2025-08-23 12:27:04 -05:00
parent f6adffc84e
commit a2bc3309c0
4 changed files with 86 additions and 20 deletions
+10 -6
View File
@@ -15,6 +15,7 @@ import 'camera_provider_with_cache.dart';
import 'map/camera_markers.dart';
import 'map/direction_cones.dart';
import 'map/map_overlays.dart';
import 'network_status_indicator.dart';
import '../dev_config.dart';
class MapView extends StatefulWidget {
@@ -95,6 +96,7 @@ class _MapViewState extends State<MapView> {
void _onTilesCached() {
// When new tiles are cached, just trigger a widget rebuild
// This should cause the TileLayer to re-render with cached tiles
debugPrint('[MapView] Tile cached callback triggered, calling setState');
if (mounted) {
setState(() {});
}
@@ -176,12 +178,6 @@ class _MapViewState extends State<MapView> {
return ids1.length == ids2.length && ids1.containsAll(ids2);
}
@override
Widget build(BuildContext context) {
final appState = context.watch<AppState>();
@@ -270,6 +266,11 @@ class _MapViewState extends State<MapView> {
if (session != null) {
appState.updateSession(target: pos.center);
}
// Simple approach: cancel tiles on ANY significant view change
final tileProvider = Provider.of<TileProviderWithCache>(context, listen: false);
tileProvider.cancelAllTileRequests();
// Request more cameras on any map movement/zoom at valid zoom level
// This ensures cameras load even when zooming without panning (like with zoom buttons)
if (pos.zoom >= 10) {
@@ -323,6 +324,9 @@ class _MapViewState extends State<MapView> {
uploadMode: appState.uploadMode,
session: session,
),
// Network status indicator (top-left)
const NetworkStatusIndicator(),
],
);
}
+15 -3
View File
@@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import '../services/map_data_provider.dart';
import '../services/map_data_submodules/tiles_from_osm.dart';
/// In-memory tile cache and async provider for custom tiles.
class TileProviderWithCache extends TileProvider with ChangeNotifier {
@@ -11,7 +12,7 @@ class TileProviderWithCache extends TileProvider with ChangeNotifier {
bool _disposed = false;
int _disposeCount = 0;
VoidCallback? _onTilesCachedCallback;
TileProviderWithCache();
/// Set a callback to be called when tiles are cached (used by MapView for refresh)
@@ -19,6 +20,12 @@ class TileProviderWithCache extends TileProvider with ChangeNotifier {
_onTilesCachedCallback = callback;
}
/// Cancel ALL pending tile requests - delegates to OSM tile fetcher
void cancelAllTileRequests() {
clearOSMTileQueue(); // This handles all the cancellation logic
debugPrint('[TileProviderWithCache] Cancelled all tile requests');
}
@override
void dispose() {
_disposeCount++;
@@ -73,12 +80,17 @@ class TileProviderWithCache extends TileProvider with ChangeNotifier {
if (!_disposed && hasListeners) {
notifyListeners(); // This updates any listening widgets
}
// Trigger map refresh callback to force tile re-rendering
// Trigger map refresh callback to force tile re-rendering
debugPrint('[TileProviderWithCache] Tile cached: $key, calling refresh callback');
_onTilesCachedCallback?.call();
}
// If bytes were empty, don't cache (will re-attempt next time)
} catch (e) {
// Do NOT cache a failed or empty tile! Placeholder tiles will be evicted on online transition.
// Cancelled requests will throw exceptions from fetchOSMTile(), just ignore them
if (e.toString().contains('cancelled')) {
debugPrint('[TileProviderWithCache] Tile request was cancelled: $key');
}
// Don't cache failed tiles regardless of reason
}
}
}