From 63a61cd4133b05b1ed4ea5f871eb05675707bcca Mon Sep 17 00:00:00 2001 From: danieljosua Date: Thu, 12 Sep 2024 09:50:23 +0200 Subject: [PATCH 1/4] Implementation of clearAmbientCache functionality --- .../maplibregl/MapLibreMapController.java | 18 ++++++++++++++++++ .../maplibre_gl/MapLibreMapController.swift | 9 +++++++++ maplibre_gl/lib/src/controller.dart | 4 ++++ .../src/maplibre_gl_platform_interface.dart | 2 ++ .../lib/src/method_channel_maplibre_gl.dart | 10 ++++++++++ 5 files changed, 43 insertions(+) diff --git a/maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java b/maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java index 724c39c1..33568ebb 100644 --- a/maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java +++ b/maplibre_gl/android/src/main/java/org/maplibre/maplibregl/MapLibreMapController.java @@ -934,6 +934,24 @@ public void onError(@NonNull String message) { }); break; } + case "map#clearAmbientCache": + { + OfflineManager fileSource = OfflineManager.Companion.getInstance(context); + + fileSource.clearAmbientCache( + new OfflineManager.FileSourceCallback() { + @Override + public void onSuccess() { + result.success(null); + } + + @Override + public void onError(@NonNull String message) { + result.error("MAPBOX CACHE ERROR", message, null); + } + }); + break; + } case "source#addGeoJson": { final String sourceId = call.argument("sourceId"); diff --git a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift index f525566e..2a1c16dd 100644 --- a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift +++ b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift @@ -158,6 +158,15 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate, result(nil) } } + case "map#clearAmbientCache": + MLNOfflineStorage.shared.clearAmbientCache { + error in + if let error = error { + result(error) + } else { + result(nil) + } + } case "map#updateMyLocationTrackingMode": guard let arguments = methodCall.arguments as? [String: Any] else { return } if let myLocationTrackingMode = arguments["mode"] as? UInt, diff --git a/maplibre_gl/lib/src/controller.dart b/maplibre_gl/lib/src/controller.dart index 71a5e827..35ce31d5 100644 --- a/maplibre_gl/lib/src/controller.dart +++ b/maplibre_gl/lib/src/controller.dart @@ -1111,6 +1111,10 @@ class MapLibreMapController extends ChangeNotifier { return _maplibrePlatform.invalidateAmbientCache(); } + Future clearAmbientCache() async { + return _maplibrePlatform.clearAmbientCache(); + } + /// Get last my location /// /// Return last latlng, nullable diff --git a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart index 9f6bb1a8..ed1205db 100644 --- a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart +++ b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart @@ -74,6 +74,8 @@ abstract class MapLibrePlatform { Future querySourceFeatures( String sourceId, String? sourceLayerId, List? filter); Future invalidateAmbientCache(); + + Future clearAmbientCache(); Future requestMyLocationLatLng(); Future getVisibleRegion(); diff --git a/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart b/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart index d2b4cccc..78d86412 100644 --- a/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart +++ b/maplibre_gl_platform_interface/lib/src/method_channel_maplibre_gl.dart @@ -321,6 +321,16 @@ class MapLibreMethodChannel extends MapLibrePlatform { } } + @override + Future clearAmbientCache() async { + try { + await _channel.invokeMethod('map#clearAmbientCache'); + return null; + } on PlatformException catch (e) { + return Future.error(e); + } + } + @override Future requestMyLocationLatLng() async { try { From 3561ace8e90597879cbefd9728ec484b5fe5e831 Mon Sep 17 00:00:00 2001 From: danieljosua Date: Fri, 13 Sep 2024 08:44:46 +0200 Subject: [PATCH 2/4] Implementation of clearAmbientCache functionality --- maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart b/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart index 426f89f5..a6ad2b7e 100644 --- a/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart +++ b/maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart @@ -355,6 +355,11 @@ class MapLibreMapController extends MapLibrePlatform print('Offline storage not available in web'); } + @override + Future clearAmbientCache() async { + print('Offline storage not available in web'); + } + @override Future requestMyLocationLatLng() async { return _myLastLocation; From 3e3f03e413db6a59ae745212429529aa468cfa6c Mon Sep 17 00:00:00 2001 From: danieljosua Date: Tue, 8 Oct 2024 13:09:41 +0200 Subject: [PATCH 3/4] -Removed empty line in maplibre_gl_platform_interface.dart -Fixed Indentation --- .../maplibre_gl/MapLibreMapController.swift | 16 ++++++++-------- .../lib/src/maplibre_gl_platform_interface.dart | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift index 2a1c16dd..33ee693f 100644 --- a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift +++ b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift @@ -159,14 +159,14 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate, } } case "map#clearAmbientCache": - MLNOfflineStorage.shared.clearAmbientCache { - error in - if let error = error { - result(error) - } else { - result(nil) - } - } + MLNOfflineStorage.shared.clearAmbientCache { + error in + if let error = error { + result(error) + } else { + result(nil) + } + } case "map#updateMyLocationTrackingMode": guard let arguments = methodCall.arguments as? [String: Any] else { return } if let myLocationTrackingMode = arguments["mode"] as? UInt, diff --git a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart index ed1205db..d748807c 100644 --- a/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart +++ b/maplibre_gl_platform_interface/lib/src/maplibre_gl_platform_interface.dart @@ -74,7 +74,6 @@ abstract class MapLibrePlatform { Future querySourceFeatures( String sourceId, String? sourceLayerId, List? filter); Future invalidateAmbientCache(); - Future clearAmbientCache(); Future requestMyLocationLatLng(); From 8f6bb8d7f0cd8c0cca5724c7ed30b5f8535e0f69 Mon Sep 17 00:00:00 2001 From: danieljosua Date: Tue, 8 Oct 2024 13:15:12 +0200 Subject: [PATCH 4/4] -Fixed Indentation --- .../Sources/maplibre_gl/MapLibreMapController.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift index 33ee693f..04718664 100644 --- a/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift +++ b/maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/MapLibreMapController.swift @@ -160,12 +160,12 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate, } case "map#clearAmbientCache": MLNOfflineStorage.shared.clearAmbientCache { - error in - if let error = error { - result(error) - } else { - result(nil) - } + error in + if let error = error { + result(error) + } else { + result(nil) + } } case "map#updateMyLocationTrackingMode": guard let arguments = methodCall.arguments as? [String: Any] else { return }