Restrict map panning to an area

Prevent a map from being panned to a different place by setting maxBounds.

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';
// Set bounds to New York, New York
const bounds = [
    [-74.04728500751165, 40.68392799015035], // Southwest coordinates
    [-73.91058699000139, 40.87764500765852] // Northeast coordinates
];

const map = new Map({
    container: 'map',
    style: MapStyle.STREETS, 
    center: [-73.9978, 40.7209],
    zoom: 13,
    maxBounds: bounds // Sets bounds as max
});
Disable scroll zoom

Disable scroll zoom

Examples

Prevent scroll actions from zooming your interactive map.

Disable map rotation

Disable map rotation

Examples

Prevent users from rotating your interactive map.

Fly to a location

Fly to a location

Examples

Smoothly interpolate between locations using the flyTo animation.

How to center map based on visitor’s country bounds

Center map by visitor’s country IP

Tutorials

This tutorial shows how to center map based on the visitor’s country bounds using the MapTiler Geolocation API.

Was this helpful?