当我在手机上使用我的mapbox-gl.js地图时,它会一直转动,因为我转动手机以保持北方。我怎么能阻止这个?我确实想继续用触摸手势旋转地图......
这是api。
答案 0 :(得分:0)
Ahum ...,抱歉,此刻轴承跟踪不在mapbox-gl.js api中。这是'我自己'的代码。我从某个地方调整了一个片段而忘记了......:
const easing = t => t * (2 - t)
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', event => {
let compassdir
if (event.webkitCompassHeading) {
// Apple works only with this, alpha doesn't work
compassdir = event.webkitCompassHeading
}
else {
compassdir = event.alpha
}
myMap.easeTo({
bearing: 360 - compassdir,
easing: easing
})
})
}
else {
alert("Sorry, your browser doesn't support Device Orientation")
}