【发布时间】:2017-03-17 17:05:27
【问题描述】:
当我在手机上使用我的 mapbox-gl.js 地图时,它会在我转动手机以保持北方时不断旋转。我怎样才能阻止这个?我确实希望继续能够通过触摸手势旋转地图...
这里是api。
【问题讨论】:
-
你是说手机每次旋转地图都会旋转?这听起来很奇怪,当然不是预期的行为,也不是我所见过的。可以发网址吗?
当我在手机上使用我的 mapbox-gl.js 地图时,它会在我转动手机以保持北方时不断旋转。我怎样才能阻止这个?我确实希望继续能够通过触摸手势旋转地图...
这里是api。
【问题讨论】:
嗯...,对不起,方位跟踪目前不在 mapbox-gl.js api 中。这是“我自己的”代码。我从某个地方调整过的一个 sn-p 忘记了...:
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")
}
【讨论】:
setMyBearingTrackingMode 函数和 COMPASS 值。