经纬志
首页 / MapLibre / 使用示例

禁用地图旋转

只允许平移和缩放,右键拖拽、双指旋转、键盘旋转全部关闭,视角始终朝北。

MapLibre GL JS 4.x · 更新 2026-10-28
源码与运行效果
运行效果

说明

构造时 dragRotate 与 pitchWithRotate 关掉,touchPitch 也关掉,再单独调用 touchZoomRotate.disableRotation() 覆盖触屏路径。

键盘旋转要单独 disableRotation(),构造参数管不到它。

配置取值说明
dragRotatefalse关掉鼠标右键旋转
pitchWithRotatefalse关掉随旋转改俯仰
touchZoomRotate.disableRotation()方法关掉双指旋转

只关 dragRotate 时,触屏双指仍能旋转,必须补上 touchZoomRotate.disableRotation()。