Fly to a location

Use flyTo to smoothly interpolate between locations.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.STREETS, 
    center: [74.241, 41.201],
    zoom: 6.16
});

//

document.getElementById('fly').addEventListener('click', function () {
    // Fly to a random location by offsetting the point 74.241, 41.201
    // by up to 5 degrees.
    map.flyTo({
        center: [
        74.241 + (Math.random() - 0.5) * 10,
        41.201 + (Math.random() - 0.5) * 10
        ],
        essential: true // this animation is considered essential with respect to prefers-reduced-motion
    });
});
Fit to the bounds of a lineString

Fit to the bounds of a lineString

Examples

Get the bounds of a lineString.

Fit a map to a bounding box

Fit a map to a bounding box

Examples

Fit map to a specific area using fitBounds method.

Slowly fly to a location

Slowly fly to a location

Examples

Slowly zoom to locations using flyTo with flyOptions.

Create a story map, fly to a location based on the scroll position

Fly to a location based on the scroll position

Examples

Fly to locations on the map by scrolling.

Was this helpful?