Skip to content

Commit 85dc288

Browse files
committed
2 parents cfaa72e + 2e9af8b commit 85dc288

File tree

7 files changed

+67
-0
lines changed

7 files changed

+67
-0
lines changed

maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,24 @@ public void onError(@NonNull String message) {
935935
});
936936
break;
937937
}
938+
case "map#clearAmbientCache":
939+
{
940+
OfflineManager fileSource = OfflineManager.Companion.getInstance(context);
941+
942+
fileSource.clearAmbientCache(
943+
new OfflineManager.FileSourceCallback() {
944+
@Override
945+
public void onSuccess() {
946+
result.success(null);
947+
}
948+
949+
@Override
950+
public void onError(@NonNull String message) {
951+
result.error("MAPBOX CACHE ERROR", message, null);
952+
}
953+
});
954+
break;
955+
}
938956
case "source#addGeoJson":
939957
{
940958
final String sourceId = call.argument("sourceId");

maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
158158
result(nil)
159159
}
160160
}
161+
case "map#clearAmbientCache":
162+
MLNOfflineStorage.shared.clearAmbientCache {
163+
error in
164+
if let error = error {
165+
result(error)
166+
} else {
167+
result(nil)
168+
}
169+
}
161170
case "map#updateMyLocationTrackingMode":
162171
guard let arguments = methodCall.arguments as? [String: Any] else { return }
163172
if let myLocationTrackingMode = arguments["mode"] as? UInt,

maplibre_gl/lib/src/controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ class MapLibreMapController extends ChangeNotifier {
11121112
return _maplibrePlatform.invalidateAmbientCache();
11131113
}
11141114

1115+
Future clearAmbientCache() async {
1116+
return _maplibrePlatform.clearAmbientCache();
1117+
}
1118+
11151119
/// Get last my location
11161120
///
11171121
/// Return last latlng, nullable

maplibre_gl_platform_interface/lib/src/location.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ class LatLngBounds {
8484
return <dynamic>[southwest.toJson(), northeast.toJson()];
8585
}
8686

87+
/// Determines whether a given geographical point (`LatLng`) is within the
88+
/// bounds defined by two other geographical points: `southwest` (lower-left corner)
89+
/// and `northeast` (upper-right corner).
90+
///
91+
bool contains(LatLng point) {
92+
final isLatitudeInBounds = point.latitude >= southwest.latitude &&
93+
point.latitude <= northeast.latitude;
94+
95+
final bool isLongitudeInBounds;
96+
97+
if (southwest.longitude <= northeast.longitude) {
98+
isLongitudeInBounds = point.longitude >= southwest.longitude &&
99+
point.longitude <= northeast.longitude;
100+
} else {
101+
isLongitudeInBounds = point.longitude >= southwest.longitude ||
102+
point.longitude <= northeast.longitude;
103+
}
104+
return isLatitudeInBounds && isLongitudeInBounds;
105+
}
106+
87107
@visibleForTesting
88108
static LatLngBounds? fromList(dynamic json) {
89109
if (json == null) {

maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ abstract class MapLibrePlatform {
7474
Future<List> querySourceFeatures(
7575
String sourceId, String? sourceLayerId, List<Object>? filter);
7676
Future invalidateAmbientCache();
77+
Future clearAmbientCache();
7778
Future<LatLng?> requestMyLocationLatLng();
7879

7980
Future<LatLngBounds> getVisibleRegion();

maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ class MapLibreMethodChannel extends MapLibrePlatform {
323323
}
324324
}
325325

326+
@override
327+
Future clearAmbientCache() async {
328+
try {
329+
await _channel.invokeMethod('map#clearAmbientCache');
330+
return null;
331+
} on PlatformException catch (e) {
332+
return Future.error(e);
333+
}
334+
}
335+
326336
@override
327337
Future<LatLng> requestMyLocationLatLng() async {
328338
try {

maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ class MapLibreMapController extends MapLibrePlatform
355355
print('Offline storage not available in web');
356356
}
357357

358+
@override
359+
Future clearAmbientCache() async {
360+
print('Offline storage not available in web');
361+
}
362+
358363
@override
359364
Future<LatLng?> requestMyLocationLatLng() async {
360365
return _myLastLocation;

0 commit comments

Comments
 (0)