Remove HeatmapLayer from google maps

前端 未结 5 1306
余生分开走
余生分开走 2021-01-17 18:09

I\'m using the HeatmapLayer api https://developers.google.com/maps/documentation/javascript/layers#JSHeatMaps

I generate the heatmap like this:

heatm         


        
5条回答
  •  隐瞒了意图╮
    2021-01-17 18:48

    You need to declare the heatmap globally and then when you want to display new data on the heatmap do this:

    let heatmap;
    
    setData(heatmapData) {
        if (heatmap) {
          // Clear heatmap data
          heatmap.setMap(null);
          heatmap.setData([]);
        }
        heatmap = new google.maps.visualization.HeatmapLayer({
          data: heatmapData
        });
    
        heatmap.setMap(this.map);
    }
    

提交回复
热议问题