diff --git a/src/render/draw_heatmap.js b/src/render/draw_heatmap.js index 45ed2674f80..a6e90ba721f 100644 --- a/src/render/draw_heatmap.js +++ b/src/render/draw_heatmap.js @@ -61,7 +61,6 @@ function drawHeatmap(painter: Painter, sourceCache: SourceCache, layer: HeatmapS programConfiguration.setUniforms(painter.context, program, layer.paint, {zoom}); first = false; } - gl.uniform1f(program.uniforms.u_radius, layer.paint.get('heatmap-radius')); gl.uniform1f(program.uniforms.u_extrude_scale, pixelsToTileUnits(tile, 1, zoom)); diff --git a/src/shaders/heatmap.fragment.glsl b/src/shaders/heatmap.fragment.glsl index 35ad8a0ea27..d3a157ce5f7 100644 --- a/src/shaders/heatmap.fragment.glsl +++ b/src/shaders/heatmap.fragment.glsl @@ -1,7 +1,6 @@ #pragma mapbox: define highp float weight uniform highp float u_intensity; -uniform highp float u_radius; varying vec2 v_extrude; // Gaussian kernel coefficient: 1 / sqrt(2 * PI) diff --git a/src/shaders/heatmap.vertex.glsl b/src/shaders/heatmap.vertex.glsl index 834e21291f4..b2ff408f6bf 100644 --- a/src/shaders/heatmap.vertex.glsl +++ b/src/shaders/heatmap.vertex.glsl @@ -1,8 +1,8 @@ #pragma mapbox: define highp float weight +#pragma mapbox: define mediump float radius uniform mat4 u_matrix; uniform float u_extrude_scale; -uniform float u_radius; uniform float u_opacity; uniform float u_intensity; @@ -20,6 +20,7 @@ const highp float ZERO = 1.0 / 255.0 / 16.0; void main(void) { #pragma mapbox: initialize highp float weight + #pragma mapbox: initialize mediump float radius // unencode the extrusion vector that we snuck into the a_pos vector vec2 unscaled_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); @@ -37,12 +38,12 @@ void main(void) { // S = sqrt(-2.0 * log(ZERO / (weight * u_intensity * GAUSS_COEF))) / 3.0 float S = sqrt(-2.0 * log(ZERO / weight / u_intensity / GAUSS_COEF)) / 3.0; - // Pass the varying in units of u_radius + // Pass the varying in units of radius v_extrude = S * unscaled_extrude; - // Scale by u_radius and the zoom-based scale factor to produce actual + // Scale by radius and the zoom-based scale factor to produce actual // mesh position - vec2 extrude = v_extrude * u_radius * u_extrude_scale; + vec2 extrude = v_extrude * radius * u_extrude_scale; // multiply a_pos by 0.5, since we had it * 2 in order to sneak // in extrusion data diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 7856c9cc84e..04aa3442c04 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -3215,7 +3215,7 @@ "minimum": 1, "function": "interpolated", "zoom-function": true, - "property-function": false, + "property-function": true, "transition": true, "units": "pixels", "doc": "Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed.", diff --git a/src/style/style_layer/heatmap_style_layer_properties.js b/src/style/style_layer/heatmap_style_layer_properties.js index d6eea888d39..53bdae8c5c0 100644 --- a/src/style/style_layer/heatmap_style_layer_properties.js +++ b/src/style/style_layer/heatmap_style_layer_properties.js @@ -16,7 +16,7 @@ import type Color from '../../style-spec/util/color'; export type PaintProps = {| - "heatmap-radius": DataConstantProperty, + "heatmap-radius": DataDrivenProperty, "heatmap-weight": DataDrivenProperty, "heatmap-intensity": DataConstantProperty, "heatmap-color": HeatmapColorProperty, @@ -24,7 +24,7 @@ export type PaintProps = {| |}; const paint: Properties = new Properties({ - "heatmap-radius": new DataConstantProperty(styleSpec["paint_heatmap"]["heatmap-radius"]), + "heatmap-radius": new DataDrivenProperty(styleSpec["paint_heatmap"]["heatmap-radius"]), "heatmap-weight": new DataDrivenProperty(styleSpec["paint_heatmap"]["heatmap-weight"]), "heatmap-intensity": new DataConstantProperty(styleSpec["paint_heatmap"]["heatmap-intensity"]), "heatmap-color": new HeatmapColorProperty(styleSpec["paint_heatmap"]["heatmap-color"]), diff --git a/test/integration/render-tests/heatmap-radius/data-expression/expected.png b/test/integration/render-tests/heatmap-radius/data-expression/expected.png new file mode 100644 index 00000000000..fee0d838576 Binary files /dev/null and b/test/integration/render-tests/heatmap-radius/data-expression/expected.png differ diff --git a/test/integration/render-tests/heatmap-radius/data-expression/style.json b/test/integration/render-tests/heatmap-radius/data-expression/style.json new file mode 100644 index 00000000000..bc414ef1a21 --- /dev/null +++ b/test/integration/render-tests/heatmap-radius/data-expression/style.json @@ -0,0 +1,58 @@ +{ + "version": 8, + "metadata": { + "test": { + "height": 64, + "width": 64 + } + }, + "sources": { + "geojson": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "radius": 5 + }, + "geometry": { + "type": "Point", + "coordinates": [ + -10, + 0 + ] + } + }, + { + "type": "Feature", + "properties": { + "radius": 10 + }, + "geometry": { + "type": "Point", + "coordinates": [ + 10, + 0 + ] + } + } + ] + } + } + }, + "layers": [ + { + "id": "heatmap", + "type": "heatmap", + "source": "geojson", + "paint": { + "heatmap-radius": [ + "get", + "radius" + ] + } + } + ] +}