This is the documentation of version 0.62.2. 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
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();

Use cases

What it needs from the route

The line and its progress, which a calculated route carries by default. Ask for guidance: { type: 'coded' } too to unlock the instruction aim and the instructions framing; without guidance, both fall back to distances.

The camera

Every field has a default and can be changed mid-flight with setCamera().

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 next instruction, 250 m fallback
zoom what sets the camera's height framed on the next 2 instructions
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

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

The camera looks at the road on the ground, so the anchor holds over terrain at any pitch and zoom. A changed anchor is eased onto, not jumped to.

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().

// 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, in the SDK's default route colours
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
flyover.setRoute(nextRoute);  // fly a different route, from its start
flyover.setCamera({ pitch: 45 });
flyover.setMarker({ visible: false });
flyover.remove();             // stop, take the marker off, and restore your padding

onProgress reports the distance and time travelled five times a second.

API reference

For complete documentation see the RouteFlyover API Reference.