This is the documentation of version 0.64.0. Go to the latest version, 1.0.0-rc.5.

Fly-over plugin

A camera that flies a route: it aims at the junctions ahead, frames them, keeps clear of the terrain, and parks the followed position, marked with an arrow, where you want it on screen.

npm install @tomtom-org/maps-sdk maplibre-gl @tomtom-org/maps-sdk-plugin-flyover

@tomtom-org/maps-sdk and maplibre-gl are peer dependencies.

import { calculateRoute } from '@tomtom-org/maps-sdk/services';
import { RouteFlyover } from '@tomtom-org/maps-sdk-plugin-flyover';

const routes = await calculateRoute({ locations, guidance: { type: 'coded' } });
const flyover = new RouteFlyover(map, {
    route: routes.features[0],
    camera: { speedKMH: 300, pitch: 76 },
    onProgress: ({ traveledDistanceInMeters }) => showProgress(traveledDistanceInMeters),
});

flyover.start();

MapLibre caps the pitch at 60° by default: a flight tilted further needs mapLibre: { maxPitch: 85 } on the map.

Use cases

What it needs from the route

The camera

Every field has a default and can be changed mid-flight with setCamera(); getCamera() returns the camera in use, defaults included.

Field What it does Default
speedKMH ground speed of the camera 200
pitch camera tilt in degrees; the map's maxPitch is the ceiling 70
aim what the camera looks at down the road { mode: 'instruction', fallbackMetersAhead: 250 }
zoom what sets the camera's height { mode: 'instructions', instructionsAhead: 2 }
anchor where the followed position sits on screen follows the pitch

Aim: what the camera looks at

The camera points ahead of itself, so it turns into a bend before reaching it.

Zoom: how high it rides

The two automatic modes keep between zoom 11 and 15. In every mode the camera pulls back further where terrain would block its view of the road.

Anchor: where the position sits on screen

A level map is a plan, so the position belongs in the middle; a tilted one shows mostly what lies ahead, so the position belongs low. Absent an anchor, it slides down with the pitch to two thirds at 60°, so a top-down pass needs no mode of its own.

import { anchorForPitch } from '@tomtom-org/maps-sdk-plugin-flyover';

flyover.setCamera({ anchor: { x: 0.5, y: 0.67 } }); // fractions of the viewport
const anchor = anchorForPitch(76); // what a pitch would choose: { x: 0.5, y: 0.667 }

The marker

An arrow lies on the road at the followed position, facing along it. Restyle it, replace it or hide it with marker, and change it mid-flight with setMarker(), which replaces the whole marker setting.

// The arrow, recoloured with the SDK's SVG icon options.
new RouteFlyover(map, { route, marker: { image: { type: 'arrow', fillColor: '#e2231a', outlineColor: 'white' } } });

// An image of your own, drawn pointing up: a URL, raw SVG markup, a data URI or a loaded <img>.
flyover.setMarker({ image: { type: 'custom', image: '/icons/car-top-down.png' }, size: 56 });

flyover.setMarker({ visible: false });
Field What it does Default
visible whether the marker is shown true
image { type: 'arrow', fillColor?, outlineColor?, outlineOpacity? } or { type: 'custom', image } the arrow: the SDK's default route outline colour, outlined in white
size width and height in pixels, before the pitch foreshortens it 44

Terrain

Smoothness, and what it costs

Controlling the flight

flyover.start();              // or resume, ramping up to speed
flyover.stop();               // freeze where it is
flyover.seek(0.5);            // jump to half way along, clamped to 0..1
flyover.setRoute(nextRoute);  // fly a different route, from its start
flyover.setCamera({ pitch: 45 });
flyover.running;              // whether the flight is advancing
flyover.remove();             // stop, take the marker off, and restore your padding

API reference

For complete documentation see the RouteFlyover API Reference and anchorForPitch.

Related guides and examples