-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
276 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:developer' show log; | ||
|
||
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; | ||
|
||
import './map_utils.dart'; | ||
|
||
class OfflineMapMetadata { | ||
static const String downloadTime = "download-time"; | ||
|
||
static DateTime? parseMetadata(Map<String, Object> metadata) { | ||
try { | ||
final downloadTime = metadata[OfflineMapMetadata.downloadTime] as int; | ||
return DateTime.fromMillisecondsSinceEpoch(downloadTime); | ||
} catch (e) { | ||
log('failed to parse metadata: $e'); | ||
} | ||
return null; | ||
} | ||
|
||
static Map<String, Object> createMetadata({required DateTime downloadTime}) { | ||
return {OfflineMapMetadata.downloadTime: downloadTime.millisecondsSinceEpoch}; | ||
} | ||
} | ||
|
||
Future<TileRegionLoadOptions> createRegionLoadOptions(MapboxMap mapboxMap) async { | ||
final (String styleURI, CoordinateBounds cameraBounds, CameraBounds bounds) = | ||
await (mapboxMap.style.getStyleURI(), mapboxMap.getCameraBounds(), mapboxMap.getBounds()).wait; | ||
return TileRegionLoadOptions( | ||
geometry: _coordinateBoundsToPolygon(cameraBounds).toJson(), | ||
descriptorsOptions: [TilesetDescriptorOptions(styleURI: styleURI, minZoom: 6, maxZoom: bounds.maxZoom.floor())], | ||
acceptExpired: true, | ||
metadata: OfflineMapMetadata.createMetadata(downloadTime: DateTime.now()), | ||
networkRestriction: NetworkRestriction.DISALLOW_EXPENSIVE); | ||
} | ||
|
||
Polygon _coordinateBoundsToPolygon(CoordinateBounds bounds) { | ||
return Polygon.fromPoints(points: [ | ||
[ | ||
bounds.southwest, | ||
Point(coordinates: Position.named(lng: bounds.southwest.coordinates.lng, lat: bounds.northeast.coordinates.lat)), | ||
bounds.northeast, | ||
Point(coordinates: Position.named(lng: bounds.northeast.coordinates.lng, lat: bounds.southwest.coordinates.lat)), | ||
] | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.