Skip to content

Commit 5a3daa2

Browse files
authored
Implementation of clearAmbientCache functionality (#502)
1 parent b077b95 commit 5a3daa2

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-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
@@ -934,6 +934,24 @@ public void onError(@NonNull String message) {
934934
});
935935
break;
936936
}
937+
case "map#clearAmbientCache":
938+
{
939+
OfflineManager fileSource = OfflineManager.Companion.getInstance(context);
940+
941+
fileSource.clearAmbientCache(
942+
new OfflineManager.FileSourceCallback() {
943+
@Override
944+
public void onSuccess() {
945+
result.success(null);
946+
}
947+
948+
@Override
949+
public void onError(@NonNull String message) {
950+
result.error("MAPBOX CACHE ERROR", message, null);
951+
}
952+
});
953+
break;
954+
}
937955
case "source#addGeoJson":
938956
{
939957
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
@@ -1111,6 +1111,10 @@ class MapLibreMapController extends ChangeNotifier {
11111111
return _maplibrePlatform.invalidateAmbientCache();
11121112
}
11131113

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

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
@@ -321,6 +321,16 @@ class MapLibreMethodChannel extends MapLibrePlatform {
321321
}
322322
}
323323

324+
@override
325+
Future clearAmbientCache() async {
326+
try {
327+
await _channel.invokeMethod('map#clearAmbientCache');
328+
return null;
329+
} on PlatformException catch (e) {
330+
return Future.error(e);
331+
}
332+
}
333+
324334
@override
325335
Future<LatLng> requestMyLocationLatLng() async {
326336
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)