Skip to content

Commit 07d99f4

Browse files
karimnaajiansis
authored andcommitted
Disable sky after maximum projection transition to mercator (#11215)
* Disable sky below maximum projection transition to mercator * Revert change * Better naming * Apply Ansis suggestion * Renaming
1 parent 1a53d1e commit 07d99f4

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/geo/transform.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,8 @@ class Transform {
19151915
}
19161916

19171917
// Check if any of the four corners are off the edge of the rendered map
1918-
isCornerOffEdge(p0: Point, p1: Point): boolean {
1918+
// This function will return `false` for all non-mercator projection
1919+
anyCornerOffEdge(p0: Point, p1: Point): boolean {
19191920
const minX = Math.min(p0.x, p1.x);
19201921
const maxX = Math.max(p0.x, p1.x);
19211922
const minY = Math.min(p0.y, p1.y);
@@ -1924,6 +1925,10 @@ class Transform {
19241925
const horizon = this.horizonLineFromTop(false);
19251926
if (minY < horizon) return true;
19261927

1928+
if (this.projection.name !== 'mercator') {
1929+
return false;
1930+
}
1931+
19271932
const min = new Point(minX, minY);
19281933
const max = new Point(maxX, maxY);
19291934

@@ -1958,14 +1963,15 @@ class Transform {
19581963
// Checks the four corners of the frustum to see if they lie in the map's quad.
19591964
//
19601965
isHorizonVisible(): boolean {
1966+
19611967
// we consider the horizon as visible if the angle between
19621968
// a the top plane of the frustum and the map plane is smaller than this threshold.
19631969
const horizonAngleEpsilon = 2;
19641970
if (this.pitch + radToDeg(this.fovAboveCenter) > (90 - horizonAngleEpsilon)) {
19651971
return true;
19661972
}
19671973

1968-
return this.isCornerOffEdge(new Point(0, 0), new Point(this.width, this.height));
1974+
return this.anyCornerOffEdge(new Point(0, 0), new Point(this.width, this.height));
19691975
}
19701976

19711977
/**

src/render/draw_sky.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import CullFaceMode from '../gl/cull_face_mode.js';
77
import Context from '../gl/context.js';
88
import Texture from './texture.js';
99
import Program from './program.js';
10+
import {smoothstep} from '../util/util.js';
1011
import type SourceCache from '../source/source_cache.js';
1112
import SkyboxGeometry from './skybox_geometry.js';
1213
import {skyboxUniformValues, skyboxGradientUniformValues} from './program/skybox_program.js';
@@ -18,8 +19,16 @@ import assert from 'assert';
1819

1920
export default drawSky;
2021

22+
const TRANSITION_OPACITY_ZOOM_START = 7;
23+
const TRANSITION_OPACITY_ZOOM_END = 8;
24+
2125
function drawSky(painter: Painter, sourceCache: SourceCache, layer: SkyLayer) {
22-
const opacity = layer.paint.get('sky-opacity');
26+
const tr = painter.transform;
27+
const isMercator = tr.projection.name === 'mercator';
28+
// For non-mercator projection, use a forced opacity transition. This transition is set to be
29+
// 1.0 after the sheer adjustment upper bound which ensures to be in the mercator projection.
30+
const transitionOpacity = isMercator ? 1.0 : smoothstep(TRANSITION_OPACITY_ZOOM_START, TRANSITION_OPACITY_ZOOM_END, tr.zoom);
31+
const opacity = layer.paint.get('sky-opacity') * transitionOpacity;
2332
if (opacity === 0) {
2433
return;
2534
}

src/style-spec/reference/v8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
},
9797
"projection": {
9898
"type": "projection",
99-
"doc": "The projection the map should be rendered in. Suported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth, and Winkel Tripel. Terrain, fog and CustomLayerInterface are not supported for projections other than mercator.",
99+
"doc": "The projection the map should be rendered in. Suported projections are Albers, Equal Earth, Equirectangular (WGS84), Lambert conformal conic, Mercator, Natural Earth, and Winkel Tripel. Terrain, fog, sky and CustomLayerInterface are not supported for projections other than mercator.",
100100
"example": {
101101
"name": "albers",
102102
"center": [-154, 50],

src/ui/camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ class Camera extends Evented {
852852
const raycast = this._raycastElevationBox(point0, point1);
853853

854854
if (!raycast) {
855-
if (this.transform.isCornerOffEdge(point0, point1)) {
855+
if (this.transform.anyCornerOffEdge(point0, point1)) {
856856
return this;
857857
}
858858

test/unit/geo/transform.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ test('transform', (t) => {
10971097

10981098
t.test('isHorizonVisible', (t) => {
10991099

1100-
t.test('isCornerOffEdge', (t) => {
1100+
t.test('anyCornerOffEdge', (t) => {
11011101
const transform = new Transform();
11021102
transform.maxPitch = 85;
11031103
transform.resize(800, 800);
@@ -1109,21 +1109,21 @@ test('transform', (t) => {
11091109
t.true(transform.isHorizonVisible());
11101110

11111111
p0 = new Point(0, 0); p1 = new Point(10, 10);
1112-
t.true(transform.isCornerOffEdge(p0, p1));
1112+
t.true(transform.anyCornerOffEdge(p0, p1));
11131113

11141114
p0 = new Point(0, 250); p1 = new Point(10, 350);
1115-
t.true(transform.isCornerOffEdge(p0, p1));
1115+
t.true(transform.anyCornerOffEdge(p0, p1));
11161116

11171117
p0 = new Point(0, transform.horizonLineFromTop() - 10);
11181118
p1 = new Point(10, transform.horizonLineFromTop() + 10);
1119-
t.true(transform.isCornerOffEdge(p0, p1));
1119+
t.true(transform.anyCornerOffEdge(p0, p1));
11201120

11211121
p0 = new Point(0, 700); p1 = new Point(10, 710);
1122-
t.false(transform.isCornerOffEdge(p0, p1));
1122+
t.false(transform.anyCornerOffEdge(p0, p1));
11231123

11241124
p0 = new Point(0, transform.horizonLineFromTop());
11251125
p1 = new Point(10, transform.horizonLineFromTop() + 10);
1126-
t.false(transform.isCornerOffEdge(p0, p1));
1126+
t.false(transform.anyCornerOffEdge(p0, p1));
11271127

11281128
t.end();
11291129
});

0 commit comments

Comments
 (0)