【问题标题】:Locate to specific bound by using fitBounds of react-mapbox-gl使用 react-mapbox-gl 的 fitBounds 定位到特定边界
【发布时间】:2018-10-21 02:40:04
【问题描述】:

我想让地图重新定位到按钮单击事件的常量绑定。 加载页面时,它显示我得到正确计算的界限的界限。 加载后,我需要导航到我绘制的标记。 导航到几个标记后,需要飞到我首先得到的原始边界。 但它位于伦敦市。 我不确定为什么它没有重新定位到原始边界。

这是我的代码

<CustomMapbox
    showAll={this.state.showAll}
    center={this.state.center}
    fitBounds={this.state.bound}
    zoom={[8]}
    containerStyle={{
       height: "100%"
    }} onClick={this.onClickMap}
>
     <Marker
        locations={this.state.places}
        data={this.state.product}
        onClick={this.onClickPosition} 
     />

      { (this.state.selectedPoint ) && (this.state.showPopup) &&
         <Popup key={`${this.state.selectedPoint[0]}_${this.state.selectedPoint[1]}`} coordinates={this.state.selectedPoint}>
              <StyledPopup>
                <div>{this.state.selectedUPCDate}</div>
              </StyledPopup>
         </Popup>
                }
</CustomMapbox>

如您所见,我正在使用 CustomMapbox 组件和道具,例如 showAllcenterfitBounds 用于 Map。 showAll 是否显示所有标记。 当showAll 为真时,需要显示所有标记,因此需要显示带有fitBound 的区域。 而当showAll为false时,需要显示中心点。

我制作了CustomMapbox 以通过showAll 变量选择正确的道具。 在CustomMapbox 中,如果showAll 为真,则center 道具将被移除,而fitBounds 道具将被移除。 问题是在页面加载时正确显示此区域,但在导航到特定中心后不显示。

有没有办法用react-mapbox-gl来实现这个功能?

【问题讨论】:

    标签: reactjs mapbox react-map-gl


    【解决方案1】:

    大家! 我自己解决了。 使用 fitBounds 时,需要使用该边界的中心。 它现在运行良好

    不需要为fitBounds 使用showAll 标志 只需要使用fitBounds 及其center

    【讨论】:

    • 如果你能发布更新的代码那就太好了
    猜你喜欢
    • 2016-03-06
    • 2016-06-05
    • 2016-03-20
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多