我想获取数据并在react-google-maps上显示
https://tomchentw.github.io/react-google-maps/#googlemap
问题是,为了获取数据,我需要将地图绑定作为查询,并且只在onIdle上获取地图绑定
onIdle = () => {
console.log('MAP IS READY');
console.log('GET BOUNDS IN ON IDLE: ', this.mapRef.getBounds());
}
如果我在onIdle上获取数据,则该组件将更新地图并再次调用onIdle。这会导致不定式循环。
我的问题是,在反应goole映射中获取数据的最佳位置是什么(请注意,我需要映射边界)。或者我只是在onIdle上获取它,并在获取之前检查是否已获取
答案 0 :(得分:0)
根据react-google-maps
文档,您必须以componentWillMount
周期为界。
答案 1 :(得分:0)
为Google地图添加列表器,我不确定tilesloaded
是最好的活动。如果没有,您可以尝试other events。
const map = new google.maps.Map(...)
map.addListener('tilesloaded', () => {
fetchYourDataHere().then((response) => {
this.setState({googleMapsData: response})
});
})