Skip to content

Display map navigation controls

Add zoom and rotation controls to the map.

const map = new maplibregl.Map({
    container: 'map', // container id
    style: 'https://demotiles.maplibre.org/style.json',
    center: [-74.5, 40], // starting position
    zoom: 2, // starting zoom
    rollEnabled: true // Enable mouse control of camera roll angle with `Ctrl` + right-click and drag
});

// Add zoom and rotation controls to the map.
map.addControl(new maplibregl.NavigationControl({
    visualizePitch: true,
    visualizeRoll: true,
    showZoom: true,
    showCompass: true
}));
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Display map navigation controls</title>
    <meta property="og:description" content="Add zoom and rotation controls to the map." />
    <meta property="og:created" content="2025-06-25" />
    <meta charset='utf-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.24.0/dist/maplibre-gl.css' />
    <script src='https://unpkg.com/maplibre-gl@5.24.0/dist/maplibre-gl.js'></script>
    <style>
        body { margin: 0; padding: 0; }
        html, body, #map { height: 100%; }
    </style>
</head>
<body>
<div id="map"></div>
<script>
    const map = new maplibregl.Map({
        container: 'map', // container id
        style: 'https://demotiles.maplibre.org/style.json',
        center: [-74.5, 40], // starting position
        zoom: 2, // starting zoom
        rollEnabled: true // Enable mouse control of camera roll angle with `Ctrl` + right-click and drag
    });

    // Add zoom and rotation controls to the map.
    map.addControl(new maplibregl.NavigationControl({
        visualizePitch: true,
        visualizeRoll: true,
        showZoom: true,
        showCompass: true
    }));
</script>
</body>
</html>