user3845489
user3845489

Reputation: 11

Google heatmap gradient range?

I get a heatmap layer of city people, and I need to sort range people on a heatmap, how I dynamically change google heatmap gradient?

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

For example: How I look range from 20 to 40 on heatmap?

Upvotes: 1

Views: 3853

Answers (1)

Physicsman
Physicsman

Reputation: 181

Use this command. More info 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);
  }

Upvotes: 2

Related Questions