Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Offline][iOS][Android] Add option to set maximum offline tile count #549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
OfflineManagerUtils.mergeRegions(result, context, methodCall.argument("path"));
break;

case "setOfflineTileCountLimit":
OfflineManagerUtils.setOfflineTileCountLimit(result, context, methodCall.<Number>argument("limit").longValue());
break;

case "downloadOfflineRegion":
// Get download region arguments from caller
OfflineRegionData regionData = new Gson().fromJson(methodCall.argument("region").toString(), OfflineRegionData.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void onError(String error) {
});
}

static void setOfflineTileCountLimit(MethodChannel.Result result, Context context, long limit){
OfflineManager.getInstance(context).setOfflineMapboxTileCountLimit(limit);
result.success(null);
}

static void downloadRegion(
MethodChannel.Result result,
Context context,
Expand Down
8 changes: 7 additions & 1 deletion ios/Classes/OfflineManagerUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ class OfflineManagerUtils {
}
result(regionsArgsJsonString)
}


static func setOfflineTileCountLimit(result: @escaping FlutterResult, maximumCount: UInt64) {
let offlineStorage = MGLOfflineStorage.shared
offlineStorage.setMaximumAllowedMapboxTiles(maximumCount)
result(nil)
}

static func deleteRegion(result: @escaping FlutterResult, id: Int) {
let offlineStorage = MGLOfflineStorage.shared
guard let pacs = offlineStorage.packs else { return }
Expand Down
11 changes: 11 additions & 0 deletions ios/Classes/SwiftMapboxGlFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public class SwiftMapboxGlFlutterPlugin: NSObject, FlutterPlugin {
result: result,
registrar: registrar
)
case "setOfflineTileCountLimit":
guard let arguments = methodCall.arguments as? [String: Any],
let limit = arguments["limit"] as? UInt64 else {
result(FlutterError(
code: "SetOfflineTileCountLimitError",
message: "could not decode arguments",
details: nil
))
return
}
OfflineManagerUtils.setOfflineTileCountLimit(result: result, maximumCount: limit)
case "getListOfRegions":
// Note: this does not download anything from internet, it only fetches data drom database
OfflineManagerUtils.regionsList(result: result)
Expand Down
9 changes: 9 additions & 0 deletions lib/src/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ Future<OfflineRegion> updateOfflineRegionMetadata(
return OfflineRegion.fromJson(json.decode(regionJson));
}

Future<dynamic> setOfflineTileCountLimit(int limit, {String accessToken}) =>
_globalChannel.invokeMethod(
'setOfflineTileCountLimit',
<String, dynamic>{
'limit': limit,
'accessToken': accessToken,
},
);

Future<dynamic> deleteOfflineRegion(int id, {String accessToken}) =>
_globalChannel.invokeMethod(
'deleteOfflineRegion',
Expand Down