清除谷歌地图图层时遇到问题
Having issues clearing google maps layer
我一直在研究这篇文章和这个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 文件中获取数据。
在声明var d =
时,使用第二个for in
循环,您似乎并没有在所有[coords]
进行迭代。因此,我想d[0]
将容纳来自co_arr.coordinates
的所有键值对。这可能是问题的一部分吗?
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 将jQuery转换为用户脚本的普通Javascript时遇到问题
- 将子文档推送到父数组时遇到问题
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 在将javascript附加到我的html中时遇到问题
- 为什么我在以编程方式打开窗口时遇到问题
- 在将缩略图链接到模态时遇到问题
- 使用 ng 模型获取数据时遇到问题
- 是否有其他人在设计Twitter Typeahead时遇到问题'的搜索栏
- 使用jquery进行整数比较时遇到问题
- 使用PhantomJS下载动态web内容时遇到问题
- 设置RequireJS时遇到问题
- 让Javascript在SharePoint 2010上运行时遇到问题
- I'我在react.js中编写for循环时遇到问题
- 通过jQuery获取上传的文件名时遇到问题
- 我在启动我的节点时遇到问题.js IRC 机器人
- Ruby on Rails 4:在 Rails Web 应用程序中添加 Javascript 文件时遇到问题
- 从谷歌地图自定义控件打开离子模态时遇到问题
- 在使用 YAML 和 Google App Engine 时遇到问题
- 在 Chrome 扩展程序中将鼠标悬停在广告上使用时遇到问题