Heatmaps (v2.1.x - iOS)
The SDK allows users to display heatmaps on the map using the NMHeatmapManager
class.
To add a heatmap to the map, retrieve an instance of this class using the NMSdk
property heatmapManager
, create a list of points, and pass it to one of the manager's methods:
-(NSUInteger)addHeatmapWithWeightedPoints:(NSArray <NMWeightedMapCoordinates *>*)weightedMapCoordinates;
for weighted points (represented by anNSArray
ofNMWeightedMapCoordinates
)-(NSUInteger)addHeatmap:(NSArray <NMMapCoordinates *>*)mapCoordinates
for non-weighted points (represented by an
NSArray
ofNMMapCoordinates
).
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 NMHeatmapParameters
class. 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
-(void)setDataWithHeatmapId:(NSUInteger)heatmapId mapCoordinates:(NSArray <NMMapCoordinates *>*)mapCoordinates
or
-(void)setDataWithHeatmapId:(NSUInteger)heatmapId weightedMapCoordinates:(NSArray <NMWeightedMapCoordinates *>*)weightedMapCoordinates
method.
To modify the parameters of an existing heatmap, use the
-(void)setDataWithHeatmapId:(NSUInteger)heatmapId parameters:(NMHeatmapParameters *)parameters
method, passing the identifier of the heatmap.
To remove a heatmap, call the -(void)removeHeatmapWithId:(NSUInteger)heatmapId
method.
Heatmap gradient
The color of the heatmap can be configured using a NSArray
object with a list of NMHeatmapGradientValue
. 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:
NSArray<NMHeatmapGradientValue *>* gradient = @[
[[NMHeatmapGradientValue alloc] initWithColor:[UIColor colorWithRed:0.4 green:0.9 blue:0.0 alpha:1.0] intensity:0.2],
[[NMHeatmapGradientValue alloc] initWithColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0] intensity:1.0]
];
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:
NSArray<NMWeightedMapCoordinates *> *points = @[
[NMWeightedMapCoordinates weightedMapCoordinatesWithCoordinates:[NMMapCoordinates mapCoordinatesWithLatitude:19.07261881 longitude:72.883961] weight:1],
[NMWeightedMapCoordinates weightedMapCoordinatesWithCoordinates:[NMMapCoordinates mapCoordinatesWithLatitude:19.343497 longitude:72.883961] weight:1],
[NMWeightedMapCoordinates weightedMapCoordinatesWithCoordinates:[NMMapCoordinates mapCoordinatesWithLatitude:18.908447 longitude:73.328485] weight:1],
[NMWeightedMapCoordinates weightedMapCoordinatesWithCoordinates:[NMMapCoordinates mapCoordinatesWithLatitude:19.567605 longitude:74.202329] weight:1],
[NMWeightedMapCoordinates weightedMapCoordinatesWithCoordinates:[NMMapCoordinates mapCoordinatesWithLatitude:18.880478 longitude:72.936622] weight:4]
];
NMHeatmapParameters *parameters = [[NMHeatmapParameters alloc] init];
parameters.radius = 10;
parameters.opacity = 0.5;
NSUInteger heatmapId = [sdk.heatmapManager addHeatmapWithWeightedPoints:points parameters:parameters];
The resulting heatmap: