Remove HeatmapLayer from google maps

前端 未结 5 1324
余生分开走
余生分开走 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:54

    Using heatmap.setMap(null) will only hide your heatmap layer. If you later type heatmap.setMap(map), you will see your heatmap layer again, so it didn't really get deleted.

    In order to delete the data you have to do the following steps.

    heatmap.setMap(null) //This will hide the heatmap layer

    heatmap.getData().j = []; //This is what actually sets the coordinates array to zero.

    heatmap.setMap(map) //Now when you toggle back the map, the heatlayer is gone and you can create a new one.

    Hope this helps. Took me a while to figure it out, but it definitely worked.

提交回复
热议问题