【发布时间】: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 组件和道具,例如 showAll、center、fitBounds 用于 Map。
showAll 是否显示所有标记。
当showAll 为真时,需要显示所有标记,因此需要显示带有fitBound 的区域。
而当showAll为false时,需要显示中心点。
我制作了CustomMapbox 以通过showAll 变量选择正确的道具。
在CustomMapbox 中,如果showAll 为真,则center 道具将被移除,而fitBounds 道具将被移除。
问题是在页面加载时正确显示此区域,但在导航到特定中心后不显示。
有没有办法用react-mapbox-gl来实现这个功能?
【问题讨论】:
标签: reactjs mapbox react-map-gl