Overview
ThesnapshotManager provides a simple API to create static map images with customizable:
- Map center or bounds
- Zoom level, pitch, and heading
- Style URL
- Image dimensions
- Output format (file or base64)
Basic Usage
Snapshot Options
Using Center Coordinate
Create a snapshot centered on a specific location:Using Bounds
Create a snapshot that fits specific geographic bounds:When using
bounds, the zoomLevel, pitch, and heading parameters are ignored. The map automatically calculates the optimal zoom to fit the bounds.Snapshot Options Reference
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
centerCoordinate | [lng, lat] | Yes* | - | Center point of the snapshot |
bounds | [[lng, lat], [lng, lat]] | Yes* | - | Southwest and northeast corners |
width | number | Yes | 50 | Image width in pixels |
height | number | Yes | 50 | Image height in pixels |
styleURL | string | No | StyleURL.Street | Map style URL |
zoomLevel | number | No | 16 | Zoom level (0-22) |
pitch | number | No | 0 | Camera pitch in degrees (0-60) |
heading | number | No | 0 | Camera heading in degrees (0-360) |
writeToDisk | boolean | No | false | Write to temporary file (returns file URI) |
withLogo | boolean | No | true | Include Mapbox logo (Android only) |
centerCoordinate or bounds must be provided.
Output Formats
Base64 String
By default, snapshots return a base64-encoded PNG:File URI
Write to a temporary file for better performance with large images:Use
writeToDisk: true for larger images to avoid memory issues with base64 encoding.Practical Examples
Map Thumbnail Generator
Multiple Style Comparisons
3D Perspective Snapshot
Create dramatic snapshots with pitch and heading:Share Map Location
Complete Example
Platform Differences
Android-Specific
Control Mapbox logo visibility:iOS-Specific
On iOS, the logo is always included and cannot be removed via the API.Performance Tips
- Use
writeToDisk: truefor images larger than 500x500 pixels - Generate snapshots in the background to avoid blocking the UI
- Cache generated snapshots to avoid regenerating the same image
- Consider image dimensions - larger sizes take longer to generate
- Use lower zoom levels for faster generation
Error Handling
Best Practices
- Always provide either
centerCoordinateorbounds - Set reasonable image dimensions based on your use case
- Use
writeToDiskfor images you’ll display multiple times - Handle errors gracefully with try-catch
- Consider generating thumbnails asynchronously
- Test with different styles to find what works best
Reference
- Snapshot Manager:
src/modules/snapshot/snapshotManager.ts:1 - Snapshot Options:
src/modules/snapshot/SnapshotOptions.ts:1