From 9e37543112ec185ad5e7102e2b3c293b7a39950a Mon Sep 17 00:00:00 2001 From: PaulPickhardt Date: Tue, 2 Jan 2024 15:54:09 +0100 Subject: [PATCH] fix cache background images and remove url with access token in ligs --- lib/common/map/image_cache.dart | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/common/map/image_cache.dart b/lib/common/map/image_cache.dart index c4f6cc7b5..6b94ff0ed 100644 --- a/lib/common/map/image_cache.dart +++ b/lib/common/map/image_cache.dart @@ -83,25 +83,25 @@ class MapboxTileImageCache { // the background image that should be cached and displayed in the all rides view. final cacheUrl = - "https://api.mapbox.com/styles/v1/$styleId/static/$bboxStr/${(1000 * widthRatio).toInt()}x${(1000 * heightRatio).toInt()}/?attribution=false&logo=false&$accessToken"; - final endpoint = Uri.parse(cacheUrl); + "https://api.mapbox.com/styles/v1/$styleId/static/$bboxStr/1000x1000/?attribution=false&logo=false&$accessToken"; - // Only run if ratios differ. Otherwise we would make the same request. - if (heightRatio != 1 && widthRatio != 1) { - final cacheResponse = await Http.get(endpoint).timeout(const Duration(seconds: 4)); - if (cacheResponse.statusCode != 200) { - final err = "Error while fetching background image status from Mapbox: ${cacheResponse.statusCode}"; - throw Exception(err); - } + // Use Cache url when height or width ratio is given. + final endpoint = Uri.parse(heightRatio != 1 || widthRatio != 1 ? cacheUrl : feedbackUrl); - final cachedImage = MemoryImage(cacheResponse.bodyBytes); - log.i("Fetched background image from Mapbox: $cacheUrl"); - await saveImage(bbox, cachedImage, brightness, styleUri); + // Only run if ratios differ. Otherwise we would make the same request. + final cacheResponse = await Http.get(endpoint).timeout(const Duration(seconds: 4)); + if (cacheResponse.statusCode != 200) { + final err = "Error while fetching background image status from Mapbox: ${cacheResponse.statusCode}"; + throw Exception(err); } + final cachedImage = MemoryImage(cacheResponse.bodyBytes); + log.i("Fetched background image from Mapbox"); + await saveImage(bbox, cachedImage, brightness, styleUri); + final MemoryImage feedbackImage = MemoryImage(feedbackResponse.bodyBytes); - log.i("Fetched background image from Mapbox: $feedbackUrl"); + log.i("Fetched background image from Mapbox"); // save timestamp of last fetch to shared preferences, used in pruning of old images final prefs = await SharedPreferences.getInstance();