mappls-map-react-native
Version:
A Mappls GL react native module for creating custom maps
54 lines (44 loc) • 1.47 kB
text/typescript
import { NativeModules } from "react-native";
import NativeRCTMGLOfflineModule from "../../../specs/NativeRCTMGLOfflineModule";
import type { OfflineCreatePackOptions } from "./OfflineCreatePackOptions";
const MapplsGLOfflineManager = NativeRCTMGLOfflineModule == null ? Object.create(NativeModules.MGLOfflineModule): NativeRCTMGLOfflineModule;
export type OfflinePackStatus = {
name: string;
state: number;
percentage: number;
completedResourceCount: number;
completedResourceSize: number;
completedTileCount: number;
completedTileSize: number;
requiredResourceCount: number;
};
export class OfflinePack {
private pack: OfflineCreatePackOptions;
private _metadata: Record<string, any> | null;
constructor(pack: OfflineCreatePackOptions) {
this.pack = pack;
this._metadata = null;
}
get name(): string | null {
const { metadata } = this;
return metadata && metadata.name;
}
get bounds(): string {
return this.pack.bounds;
}
get metadata(): Record<string, any> | null {
if (!this._metadata && this.pack.metadata) {
this._metadata = JSON.parse(this.pack.metadata);
}
return this._metadata;
}
status(): Promise<OfflinePackStatus> {
return MapplsGLOfflineManager.getPackStatus(this.name);
}
resume(): Promise<void> {
return MapplsGLOfflineManager.resumePackDownload(this.name);
}
pause(): Promise<void> {
return MapplsGLOfflineManager.pausePackDownload(this.name);
}
}