-1
我一直在努力this post和this jsfiddle。我試圖在填充新數據之前清除地圖圖層,但它看起來像覆蓋層只是堆疊在一起而沒有被清除。有問題清除谷歌地圖層
這裏是我的代碼,因爲它目前存在:
// For the heatmap layer
var heatmapData = [];
var heatmap;
// Instantiate counter
var files = 0;
// Looping and loading files with timeout
(function myLoop (i) {
setTimeout(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', ('js/tweets'+ files + '.json'), true);
xhr.onload = function() {
loadTweets(this.responseText);
};
xhr.send();
// Clear out map styles
heatmap.setMap(null);
if (--i) myLoop(i);
// Stall for 3 seconds
}, 3000)
})(100);
// Parse out the JSON and create markers
function loadTweets(results) {
// Parse out our JSON file
var tweetStructure = $.parseJSON(results);
// Go gets it
for (a in tweetStructure){
var co_arr = tweetStructure[a];
for (coords in co_arr.coordinates){
var d = co_arr.coordinates;
// Stating our lat/longs
var first = d[0];
var second = d[1];
var magnitude = d[2];
// Setting them
var latLng = new google.maps.LatLng(first, second);
// Weighted location to express polarity
var weightedLoc = {
location: latLng,
weight: Math.pow(2, magnitude)
};
heatmapData.push(weightedLoc);
}
}
// Instantiate heat map
heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapData,
dissipating: false,
map: map
});
}
我從四個靜態JSON文件得到我的數據。
此信息可能會對您有所幫助。 http://stackoverflow.com/questions/16847944/toggle-between-data-in-google-heat-map – geocodezip