【问题标题】:Having issues clearing google maps layer清除谷歌地图图层时遇到问题
【发布时间】:2013-11-09 13:42:21
【问题描述】:

我一直在使用 this postthis 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 文件中获取数据。

【问题讨论】:

标签: javascript google-maps google-maps-api-3 google-maps-markers


【解决方案1】:

在声明var d = 时使用第二个for in 循环,您似乎并没有迭代所有[coords]。因此,我猜d[0] 将包含来自co_arr.coordinates 的所有键值对。这可能是问题的一部分吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    相关资源
    最近更新 更多