@goongmaps/goong-map-react-native
Version:
A Goong GL react native module for creating custom maps
69 lines (63 loc) • 2.12 kB
JavaScript
import {NativeModules} from 'react-native';
import SnapshotOptions from './SnapshotOptions';
const GoongSDKSnapshotManger = NativeModules.MGLSnapshotModule;
/**
* The snapshotManager generates static raster images of the map.
* Each snapshot image depicts a portion of a map defined by an SnapshotOptions object you provide.
* The snapshotter generates the snapshot asynchronous.
*/
class SnapshotManager {
/**
* Takes a snapshot of the base map using the provided Snapshot options. NOTE pitch, heading, zoomLevel only works when centerCoordinate is set!
*
* @example
*
* // creates a temp file png of base map
* const uri = await GoongSDK.snapshotManager.takeSnap({
* centerCoordinate: [-74.126410, 40.797968],
* width: width,
* height: height,
* zoomLevel: 12,
* pitch: 30,
* heading: 20,
* styleURL: GoongSDK.StyleURL.Dark,
* writeToDisk: true, // Create a temporary file
* });
*
* // creates base64 png of base map without logo
* const uri = await GoongSDK.snapshotManager.takeSnap({
* centerCoordinate: [-74.126410, 40.797968],
* width: width,
* height: height,
* zoomLevel: 12,
* pitch: 30,
* heading: 20,
* styleURL: GoongSDK.StyleURL.Dark,
* withLogo: false, // Disable Mapbox logo (Android only)
* });
*
* // creates snapshot with bounds
* const uri = await GoongSDK.snapshotManager.takeSnap({
* bounds: [[-74.126410, 40.797968], [-74.143727, 40.772177]],
* width: width,
* height: height,
* styleURL: GoongSDK.StyleURL.Dark,
* });
*
* @param {SnapshotOptions} options Snapshot options for create a static image of the base map
* @return {Promise}
*/
takeSnap(options = {}) {
const snapshotOptions = new SnapshotOptions(options);
return new Promise(async (resolve, reject) => {
try {
const uri = await GoongSDKSnapshotManger.takeSnap(snapshotOptions);
resolve(uri);
} catch (e) {
reject(e);
}
});
}
}
const snapshotManager = new SnapshotManager();
export default snapshotManager;