Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support line layer on Globe with Terrain3D #4970

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- _...Add new stuff here..._

### 🐞 Bug fixes
- Fix `line` layer on Globe with Terrain Elevation
- _...Add new stuff here..._

## 5.0.0-pre.5
Expand Down
15 changes: 12 additions & 3 deletions src/render/draw_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line

const depthMode = painter.getDepthModeForSublayer(0, DepthMode.ReadOnly);
const colorMode = painter.colorModeForRenderPass();

const hasTerrain = !!painter.style.map.terrain;
birkskyum marked this conversation as resolved.
Show resolved Hide resolved
const isGlobe = painter.style.projection.name === 'globe';

const dasharray = layer.paint.get('line-dasharray');
const patternProperty = layer.paint.get('line-pattern');
const image = patternProperty.constantOr(1 as any);
Expand Down Expand Up @@ -67,7 +69,11 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line
if (posTo && posFrom) programConfiguration.setConstantPatternPositions(posTo, posFrom);
}

const projectionData = transform.getProjectionData({overscaledTileID: coord});
const projectionData = transform.getProjectionData({
overscaledTileID: coord,
ignoreGlobeMatrix: hasTerrain && isGlobe
});

const pixelRatio = transform.getPixelScale();

const uniformValues = image ? linePatternUniformValues(painter, tile, layer, pixelRatio, crossfade) :
Expand Down Expand Up @@ -117,8 +123,11 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line
gradientTexture.bind(layer.stepInterpolant ? gl.NEAREST : gl.LINEAR, gl.CLAMP_TO_EDGE);
}

const [stencilModes] = painter.stencilConfigForOverlap(coords);
const stencil = (hasTerrain && isGlobe) ? stencilModes[coord.overscaledZ] : painter.stencilModeForClipping(coord);

program.draw(context, gl.TRIANGLES, depthMode,
painter.stencilModeForClipping(coord), colorMode, CullFaceMode.disabled, uniformValues, terrainData, projectionData,
stencil, colorMode, CullFaceMode.disabled, uniformValues, terrainData, projectionData,
layer.id, bucket.layoutVertexBuffer, bucket.indexBuffer, bucket.segments,
layer.paint, painter.transform.zoom, programConfiguration, bucket.layoutVertexBuffer2);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"version": 8,
"metadata": {
"test": {
}
},
"sky": {
"atmosphere-blend": 0.0
},
"center": [
0.0,
0.0
],
"zoom": 1,
"projection": { "type": "globe" },
"terrain": {
"source": "terrain",
"exaggeration": 2
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": ["local://tiles/{z}-{x}-{y}.terrain.png"],
"maxzoom": 15,
"tileSize": 256
},
"fill": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-180,
-90
],
[
-180,
90
],
[
180,
90
],
[
180,
-90
],
[
-180,
-90
]
]
]
}
},
"line": {
"type": "geojson",
"lineMetrics": true,
"data": {
"type": "LineString",
"coordinates": [
[
-90,
-85
],
[
90,
85
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "fill",
"type": "fill",
"source": "fill",
"paint": {
"fill-antialias": false,
"fill-color": "grey"
}
},
{
"id": "line",
"type": "line",
"source": "line",
"paint": {
"line-width": 10,
"line-gradient": [
"interpolate-lab",
[
"linear"
],
[
"line-progress"
],
0,
"blue",
0.1,
"royalblue",
0.3,
"cyan",
0.5,
"lime",
0.7,
"yellow",
1,
"red"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"version": 8,
"metadata": {
"test": {
}
},
"sky": {
"atmosphere-blend": 0.0
},
"center": [
0.0,
0.0
],
"zoom": 1,
"projection": { "type": "globe" },
"terrain": {
"source": "terrain",
"exaggeration": 2
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": ["local://tiles/{z}-{x}-{y}.terrain.png"],
"maxzoom": 15,
"tileSize": 256
},
"fill": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-180,
-90
],
[
-180,
90
],
[
180,
90
],
[
180,
-90
],
[
-180,
-90
]
]
]
}
},
"line": {
"type": "geojson",
"data": {
"type": "LineString",
"coordinates": [
[
-1440,
-85
],
[
1440,
85
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "fill",
"type": "fill",
"source": "fill",
"paint": {
"fill-antialias": false,
"fill-color": "grey"
}
},
{
"id": "line",
"type": "line",
"source": "line",
"paint": {
"line-width": 10,
"line-color": "red"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading