2014-09-06 56 views
0

我在我的網頁中有熱圖。它工作正常,但我必須刷新整個頁面才能獲取新值。刪除熱圖更新

我現在正在更改它,每5秒獲取一個值並繪製新值。

也工作正常。但我認爲新的價值觀正在被繪製在舊的價值觀上,因爲我每5秒鐘就會得到一個更明亮的噪音點。

如何刪除塗色值並繪製新值?

function initialize() { 
    mapOptions = { 
     zoom: 16, 
     center: new google.maps.LatLng(lat, lon), 
     mapTypeId: google.maps.MapTypeId.SATELLITE 
    }; 

    map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 
    initValues(); 
    } 

    function initValues(){ 
    pointArray = new google.maps.MVCArray(taxiData); 

    heatmap = new google.maps.visualization.HeatmapLayer({ 
     data: pointArray 
    }); 
     heatmap.setOptions({radius: 40}); 
    heatmap.setMap(map); 
    } 

在taxiData中我每次調用initValues函數都有更新的值。我調用一次初始化,然後每5秒更新一次taxiData並調用initValues。

回答

1

爲別人尋找這個我發現了以下工作。

首先聲明變量爲全局變量,它將保存熱圖MVCObject。

var mvcObj; 

然後,在功能使用添加熱圖

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 
}); 
1

這應該工作(隱藏添加新的一個以前的老熱圖):

function initialize() { 
    mapOptions = { 
     zoom: 16, 
     center: new google.maps.LatLng(lat, lon), 
     mapTypeId: google.maps.MapTypeId.SATELLITE 
    }; 

    map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 
    initValues(); 
    } 

    function initValues(){ 
    pointArray = new google.maps.MVCArray(taxiData); 
    if (!!heatmap && !!heatmap.setMap) 
     heatmap.setMap(null); 
    heatmap = new google.maps.visualization.HeatmapLayer({ 
     data: pointArray 
    }); 
    heatmap.setOptions({radius: 40}); 
    heatmap.setMap(map); 
    }