谷歌热图的渐变范围?

时间:2014-10-20 11:14:25

标签: javascript jquery google-maps google-maps-api-3 heatmap

我得到一个城市人的热图图层,我需要在热图上对范围人进行排序,我如何动态更改google热图渐变?

var heatMapData = [
  {location: new google.maps.LatLng(37.782, -122.447), weight: 50},
  new google.maps.LatLng(37.782, -122.445),
  {location: new google.maps.LatLng(37.782, -122.443), weight: 20},
  {location: new google.maps.LatLng(37.782, -122.441), weight: 30},
  {location: new google.maps.LatLng(37.782, -122.439), weight: 20},
  new google.maps.LatLng(37.782, -122.437),
  {location: new google.maps.LatLng(37.782, -122.435), weight: 55},

  {location: new google.maps.LatLng(37.785, -122.447), weight: 30},
  {location: new google.maps.LatLng(37.785, -122.445), weight: 20},
  new google.maps.LatLng(37.785, -122.443),
  {location: new google.maps.LatLng(37.785, -122.441), weight: 86},
  new google.maps.LatLng(37.785, -122.439),
  {location: new google.maps.LatLng(37.785, -122.437), weight: 20},
  {location: new google.maps.LatLng(37.785, -122.435), weight: 20}
];

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);

例如:我如何在热图上看20到40的范围?

1 个答案:

答案 0 :(得分:0)

使用此命令。更多信息here

 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);
  }