Heatmaps

The SDK allows users to display heatmaps on the map using the HeatmapManager class.

To add a heatmap to the map, retrieve an instance of this class using the Sdk.getHeatmapManager() method, create a list of points, and pass it to one of the manager's methods:

  • addHeatmapWithWeightedPoints for weighted points (represented by an ArrayList of WeightedMapCoordinates);

  • addHeatmap for non-weighted points (represented by an ArrayList of MapCoordinates).

Using non-weighted points is equivalent to using weighted points where each point is assigned a weight of 1.

It is also possible to pass a list of parameters as an object of the HeatmapParameters class, which can be created using HeatmapParameters.Builder. The following parameters can be set:

  • The radius of the heatmap elements (the default value is 20);

  • The opacity of the heatmap (the default value is 1.0);

  • The gradient to use for the heatmap;

  • A custom maximum intensity for the heatmap (if not set, it will be estimated automatically).

To change the data of an existing heatmap, call the setHeatmapData or setWeightedHeatmapData method. To modify the parameters of an existing heatmap, use the setHeatmapParameters method, passing the identifier of the heatmap.

To remove a heatmap, call the removeHeatmap method.

Heatmap gradient

The color of the heatmap can be configured using a HeatmapGradient object, which stores a list of HeatmapGradientValue. Each value is a pair consisting of a color and the intensity at which this color is applied.

The default gradient is defined as follows:

private HeatmapGradient gradient = new HeatmapGradient(new ArrayList<>( Arrays.asList( new HeatmapGradientValue(new Color(0.4f, 0.9f, 0), 0.2), new HeatmapGradientValue(new Color(1, 0, 0), 1) )));

When the first intensity value is greater than 0, the opacity of the corresponding color will be adjusted, leading to a smooth fading effect between the initial color of the gradient and the map.

Example:

ArrayList<WeightedMapCoordinates> points = new ArrayList<>(Arrays.asList( new WeightedMapCoordinates(new MapCoordinates(19.07261881, 72.883961), 1), new WeightedMapCoordinates(new MapCoordinates(19.343497, 72.805533), 1), new WeightedMapCoordinates(new MapCoordinates(18.908447, 73.328485), 1), new WeightedMapCoordinates(new MapCoordinates(19.567605, 74.202329), 1), new WeightedMapCoordinates(new MapCoordinates(18.880478, 72.936622), 4) )); HeatmapParameters parameters = new HeatmapParameters.Builder() .setRadius(10) .setOpacity(0.5f) .build(); sdk.getHeatmapManager().addHeatmapWithWeightedPoints(points, getHeatmapParameters());

The resulting heatmap:

image-20240830-155849.png