首页 > 解决方案 > 无法在单个配置中同时重置俯仰、航向、边界、中心坐标

问题描述

当我尝试在单个配置中设置相机的俯仰、航向、边界和中心坐标时,我遇到了这个奇怪的问题。

最初,这是我拥有的相机的配置 -

间距:0

标题:0

bounds:一些坐标边界

中心坐标:空

这些值通过 props 传递给相机,如下所示 -

const {
  followUserLocation,
  heading,
  pitch,
  animationDuration,
  zoomLevel, 
  centerCoordinate,
  bounds
} = this.state;
<MapboxGL.Camera
      ref={camera => (this._camera = camera)}
      bounds={bounds}
      centerCoordinate={centerCoordinate}
      heading={heading}
      pitch={pitch}
      animationDuration={animationDuration}
      zoomLevel={zoomLevel}
      followUserLocation={locationPermissionGranted ? 
      followUserLocation : false}
      followUserMode={'normal'}
/>

在某些外部事件上,我收到一组航点,我想更新俯仰和航向,并将相机聚焦在每个外部事件的每个航点上(例如单击下一个/上一个按钮)。所以我做以下 -

this.setState({
  pitch: 60,
  heading: someHeading,
  animationDuration: 400,
  bounds: undefined,
  centerCoordinate: nextWaypoint,
  zoomLevel
})

我的相机正确地更新了俯仰,航向,删除了默认边界并立即正确地聚焦到中心坐标。

当我尝试将相机“重置”到默认阶段时出现问题 - 重置俯仰、航向、清除 centerCoordinate 并使用 setState 设置一些边界 -

this.setState({
      heading: 0, //reset
      pitch: 0, //reset
      animationDuration: 1000,
      bounds : defaultBounds,
      centerCoordinate: null, //reset
      zoomLevel: undefined // reset
    })

当我这样做时,相机没有正确重置到默认位置 - 俯仰和航向没有重置(采用旧的)并且边界也没有正确设置。

当我尝试先设置音高和航向时,添加一些超时然后设置界限,它可以工作,但不能单打。我做错了什么还是这是一个已知的错误?

当地图框完成加载时,即触发 onDidFinishLoadingMap 事件时,我正在执行所有这些操作。

我也尝试使用setCamera(cameraConfig)函数而不是状态方法,但得到了相同的结果。

标签: androidiosreact-nativemapboxreact-native-mapbox-gl

解决方案


推荐阅读