From 7f33567632adc4661b38d11d8b08185ba786dd93 Mon Sep 17 00:00:00 2001 From: Anton Martynenko Date: Wed, 19 Nov 2025 12:17:27 +0100 Subject: [PATCH] change how tiles are stored --- .../Configs/StorageConfig.cs | 14 +++++++++++++ .../GoogleMapsDownloaderV2.cs | 20 +++++++++---------- goal.md | 8 ++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/SatelliteProvider.Common/Configs/StorageConfig.cs b/SatelliteProvider.Common/Configs/StorageConfig.cs index bac4ad4..eb3b9ca 100644 --- a/SatelliteProvider.Common/Configs/StorageConfig.cs +++ b/SatelliteProvider.Common/Configs/StorageConfig.cs @@ -4,5 +4,19 @@ public class StorageConfig { public string TilesDirectory { get; set; } = "/tiles"; public string ReadyDirectory { get; set; } = "/ready"; + + public string GetTileSubdirectoryPath(int zoomLevel, int tileX, int tileY) + { + var xBucket = tileX / 1000; + var yBucket = tileY / 1000; + return Path.Combine(TilesDirectory, zoomLevel.ToString(), xBucket.ToString(), yBucket.ToString()); + } + + public string GetTileFilePath(int zoomLevel, int tileX, int tileY, string timestamp) + { + var subdirectory = GetTileSubdirectoryPath(zoomLevel, tileX, tileY); + var fileName = $"tile_{zoomLevel}_{tileX}_{tileY}_{timestamp}.jpg"; + return Path.Combine(subdirectory, fileName); + } } diff --git a/SatelliteProvider.Services/GoogleMapsDownloaderV2.cs b/SatelliteProvider.Services/GoogleMapsDownloaderV2.cs index 34d02ee..523c958 100644 --- a/SatelliteProvider.Services/GoogleMapsDownloaderV2.cs +++ b/SatelliteProvider.Services/GoogleMapsDownloaderV2.cs @@ -27,7 +27,7 @@ public class GoogleMapsDownloaderV2 private readonly ILogger _logger; private readonly string _apiKey; - private readonly string _tilesDirectory; + private readonly StorageConfig _storageConfig; private readonly IHttpClientFactory _httpClientFactory; public GoogleMapsDownloaderV2( @@ -38,7 +38,7 @@ public class GoogleMapsDownloaderV2 { _logger = logger; _apiKey = mapConfig.Value.ApiKey; - _tilesDirectory = storageConfig.Value.TilesDirectory; + _storageConfig = storageConfig.Value; _httpClientFactory = httpClientFactory; } @@ -98,11 +98,11 @@ public class GoogleMapsDownloaderV2 var server = 0; var url = string.Format(TILE_URL_TEMPLATE, server, tileX, tileY, zoomLevel, sessionToken); - Directory.CreateDirectory(_tilesDirectory); - var timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); - var fileName = $"tile_{zoomLevel}_{tileX}_{tileY}_{timestamp}.jpg"; - var filePath = Path.Combine(_tilesDirectory, fileName); + var subdirectory = _storageConfig.GetTileSubdirectoryPath(zoomLevel, tileX, tileY); + Directory.CreateDirectory(subdirectory); + + var filePath = _storageConfig.GetTileFilePath(zoomLevel, tileX, tileY, timestamp); var imageBytes = await ExecuteWithRetryAsync(async () => { @@ -278,11 +278,11 @@ public class GoogleMapsDownloaderV2 var server = (x + y) % 4; var url = string.Format(TILE_URL_TEMPLATE, server, x, y, zoomLevel, sessionToken); - Directory.CreateDirectory(_tilesDirectory); - var timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); - var fileName = $"tile_{zoomLevel}_{x}_{y}_{timestamp}.jpg"; - var filePath = Path.Combine(_tilesDirectory, fileName); + var subdirectory = _storageConfig.GetTileSubdirectoryPath(zoomLevel, x, y); + Directory.CreateDirectory(subdirectory); + + var filePath = _storageConfig.GetTileFilePath(zoomLevel, x, y, timestamp); var imageBytes = await ExecuteWithRetryAsync(async () => { diff --git a/goal.md b/goal.md index 5d1137a..ff45125 100644 --- a/goal.md +++ b/goal.md @@ -1,3 +1,11 @@ +# TODO +- add geo fences (2 regions) +- add parameter to zip resulting tiles, 50 mb max +- implement api to download tile - lat, lon and zoom level +- implement parallel tiles fetching from google maps + + + # High level description We need to implement a service which will have the following high level functionality: