Mapbox has an example heatmap page. Several times, 4 numbers (0,0,6,1
, 0,1,9,3
, 0,2,9,20
, and 7,1,9,0
) appear in the specification:
// Increase the heatmap weight based on frequency and property magnitude
'heatmap-weight': [
'interpolate',
['linear'],
['get', 'mag'],
0,
0,
6,
1
],
or:
// Increase the heatmap color weight weight by zoom level
// heatmap-intensity is a multiplier on top of heatmap-weight
'heatmap-intensity': [
'interpolate',
['linear'],
['zoom'],
0,
1,
9,
3
],
or:
// Adjust the heatmap radius by zoom level
'heatmap-radius': [
'interpolate',
['linear'],
['zoom'],
0,
2,
9,
20
],
// Transition from heatmap to circle layer by zoom level
'heatmap-opacity': [
'interpolate',
['linear'],
['zoom'],
7,
1,
9,
0
]
This page explains the concept of heatmap-weight, heatmap-intensity, heatmap-radius and heatmap-opacity, the concepts the above code deals with:
heatmap-weight: Measures how much each individual point contributes to
the appearance of your heatmap. Heatmap layers have a weight of one by
default, which means that all points are weighted equally. Increasing
the heatmap-weight property to five has the same effect as placing
five points in the same location. You can use a stop function to set
the weight of your points based on a specified property.heatmap-intensity: A multiplier on top of heatmap-weight that is
primarily used as a convenient way to adjust the appearance of the
heatmap based on zoom level.heatmap-radius: Sets the radius for each point in pixels. The bigger
the radius, the smoother the heatmap and the less amount of detail.heatmap-opacity: Controls the global opacity of the heatmap layer.
However, I am not clear with what each of the repeatedly appearing 4 numbers represent.
How do each of the 4 numbers relate to heatmap-weight, heatmap-intensity, heatmap-radius and heatmap-opacity?
>Solution :
These numbers are used to define so-called interpolate expressions. In the first case, it’s a data expression because it’s based on mag
data value (magnitude of an earthquake), for all the rest, it’s based on zoom
factor (and hence is a camera expression).
Each of these can be treated as pair of numbers: first one in each pair is stop_input
, second is corresponding output. For example, this…
'heatmap-opacity': [
'interpolate',
['linear'],
['zoom'],
7, 1,
9, 0
]
… can be read like this: if zoom
is 7 or less, use 1 as heatmap-opacity, if zoom
is 9 or greater, use 0, and interpolate linearly in between.