Area size estimates based on preview tile size if available

This commit is contained in:
stopflock
2025-09-29 21:43:55 -05:00
parent caa20140b4
commit 2d29c93145
2 changed files with 19 additions and 4 deletions

View File

@@ -3,8 +3,8 @@ import 'package:flutter/material.dart';
/// Developer/build-time configuration for global/non-user-tunable constants.
// Example: Default tile storage estimate (KB per tile), for size estimates
const double kTileEstimateKb = 25.0;
// Fallback tile storage estimate (KB per tile), used when no preview tile data is available
const double kFallbackTileEstimateKb = 25.0;
// Direction cone for map view
const double kDirectionConeHalfAngle = 30.0; // degrees

View File

@@ -62,7 +62,8 @@ class _DownloadAreaDialogState extends State<DownloadAreaDialog> {
final maxPossibleZoom = _calculateMaxZoomForTileLimit(bounds, minZoom);
final nTiles = computeTileList(bounds, minZoom, maxZoom).length;
final totalMb = (nTiles * kTileEstimateKb) / 1024.0;
final tileEstimateKb = _getTileEstimateKb();
final totalMb = (nTiles * tileEstimateKb) / 1024.0;
final roundedMb = (totalMb * 10).round() / 10; // Round to nearest tenth
setState(() {
@@ -84,8 +85,22 @@ class _DownloadAreaDialogState extends State<DownloadAreaDialog> {
}
return kAbsoluteMaxZoom;
}
/// Get tile size estimate in KB, using preview tile data if available, otherwise fallback to constant
double _getTileEstimateKb() {
final appState = context.read<AppState>();
final selectedTileType = appState.selectedTileType;
if (selectedTileType?.previewTile != null) {
// Use actual preview tile size
final previewSizeBytes = selectedTileType!.previewTile!.length;
final previewSizeKb = previewSizeBytes / 1024.0;
return previewSizeKb;
} else {
// Fall back to configured estimate
return kFallbackTileEstimateKb;
}
}
@override
Widget build(BuildContext context) {