Remove HeatmapLayer from google maps

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

    The docs suggest you can remove a layer by calling heatmap.setMap(null)

    Update

    In your jsfiddle you were declaring your heatmap variable in the scope of each click event. To make your code work I moved the heatmap variable to exist globally, and then checked to make sure that a new heatmap did not overwrite an existing one.

    Here is your updated jsfiddle

提交回复
热议问题