reactjs - 使用 react-mapbox-gl 的 fitBounds 定位到特定边界
问题描述
我想让地图重新定位到按钮单击事件的常量绑定。加载页面时,它显示我得到正确计算的界限的界限。加载后,我需要导航到我绘制的标记。导航到几个标记后,需要飞到我首先得到的原始边界。但它位于伦敦市。我不确定为什么它没有重新定位到原始边界。
这是我的代码
<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
组件和道具,例如showAll
, center
,fitBounds
用于 Map。
showAll
是否显示所有标记。当showAll
为真时,需要显示所有标记,因此需要显示带有 的区域fitBound
。当showAll
为假时,需要显示中心点。
我通过变量CustomMapbox
选择了正确的道具。showAll
在CustomMapbox
中,如果showAll
为真,center
道具将被移除,或者,fitBounds
道具将被移除。问题是在页面加载时正确显示此区域,但在导航到特定中心后未显示。
是否有任何解决方案可以使用此功能react-mapbox-gl
?
解决方案
每个人!我自己解决了。使用 fitBounds 时,需要使用该边界的中心。它现在运行良好
不需要使用showAll
标志fitBounds
只需要使用fitBounds
和它的center
值
推荐阅读
- php - 如何在 PHP 中更改数组的键?
- spring-boot - 嵌入式服务器(微服务)是否等同于应用服务器(JbossEAP)?
- python - 对于给定的 Pandas df,按列对 df 进行排序(首先是最高的 SUMMED 值),然后在每个唯一值中按另一列排序
- gradle - 在使用 Gradle 5.4 的 multibuild 项目中,java 8 的 sourceSompatiblity 没有生效
- symfony - 如何在数据库中添加 JSON 字段?
- java - 应用程序无法加载 application.yml 文件
- regex - 使用 NIFI 中的替换文本从数据中提取文本时出错
- hibernate - SpringBoot 2.1.5.RELEASE & MySQL 8.0.15 中未生成 GenerationType.IDENTITY
- javascript - 在 React Router 中,我如何删除/更改我之前发送的 history.push 中的参数?
- javascript - 如何首先向上滚动 url 地址栏(在移动浏览器上)