Skip to main content

snapshotManager

The snapshotManager generates static raster images of the map. Each snapshot image depicts a portion of a map defined by a SnapshotOptions object. The snapshotter generates snapshots asynchronously.

Import

import { snapshotManager } from '@rnmapbox/maps';

Basic Usage

import { snapshotManager } from '@rnmapbox/maps';

const uri = await snapshotManager.takeSnap({
  centerCoordinate: [-74.126410, 40.797968],
  width: 300,
  height: 200,
  zoomLevel: 12,
  styleURL: 'mapbox://styles/mapbox/streets-v11',
});

console.log('Snapshot URI:', uri);

Methods

takeSnap()

takeSnap(options: SnapshotOptions): Promise<string>
Takes a snapshot of the base map using the provided snapshot options.
The pitch, heading, and zoomLevel options only work when centerCoordinate is set!
options
SnapshotOptions
required
Configuration for the snapshot.
options.centerCoordinate
[number, number]
The center coordinate of the snapshot [longitude, latitude]. Either centerCoordinate or bounds must be provided.
options.bounds
[[number, number], [number, number]]
Geographic bounds for the snapshot [[lng1, lat1], [lng2, lat2]]. Either centerCoordinate or bounds must be provided.
options.width
number
default:"50"
Width of the snapshot in points/pixels.
options.height
number
default:"50"
Height of the snapshot in points/pixels.
options.zoomLevel
number
default:"16"
Zoom level for the snapshot. Only works with centerCoordinate.
options.pitch
number
default:"0"
Camera pitch (tilt) in degrees. Only works with centerCoordinate.
options.heading
number
default:"0"
Camera heading (bearing) in degrees. Only works with centerCoordinate.
options.styleURL
string
default:"StyleURL.Street"
The style URL to use for the snapshot.
options.writeToDisk
boolean
default:"false"
If true, writes the snapshot to a temporary file and returns the file path. If false, returns a base64-encoded data URI.
Whether to include the Mapbox logo in the snapshot. Android only.
Returns: Promise that resolves to either:
  • File path (if writeToDisk: true)
  • Base64 data URI (if writeToDisk: false)

Examples

import { snapshotManager, StyleURL } from '@rnmapbox/maps';
import { Image } from 'react-native';

async function takeBasicSnapshot() {
  const uri = await snapshotManager.takeSnap({
    centerCoordinate: [-74.006, 40.7128],
    width: 300,
    height: 200,
    zoomLevel: 14,
    styleURL: StyleURL.Streets,
  });
  
  // Display the snapshot
  return <Image source={{ uri }} style={{ width: 300, height: 200 }} />;
}

Use Cases

Static Map Previews

Generate preview images for locations before showing the full interactive map:
const preview = await snapshotManager.takeSnap({
  centerCoordinate: location,
  width: 150,
  height: 150,
  zoomLevel: 13,
  writeToDisk: false,
});

Sharing Locations

Create shareable images of map locations:
const shareImage = await snapshotManager.takeSnap({
  centerCoordinate: [-74.006, 40.7128],
  width: 800,
  height: 600,
  zoomLevel: 14,
  pitch: 45,
  heading: 90,
  writeToDisk: true,
});

Thumbnails

Generate thumbnails for saved locations or routes:
const thumbnail = await snapshotManager.takeSnap({
  bounds: routeBounds,
  width: 200,
  height: 150,
  writeToDisk: false,
});

Performance Considerations

  • Larger snapshots (width × height) take longer to generate
  • Snapshots are generated asynchronously and don’t block the UI
  • Consider caching snapshots if you need to display them multiple times
  • Use writeToDisk: true for large images to avoid memory issues with base64
  • Base64 encoding increases the data size by ~33%

Platform Differences

iOS

  • Snapshots include the Mapbox logo by default
  • withLogo option has no effect

Android

  • The withLogo option can hide the Mapbox logo
  • Ensure you comply with Mapbox Terms of Service when hiding the logo
  • MapView - Interactive map component
  • Camera - Control camera position (similar parameters)

Build docs developers (and LLMs) love