Skip to content

Commit

Permalink
Merge branch 'master' into felix/rfc-loader-worker-triangulation
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored May 4, 2021
2 parents 1da3f16 + d5bb542 commit 5829c19
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 28 deletions.
8 changes: 8 additions & 0 deletions docs/api-reference/extensions/path-style-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const layer = new PolygonLayer({
...
getDashArray: [3, 2],
dashJustified: true,
dashGapPickable: true,
extensions: [new PathStyleExtension({dash: true})]
});
```
Expand Down Expand Up @@ -98,6 +99,13 @@ The offset to draw each path with, relative to the width of the path. Negative o
* If a number is provided, it is used as the offset for all paths.
* If a function is provided, it is called on each path to retrieve its offset.


##### `dashGapPickable` (Boolean, optional)

* Default `false`

Only effective if `getDashArray` is specified. If `true`, gaps between solid strokes are pickable. If `false`, only the solid strokes are pickable.

## Remarks

### Limitations
Expand Down
1 change: 1 addition & 0 deletions examples/layer-browser/src/examples/core-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const GeoJsonLayerExample = {
lineWidthMinPixels: 1,
pickable: true,
dashJustified: true,
dashGapPickable: true,
extensions: [new PathStyleExtension({dash: true})]
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export default class ScreenGridLayer extends GridAggregationLayer {
getPickingInfo({info, mode}) {
const {index} = info;
if (index >= 0) {
const {gpuGridAggregator} = this.state;
const {gpuGridAggregator, gpuAggregation, weights} = this.state;
// Get count aggregation results
const aggregationResults = gpuGridAggregator.getData('count');
const aggregationResults = gpuAggregation
? gpuGridAggregator.getData('count')
: weights.count;

// Each instance (one cell) is aggregated into single pixel,
// Get current instance's aggregation details.
Expand Down
4 changes: 3 additions & 1 deletion modules/extensions/src/path-style/path-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {dist} from 'gl-matrix/vec3';
const defaultProps = {
getDashArray: {type: 'accessor', value: [0, 0]},
getOffset: {type: 'accessor', value: 0},
dashJustified: false
dashJustified: false,
dashGapPickable: false
};

export default class PathStyleExtension extends LayerExtension {
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class PathStyleExtension extends LayerExtension {

if (extension.opts.dash) {
uniforms.dashAlignMode = this.props.dashJustified ? 1 : 0;
uniforms.dashGapPickable = Boolean(this.props.dashGapPickable);
}

this.state.model.setUniforms(uniforms);
Expand Down
9 changes: 7 additions & 2 deletions modules/extensions/src/path-style/shaders.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ vDashOffset = instanceDashOffsets / width.x;
'fs:#decl': `
uniform float dashAlignMode;
uniform float capType;
uniform bool dashGapPickable;
varying vec2 vDashArray;
varying float vDashOffset;
Expand Down Expand Up @@ -50,15 +51,19 @@ float round(float x) {
if (gapLength > 0.0 && unitOffset > solidLength) {
if (capType <= 0.5) {
discard;
if (!(dashGapPickable && picking_uActive)) {
discard;
}
} else {
// caps are rounded, test the distance to solid ends
float distToEnd = length(vec2(
min(unitOffset - solidLength, unitLength - unitOffset),
vPathPosition.x
));
if (distToEnd > 1.0) {
discard;
if (!(dashGapPickable && picking_uActive)) {
discard;
}
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions modules/geo-layers/src/terrain-layer/terrain-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ export default class TerrainLayer extends CompositeLayer {
maxZoom,
minZoom,
extent,
maxRequests
maxRequests,
onTileLoad,
onTileUnload,
onTileError,
maxCacheSize,
maxCacheByteSize,
refinementStrategy,
fetch
} = this.props;

if (this.state.isTiled) {
Expand Down Expand Up @@ -231,7 +238,14 @@ export default class TerrainLayer extends CompositeLayer {
maxZoom,
minZoom,
extent,
maxRequests
maxRequests,
onTileLoad,
onTileUnload,
onTileError,
maxCacheSize,
maxCacheByteSize,
refinementStrategy,
fetch
}
);
}
Expand Down
49 changes: 28 additions & 21 deletions modules/geo-layers/src/tile-layer/tile-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class TileLayer extends CompositeLayer {
return changeFlags.somethingChanged;
}

updateState({props, oldProps, context, changeFlags}) {
updateState({props, changeFlags}) {
let {tileset} = this.state;
const createTileCache =
!tileset ||
Expand All @@ -76,33 +76,16 @@ export default class TileLayer extends CompositeLayer {
if (tileset) {
tileset.finalize();
}
const maxZoom = Number.isFinite(this.state.maxZoom) ? this.state.maxZoom : props.maxZoom;
const minZoom = Number.isFinite(this.state.minZoom) ? this.state.minZoom : props.minZoom;
const {
tileSize,
maxCacheSize,
maxCacheByteSize,
refinementStrategy,
extent,
maxRequests
} = props;
tileset = new Tileset2D({
...this._getTilesetOptions(props),
getTileData: this.getTileData.bind(this),
maxCacheSize,
maxCacheByteSize,
maxZoom,
minZoom,
tileSize,
refinementStrategy,
extent,
onTileLoad: this._onTileLoad.bind(this),
onTileError: this._onTileError.bind(this),
onTileUnload: this._onTileUnload.bind(this),
maxRequests
onTileUnload: this._onTileUnload.bind(this)
});
this.setState({tileset});
} else if (changeFlags.propsChanged || changeFlags.updateTriggersChanged) {
tileset.setOptions(props);
tileset.setOptions(this._getTilesetOptions(props));
// if any props changed, delete the cached layers
this.state.tileset.tiles.forEach(tile => {
tile.layers = null;
Expand All @@ -112,6 +95,30 @@ export default class TileLayer extends CompositeLayer {
this._updateTileset();
}

_getTilesetOptions(props) {
const maxZoom = Number.isFinite(this.state.maxZoom) ? this.state.maxZoom : props.maxZoom;
const minZoom = Number.isFinite(this.state.minZoom) ? this.state.minZoom : props.minZoom;
const {
tileSize,
maxCacheSize,
maxCacheByteSize,
refinementStrategy,
extent,
maxRequests
} = props;

return {
maxCacheSize,
maxCacheByteSize,
maxZoom,
minZoom,
tileSize,
refinementStrategy,
extent,
maxRequests
};
}

_updateTileset() {
const {tileset} = this.state;
const {zRange, modelMatrix} = this.props;
Expand Down

0 comments on commit 5829c19

Please sign in to comment.