以下示例向旧金山的地图添加了 14 个数据点。
/* Data points defined as an array of LatLng objects */
var heatmapData = [
new google.maps.LatLng(37.782, -122.447),
new google.maps.LatLng(37.782, -122.445),
new google.maps.LatLng(37.782, -122.443),
new google.maps.LatLng(37.782, -122.441),
new google.maps.LatLng(37.782, -122.439),
new google.maps.LatLng(37.782, -122.437),
new google.maps.LatLng(37.782, -122.435),
new google.maps.LatLng(37.785, -122.447),
new google.maps.LatLng(37.785, -122.445),
new google.maps.LatLng(37.785, -122.443),
new google.maps.LatLng(37.785, -122.441),
new google.maps.LatLng(37.785, -122.439),
new google.maps.LatLng(37.785, -122.437),
new google.maps.LatLng(37.785, -122.435)
];
var sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: sanFrancisco,
zoom: 13,
mapTypeId: google.maps.MapTypeId.SATELLITE
});
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapData
});
heatmap.setMap(map);添加加权数据点
热图既可以呈现和对象中的任一个,也可以呈现这两者的组合。这两个对象都代表地图上的单个数据点,但是WeightedLocation对象可让您额外指明该数据点的权重。对数据点加权后,WeightedLocation会以高于简单LatLng对象的强度进行呈现。权重是线性标度,其中每个LatLng对象的隐性权重均为 1;添加单个{location: new google.maps.LatLng(37.782, -122.441), weight: 3}的WeightedLocation与添加三次google.maps.LatLng(37.782, -122.441)的效果相同。您可以在单个数组中混合weightedLocation与LatLng对象。
在执行以下操作时,使用WeightedLocation对象代替LatLng会很有用:
在单个位置添加大量数据。以 1000 的权重呈现单个WeightedLocation要比呈现 1000 个LatLng对象快。
根据任意对您的数据加以强调。例如,您在绘制地震数据时可以使用LatLng对象,但在测量各地震的里氏震级时应使用WeightedLocation。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-45243-4.html
还在吹牛逼