The map can render a picture or a video of itself, offscreen and at any size. The map on screen stays interactive meanwhile.
A picture
let recorder = ImmersiveMapStillRecorder()
let image = try await recorder.capture(
settings: .default,
camera: ImmersiveMapCameraPosition(latitudeDegrees: 55.75, longitudeDegrees: 37.61, zoom: 14),
configuration: ImmersiveMapStillConfiguration(width: 1280, height: 720))
You get a CGImage. No map has to be on screen, so this suits thumbnails and share images.
A platform’s size is a preset: ImmersiveMapStillConfiguration(format: .threadsPost) renders 1080 × 1350.
- Settings. Pass the same
ImmersiveMapSettingsas your map, with your tile source and style, to get the same look. - Content. Pins and 3D models are passed as values, with
pins:andsceneModels:. Layers are passed as their controller, withlayers:, and are drawn as they are when the capture starts. The capture waits for their data to be read and prepared. SwiftUI annotations can’t be drawn into a picture. - Scale.
pixelsPerPointis the screen scale the picture is drawn for, 2 by default: at 2, a 1280 pixel picture has its labels sized for a 640 point wide view. - Waiting. The capture waits for the tiles it needs, up to
settleTimeout(10 seconds by default), so the picture is complete. - Repeatability. Set
sceneDateto get the same sun and the same picture on every run.
A video
Record a camera tour, the same shots as a tour on screen (see Camera), into a QuickTime file:
@State private var recorder = ImmersiveMapTourVideoRecorder()
ImmersiveMapView()
.tourVideoRecorder(recorder)
// Later:
try await recorder.export(
shots: [
ImmersiveMapCameraTourShot(position: start),
ImmersiveMapCameraTourShot(position: end, options: CameraFlightOptions(duration: 6)),
],
configuration: ImmersiveMapVideoExportConfiguration(width: 1920, height: 1080, framesPerSecond: 60),
to: outputURL)
The recorder takes the map’s current look when the export starts. It renders frame by frame, waiting for each frame’s tiles, so the video never shows a missing tile, whatever the network does.
- The first frame. The video starts from where the map’s camera is when the export begins, and flies to the first shot from there. Pass
establish:to start from a position of your own, so the video opens the same way on every run:try await recorder.export(shots: shots, establish: overview, to: outputURL) - Size. A platform’s size is a preset:
ImmersiveMapVideoExportConfiguration(format: .instagramReels)records 1080 × 1920. A video’s sides are even, so an odd side of a preset is one pixel smaller. - Format. HEVC by default, or
codec: .h264for wider compatibility. - Content. Pins and SwiftUI annotations are drawn in.
includesPins: falseandincludesAnnotations: falseleave them out. The layers of the map’sImmersiveMapLayersControllerare drawn as they are when the export starts. - Progress.
recorder.onProgressreports the phase andfractionCompleted, andrecorder.cancel()stops the export and deletes the partial file.
Platform sizes
The presets of ImmersiveMapFrameFormat are the upload sizes of Threads, X, Instagram, TikTok, YouTube, LinkedIn, Facebook and GitHub, and ImmersiveMapFrameFormat(pixelWidth:pixelHeight:) is any other size. Pass one as the format of a picture or a video.
On macOS, .windowFormat(_:) on a scene opens its window at a preset’s pixels, for a screenshot or a screen recording that is ready to post:
WindowGroup {
ContentView()
}
.windowFormat(.threadsVideo)
Credit
Neither a picture nor a video contains the attribution badge. Add the data’s credit wherever you publish them (see Attribution).