updateNewsFromCacheForBounds function

void updateNewsFromCacheForBounds({
  1. required MapController mapController,
  2. required GdeltNewsService newsService,
  3. required void setMarkers(
    1. List<NewsMarker>
    ),
  4. required Future<void> fetchForCurrentBounds(),
})

Updates news markers from cache when map position changes.

Implementation

void updateNewsFromCacheForBounds({
  required MapController mapController,
  required GdeltNewsService newsService,
  required void Function(List<NewsMarker>) setMarkers,
  required Future<void> Function() fetchForCurrentBounds,
}) {
  final bounds = mapController.camera.visibleBounds;
  final cached = newsService.getMarkersInBounds(bounds);

  // Always update visible markers from cache.

  if (cached.isNotEmpty) {
    setMarkers(cached);
  }

  // Only fetch new data if significantly outside cached bounds
  // This prevents unnecessary fetches during small movements.

  if (!newsService.isBoundsCovered(bounds)) {
    // Async fetch without blocking UI.
    fetchForCurrentBounds();
  }
}