Skip to content
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 @@ -59,6 +59,10 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
installOfflineMapTiles(tilesDb);
result.success(null);
break;
case "mergeOfflineRegions":
OfflineManagerUtils.mergeRegions(result, context, methodCall.argument("path"));
break;

case "downloadOfflineRegion":
// Get download region arguments from caller
OfflineRegionData regionData = new Gson().fromJson(methodCall.argument("region").toString(), OfflineRegionData.class);
Expand Down
19 changes: 19 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/OfflineManagerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@
abstract class OfflineManagerUtils {
private static final String TAG = "OfflineManagerUtils";

static void mergeRegions(MethodChannel.Result result, Context context, String path) {
OfflineManager.getInstance(context).mergeOfflineRegions(path, new OfflineManager.MergeOfflineRegionsCallback() {
public void onMerge(OfflineRegion[] offlineRegions) {
if (result == null) return;
List<OfflineRegionData> regionsArgs = new ArrayList<>();
for (OfflineRegion offlineRegion : offlineRegions) {
regionsArgs.add(OfflineRegionData.fromOfflineRegion(offlineRegion));
}
String json = new Gson().toJson(regionsArgs);
result.success(json);
}

public void onError(String error) {
if (result == null) return;
result.error("mergeOfflineRegions Error", error, null);
}
});
}

static void downloadRegion(
MethodChannel.Result result,
Context context,
Expand Down
15 changes: 15 additions & 0 deletions lib/src/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Future<void> installOfflineMapTiles(String tilesDb) async {
);
}

Future<List<OfflineRegion>> mergeOfflineRegions(
String path, {
String accessToken,
}) async {
String regionsJson = await _globalChannel.invokeMethod(
'mergeOfflineRegions',
<String, dynamic>{
'path': path,
'accessToken': accessToken,
},
);
Iterable regions = json.decode(regionsJson);
return regions.map((region) => OfflineRegion.fromJson(region)).toList();
}

Future<List<OfflineRegion>> getListOfRegions({String accessToken}) async {
String regionsJson = await _globalChannel.invokeMethod(
'getListOfRegions',
Expand Down