3

我試圖創建類似的東西到這一點,但我有一些麻煩這個工作:Fusion Tables的熱圖層

https://google-developers.appspot.com/maps/documentation/javascript/examples/layer-heatmap

我必須存儲在Fusion Tables的約35K記載,我想用來創建熱圖。數據集包含lat,long和counts。

我還想在熱圖上加上另一個圖層,它將在地圖上顯示爲標記(這個數據集也存儲在Fusion Tables中,大約600行。我怎樣才能用下列座標替換taxiData ?我的融合表

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title> 
    <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet"> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=visualization"></script> 
    <script> 
     // Adding 500 Data Points 
     var map, pointarray, heatmap; 

     var taxiData = [ 
     new google.maps.LatLng(37.782551, -122.445368), 
     new google.maps.LatLng(37.782745, -122.444586), 
     new google.maps.LatLng(37.782842, -122.443688), 
     new google.maps.LatLng(37.782919, -122.442815), 
     new google.maps.LatLng(37.782992, -122.442112), 
     new google.maps.LatLng(37.783100, -122.441461), 
     new google.maps.LatLng(37.783206, -122.440829) 
     ]; 

     function initialize() { 
     var mapOptions = { 
      zoom: 13, 
      center: new google.maps.LatLng(37.774546, -122.433523), 
      mapTypeId: google.maps.MapTypeId.SATELLITE 
     }; 

     map = new google.maps.Map(document.getElementById('map_canvas'), 
      mapOptions); 

     pointArray = new google.maps.MVCArray(taxiData); 

     heatmap = new google.maps.visualization.HeatmapLayer({ 
      data: pointArray 
     }); 

     heatmap.setMap(map); 
     } 

     function toggleHeatmap() { 
     heatmap.setMap(heatmap.getMap() ? null : map); 
     } 

     function changeGradient() { 
     var gradient = [ 
      'rgba(0, 255, 255, 0)', 
      'rgba(0, 255, 255, 1)', 
      'rgba(0, 191, 255, 1)', 
      'rgba(0, 127, 255, 1)', 
      'rgba(0, 63, 255, 1)', 
      'rgba(0, 0, 255, 1)', 
      'rgba(0, 0, 223, 1)', 
      'rgba(0, 0, 191, 1)', 
      'rgba(0, 0, 159, 1)', 
      'rgba(0, 0, 127, 1)', 
      'rgba(63, 0, 91, 1)', 
      'rgba(127, 0, 63, 1)', 
      'rgba(191, 0, 31, 1)', 
      'rgba(255, 0, 0, 1)' 
     ] 
     heatmap.setOptions({ 
      gradient: heatmap.get('gradient') ? null : gradient 
     }); 
     } 

     function changeRadius() { 
     heatmap.setOptions({radius: heatmap.get('radius') ? null : 20}); 
     } 

     function changeOpacity() { 
     heatmap.setOptions({opacity: heatmap.get('opacity') ? null : 0.2}); 
     } 
    </script> 
    </head> 

    <body onload="initialize()"> 
    <div id="map_canvas" style="height: 600px; width: 800px;"></div> 
    <button onclick="toggleHeatmap()">Toggle Heatmap</button> 
    <button onclick="changeGradient()">Change gradient</button> 
    <button onclick="changeRadius()">Change radius</button> 
    <button onclick="changeOpacity()">Change opacity</button> 
    </body> 
</html> 

回答

1

有關Fusion Tables的,你沒有創建一個HeatmapLayer,而是FusionTablesLayer會like so

layer = new google.maps.FusionTablesLayer({ 
    query: { 
    select: 'LATITUDE', 
    from: '0ILwUgu7vj0VSZnVzaW9udGFibGVzOjEzNjcwNQ' 
    }, 
    heatmap: { 
    enabled: true 
    } 
}); 
layer.setMap(map); 

你可以限制通過添加where:部分查詢中使用的數據

要使用融合表製作帶簡單標記的圖層,只需省略heatmap: { enabled: true }部分。

+1

謝謝!有沒有辦法調整熱圖,使其在放大時不會降級/消失? – davids12 2013-02-14 15:56:38

+0

@ user2072392:這不是真的有辱人格,它只是相應地分散權重。因爲當你放大,物品「分散開來」並失去它們的體重集中時,它會產生有辱人格的幻覺。如果您想避免這種情況,您需要修改查詢過濾器,以便僅從適合視圖窗口的地理定位中提取數據 - 我認爲這不受支持。 – PinnyM 2013-02-14 16:08:24

+0

啊,我明白了。再次感謝您的幫助,我真的很感激! – davids12 2013-02-14 16:16:58

相關問題