如何阻止mapbox-gl.js跟踪我的移动罗盘

时间:2017-03-17 17:05:27

标签: javascript mapbox-gl-js

当我在手机上使用我的mapbox-gl.js地图时,它会一直转动,因为我转动手机以保持北方。我怎么能阻止这个?我确实想继续用触摸手势旋转地图......

这是api

1 个答案:

答案 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")
  }