【发布时间】:2013-12-21 10:48:15
【问题描述】:
我正在尝试将 heatmap.js 与 Google 地图集成以进行一些可视化工作。我提到了这个:
http://www.patrick-wied.at/static/heatmapjs/example-heatmap-googlemaps.html
因此,我在本地示例中的代码看起来几乎相同:
<!DOCTYPE html>
<html lang="en">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<div id="heatmapArea" style="width:1024px;padding:0;height:768px;cursor:pointer;position:relative;"></div>
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="js/heatmap.js"></script>
<script type="text/javascript" src="js/heatmap-gmaps.js"></script>
<script type="text/javascript">
window.onload = function(){
// standard gmaps initialization
var myLatlng = new google.maps.LatLng(48.3333, 16.35);
// define map properties
var myOptions = {
zoom: 3,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: false,
scrollwheel: true,
draggable: true,
navigationControl: true,
mapTypeControl: false,
scaleControl: true,
disableDoubleClickZoom: false
};
// we'll use the heatmapArea
var map = new google.maps.Map($("#heatmapArea")[0], myOptions);
// let's create a heatmap-overlay
// with heatmap config properties
var heatmap = new HeatmapOverlay(map, {
"radius":20,
"visible":true,
"opacity":60
});
// here is our dataset
// important: a datapoint now contains lat, lng and count property!
var testData={
max: 46,
data: [{lat: 33.5363, lng:-117.044, count: 1},{lat: 33.5608, lng:-117.24, count: 1},{lat: 38, lng:-97, count: 1},{lat: 38.9358, lng:-77.1621, count: 1}]
};
// now we can set the data
google.maps.event.addListenerOnce(map, "idle", function(){
// this is important, because if you set the data set too early, the latlng/pixel projection doesn't work
heatmap.setDataSet(testData);
});
};
</script>
</html>
正如我所料,我在我的 div 中获得了谷歌地图渲染,但热图本身并未在 testData 提供的经纬度数据点上渲染。
浏览器控制台中没有错误......
有人看到我在这里做了一些愚蠢的事情吗?
【问题讨论】:
-
我最好的猜测是我错过了上面的内容,或者 API 发生了一些微妙的变化,并且 Heatmap.js 没有保持最新。作者没有回复我的问题,这里也没有任何东西,所以我想我会寻找另一个解决方案:/
标签: javascript jquery google-maps heatmap