我正在使用谷歌热图,我正在尝试在 map 上加载超过 1000 个指针,但我不确定它是否正常工作。
这是我的代码:
var map, pointarray, heatmap;
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)'
]
var taxiData = [
new google.maps.LatLng(43.3128954, 10.5320177),
new google.maps.LatLng(43.4121300, 10.4157520),
....
new google.maps.LatLng(43.3116784, 10.5298907),
new google.maps.LatLng(43.3416850, 10.5290120)
]
function initialize() {
var mapOptions = {
zoom: 13,
dissipating: false,
center: new google.maps.LatLng(43.3128954, 10.5320177),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
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);
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
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.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function changeRadius() {
heatmap.set('radius', heatmap.get('radius') ? null : 20);
}
function changeOpacity() {
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}
google.maps.event.addDomListener(window, 'load', initialize);
我在这个链接上创建了一个包含完整代码的演示:http://jsfiddle.net/8b85R/
fixed fiddle (按钮点击工作)
我不明白为什么我有很多蓝色区域,但只有 2 个指针!我期待更类似于 Google 演示 (https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap) 的东西,您可以在其中找到所有 500 个指针。
我需要你的帮助! 谢谢!
最佳答案
更像是这样的:http://jsfiddle.net/6JSe7/1/ ?
我所做的只是调低(或调高数字)不透明度,这些点在不断增加的缩放级别上存在,但它们几乎不可见(我的意思是完全检测不到),并添加了消散选项:
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray,
dissipating: true,
radius: 35
});
heatmap.setMap(map);
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
heatmap.set('opacity', '0.9');
关于javascript - 谷歌热图 - map 上没有指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407123/