Skip to content

Commit f48b577

Browse files
committed
WebMercatorViewport support external projectionMatrix
Provide fov rather than scaleMultiplier Use projectionMatrix rather than fov for altitude Add this.fovy to WebMercatorViewport Fix path to math.gl/web-mercator Remove altitudeFromProjection variable
1 parent 5e9e0ac commit f48b577

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

examples/webpack.config.local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma, linkToMath) {
6161
'geoid',
6262
'geospatial',
6363
'main',
64-
'mercator',
64+
'web-mercator',
6565
'polygon',
6666
'proj4',
6767
'sun',

modules/core/src/viewports/web-mercator-viewport.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
import * as vec2 from 'gl-matrix/vec2';
3636
import {Matrix4} from 'math.gl';
3737

38+
const RADIANS_TO_DEGREES = 180 / Math.PI;
39+
3840
export default class WebMercatorViewport extends Viewport {
3941
/**
4042
* @classdesc
@@ -52,6 +54,7 @@ export default class WebMercatorViewport extends Viewport {
5254
bearing = 0,
5355
nearZMultiplier = 0.1,
5456
farZMultiplier = 1.01,
57+
projectionMatrix,
5558
orthographic = false,
5659

5760
repeat = false,
@@ -73,7 +76,7 @@ export default class WebMercatorViewport extends Viewport {
7376
width,
7477
height,
7578
pitch,
76-
altitude,
79+
altitude: projectionMatrix ? projectionMatrix[5] / 2 : altitude,
7780
nearZMultiplier,
7881
farZMultiplier
7982
});
@@ -123,6 +126,7 @@ export default class WebMercatorViewport extends Viewport {
123126
this.pitch = pitch;
124127
this.bearing = bearing;
125128
this.altitude = altitude;
129+
this.fovy = fov * RADIANS_TO_DEGREES;
126130

127131
this.orthographic = orthographic;
128132

test/modules/core/viewports/web-mercator-viewport.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import test from 'tape-catch';
2222
import {equals, config, Vector3} from 'math.gl';
2323
import {WebMercatorViewport} from 'deck.gl';
24+
import {Matrix4} from 'math.gl';
2425

2526
// Adjust sensitivity of math.gl's equals
2627
const LNGLAT_TOLERANCE = 1e-6;
2728
const ALT_TOLERANCE = 1e-5;
2829
const OFFSET_TOLERANCE = 1e-5;
2930

31+
const DEGREES_TO_RADIANS = Math.PI / 180;
32+
3033
/* eslint-disable */
3134
const TEST_VIEWPORTS = [
3235
{
@@ -276,6 +279,21 @@ test('WebMercatorViewport.subViewports', t => {
276279
t.end();
277280
});
278281

282+
test('WebMercatorViewport.projectionMatrix', t => {
283+
const opts = {...TEST_VIEWPORTS[0]};
284+
285+
const fovy = 25;
286+
const projectionMatrix = new Matrix4().perspective({
287+
fovy: fovy * DEGREES_TO_RADIANS,
288+
aspect: opts.width / opts.height,
289+
near: 0.1,
290+
far: 10
291+
});
292+
let viewport = new WebMercatorViewport({projectionMatrix, ...opts});
293+
t.deepEqual(viewport.fovy, fovy, 'fovy is passed through');
294+
t.end();
295+
});
296+
279297
function getCulling(p, planes) {
280298
let outDir = null;
281299
p = new Vector3(p);

0 commit comments

Comments
 (0)