【发布时间】:2021-07-17 20:27:33
【问题描述】:
每次我在地图上移动时,我都会尝试在我的 React 应用程序中 console.log Mapbox 地图的边界。
这是我目前的尝试:
return (
<>
<DeckGL
layers={layers}
initialViewState={INITIAL_VIEW_STATE}
controller={true}
onViewStateChange={stateChangeFunc}
>
<ReactMapGL
reuseMaps
mapStyle={mapStyle}
preventStyleDiffing={true}
ref={(ref) => console.log(ref.getMap().getBounds())}
mapboxApiAccessToken={token}
/>
</DeckGL>
</>
);
地图加载时会打印边界,但在地图上移动时无法打印。我应该使用prop 来访问此功能吗?将ref={(ref) => console.log(ref.getMap().getBounds())} 放入DeckGL 不起作用。对于ReactMapGL,是否有相当于onViewStateChange 的道具?这可能允许我创建一个打印出ref 的函数。
【问题讨论】:
标签: reactjs mapbox mapbox-gl-js deck.gl react-map-gl