Disable Map Rotation in Maptoolkit Maps JS
By default, Maptoolkit Maps JS lets users rotate the map by right-click dragging or using two fingers. You can disable this by calling map.dragRotate.disable() and map.touchZoomRotate.disableRotation() after the map is initialized. Use this when north-up orientation is required for data interpretation, when your UI assumes a fixed bearing, or in applications where accidental rotation would confuse users.
const API_KEY = 'YOUR_API_KEY';
const map = new maptoolkit.Map({
container: 'map',
apiKey: API_KEY,
style: `https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=${API_KEY}`,
center: [11.39085, 47.27574],
zoom: 12,
attributionControl: { compact: false }
});
// Disable right-click + drag and touch rotation
map.dragRotate.disable();
map.touchZoomRotate.disableRotation();<!DOCTYPE html>
<html lang="en">
<head>
<title>Disable Map Rotation - Maptoolkit Maps JS</title>
<meta property="og:description" content="Disable map rotation so the map always stays north-up." />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.3/dist/maptoolkit.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.3/dist/maptoolkit.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const API_KEY = 'YOUR_API_KEY';
const map = new maptoolkit.Map({
container: 'map',
apiKey: API_KEY,
style: `https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=${API_KEY}`,
center: [11.39085, 47.27574],
zoom: 12,
attributionControl: { compact: false }
});
// Disable right-click + drag and touch rotation
map.dragRotate.disable();
map.touchZoomRotate.disableRotation();
</script>
</body>
</html>Use the prompt below with any LLM to get the same result. Make sure the Maptoolkit MCP server is connected first — check out AI Integration & MCP to get started.
How it works
Rotation reaches the map by two routes, so switching it off takes two calls:
dragRotate.disable() for right-click and control-drag on desktop, and
touchZoomRotate.disableRotation() for the two-finger twist on touch devices. Disabling only
the first leaves phones able to rotate.
touchZoomRotate.disableRotation() keeps pinch-to-zoom working, which is what you want.
Disabling the whole handler would take zoom with it.
The reason to do this is usually accidental rotation: a map nudged three degrees off north looks broken rather than deliberate, and there is no visible way back unless a compass control is present.
If rotation stays enabled, add NavigationControl so the compass gives users a way to reset
north.
Next steps
The decision worth making next is whether north-up is a constraint or a default. Locking it suits a flat city map; allowing rotation with a visible compass suits anything with terrain or a travel direction.
If you keep rotation, snapping back to north when the user gets close to it is a small touch that removes most of the accidental cases without taking the capability away.