Skip to content

Commit afa5eec

Browse files
authored
Scatterplot layer: smooth edges prop (#6081)
1 parent 62c579b commit afa5eec

File tree

7 files changed

+20
-2
lines changed

7 files changed

+20
-2
lines changed

docs/api-reference/layers/geojson-layer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ The following props are forwarded to a `ScatterplotLayer` if `pointType` is `'ci
272272
| `pointRadiusScale` | `1` | [radiusScale](/docs/api-reference/layers/scatterplot-layer.md#radiusscale) |
273273
| `pointRadiusMinPixels` | `0` | [radiusMinPixels](/docs/api-reference/layers/scatterplot-layer.md#radiusminpixels) |
274274
| `pointRadiusMaxPixels` | `Number.MAX_SAFE_INTEGER` | [radiusMaxPixels](/docs/api-reference/layers/scatterplot-layer.md#radiusmaxpixels) |
275+
| `pointAntialiasing` | `true` | [antialiasing](/docs/api-reference/layers/scatterplot-layer.md#antialiasing) |
275276

276277

277278
### pointType:icon Options

docs/api-reference/layers/scatterplot-layer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ The maximum line width in pixels. This prop can be used to prevent the path from
142142

143143
If `true`, rendered circles always face the camera. If `false` circles face up (i.e. are parallel with the ground plane).
144144

145+
##### `antialiasing` (Boolean, optional)
146+
147+
- Default: `true`
148+
149+
If `true`, circles are rendered with smoothed edges. If `false`, circles are rendered with rough edges. Antialiasing can cause artifacts on edges of overlapping circles. Also, antialiasing isn't supported in FirstPersonView.
150+
145151
### Data Accessors
146152

147153
##### `getPosition` ([Function](/docs/developer-guide/using-layers.md#accessors), optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square")

modules/layers/src/geojson-layer/sub-layer-map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const POINT_LAYER = {
1919
pointRadiusMinPixels: 'radiusMinPixels',
2020
pointRadiusScale: 'radiusScale',
2121
pointRadiusUnits: 'radiusUnits',
22+
pointAntialiasing: 'antialiasing',
2223

2324
getFillColor: 'getFillColor',
2425
getLineColor: 'getLineColor',

modules/layers/src/scatterplot-layer/scatterplot-layer-fragment.glsl.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ precision highp float;
2525
2626
uniform bool filled;
2727
uniform float stroked;
28+
uniform bool antialiasing;
2829
2930
varying vec4 vFillColor;
3031
varying vec4 vLineColor;
@@ -36,14 +37,19 @@ void main(void) {
3637
geometry.uv = unitPosition;
3738
3839
float distToCenter = length(unitPosition) * outerRadiusPixels;
39-
float inCircle = smoothedge(distToCenter, outerRadiusPixels);
40+
float inCircle = antialiasing ?
41+
smoothedge(distToCenter, outerRadiusPixels) :
42+
step(distToCenter, outerRadiusPixels);
4043
4144
if (inCircle == 0.0) {
4245
discard;
4346
}
4447
4548
if (stroked > 0.5) {
46-
float isLine = smoothedge(innerUnitRadius * outerRadiusPixels, distToCenter);
49+
float isLine = antialiasing ?
50+
smoothedge(innerUnitRadius * outerRadiusPixels, distToCenter) :
51+
step(innerUnitRadius * outerRadiusPixels, distToCenter);
52+
4753
if (filled) {
4854
gl_FragColor = mix(vFillColor, vLineColor, isLine);
4955
} else {

modules/layers/src/scatterplot-layer/scatterplot-layer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const defaultProps = {
4141
stroked: false,
4242
filled: true,
4343
billboard: false,
44+
antialiasing: true,
4445

4546
getPosition: {type: 'accessor', value: x => x.position},
4647
getRadius: {type: 'accessor', value: 1},
@@ -119,6 +120,7 @@ export default class ScatterplotLayer extends Layer {
119120
stroked,
120121
filled,
121122
billboard,
123+
antialiasing,
122124
lineWidthUnits,
123125
lineWidthScale,
124126
lineWidthMinPixels,
@@ -134,6 +136,7 @@ export default class ScatterplotLayer extends Layer {
134136
stroked: stroked ? 1 : 0,
135137
filled,
136138
billboard,
139+
antialiasing,
137140
radiusScale: radiusScale * pointRadiusMultiplier,
138141
radiusMinPixels,
139142
radiusMaxPixels,
-33.6 KB
Loading

test/render/test-cases/core-layers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default [
9090
getFillColor: d => [255, 128, 0],
9191
getRadius: d => d.SPACES,
9292
billboard: true,
93+
antialiasing: false,
9394
radiusScale: 30,
9495
radiusMinPixels: 1,
9596
radiusMaxPixels: 30

0 commit comments

Comments
 (0)