如何使用Google-Map-React在React JS中更新Google热图?

时间:2019-09-02 18:00:26

标签: javascript reactjs google-maps heatmap

我的代码中的

map-react热图。我能够通过props第一次显示热层,但无法更新数据变化的地图。任何帮助将不胜感激。

我正在使用google-map-react。我尝试过通过道具和状态传递数据。

    <GoogleMapReact
      ref={(el) => this._googleMap = el}
      bootstrapURLKeys={{ key:"MY_API_KEY",libraries: ['visualization'] }}
      defaultCenter={this.props.center}
      defaultZoom={this.props.zoom}
      heatMapLibrary={true}
      heatMapData={this.props.heatMapData}
      yesIWantToUseGoogleMapApiInternals
      onGoogleApiLoaded={({map, maps}) => {
        let heatmap = new maps.visualization.HeatmapLayer({
          data: this.props.heatData.map(point => (
            {location: new maps.LatLng(point['location'][1], point['location'][0]),
            weight: point['weight']}))
        });
        heatmap.setMap(map);
      }}
    >

    </GoogleMapReact>

0 个答案:

没有答案