禁用地图旋转
防止用户旋转地图;
<!DOCTYPE html>
<html lang="en">
<head>
<title>禁用地图旋转</title>
<meta property="og:description" content="防止用户旋转地图" />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.5.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', // 容器id
style:
'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL', // 样式表位置
center: [-122.65, 45.52], // 起始位置
zoom: 9 // 起始缩放级别
});
// 禁用使用右键点击 + 拖拽来旋转地图
map.dragRotate.disable();
// 禁用使用键盘旋转地图
map.keyboard.disable();
// 禁用使用触摸旋转手势旋转地图
map.touchZoomRotate.disableRotation();
</script>
</body>
</html>