Remove HeatmapLayer from google maps

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

    For anyone else searching for a solution years after the original post I found the following worked. Begin by declaring the variable as a global that will hold the heatmap MVCObject.

    var mvcObj;
    

    Then, in the function you use to add the heatmap

    if( typeof( mvcObj )=='object' ) mvcObj.clear();
    /* locations is an array of latlngs */
    mvcObj = new google.maps.MVCArray( locations );
    
    /* this.map is a reference to the map object */
    var heatmap = new google.maps.visualization.HeatmapLayer({
        data: mvcObj,
        map: this.map
    });
    

提交回复
热议问题