Skip to content

Commit 7052480

Browse files
Improve tile traversal in GlobeView (visgl#6106)
1 parent 331f082 commit 7052480

File tree

8 files changed

+78
-76
lines changed

8 files changed

+78
-76
lines changed

modules/aggregation-layers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@luma.gl/shadertools": "^8.5.4",
33-
"@math.gl/web-mercator": "^3.5.3",
33+
"@math.gl/web-mercator": "^3.5.4",
3434
"d3-hexbin": "^0.2.1"
3535
},
3636
"peerDependencies": {

modules/carto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@loaders.gl/loader-utils": "^3.0.8",
3535
"@loaders.gl/mvt": "^3.0.8",
3636
"@loaders.gl/tiles": "^3.0.8",
37-
"@math.gl/web-mercator": "^3.5.3",
37+
"@math.gl/web-mercator": "^3.5.4",
3838
"cartocolor": "^4.0.2",
3939
"d3-scale": "^3.2.3"
4040
},

modules/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
"@loaders.gl/core": "^3.0.8",
3535
"@loaders.gl/images": "^3.0.8",
3636
"@luma.gl/core": "^8.5.4",
37-
"@math.gl/web-mercator": "^3.5.3",
37+
"@math.gl/web-mercator": "^3.5.4",
3838
"gl-matrix": "^3.0.0",
39-
"math.gl": "^3.5.3",
39+
"math.gl": "^3.5.4",
4040
"mjolnir.js": "^2.5.0",
4141
"probe.gl": "^3.4.0"
4242
}

modules/geo-layers/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
"@loaders.gl/terrain": "^3.0.8",
3737
"@loaders.gl/tiles": "^3.0.8",
3838
"@luma.gl/experimental": "^8.5.4",
39-
"@math.gl/culling": "^3.5.3",
40-
"@math.gl/web-mercator": "^3.5.3",
39+
"@math.gl/culling": "^3.5.4",
40+
"@math.gl/web-mercator": "^3.5.4",
4141
"h3-js": "^3.6.0",
4242
"long": "^3.2.0",
43-
"math.gl": "^3.5.3"
43+
"math.gl": "^3.5.4"
4444
},
4545
"peerDependencies": {
4646
"@deck.gl/core": "^8.0.0",

modules/geo-layers/src/tile-layer/tile-2d-traversal.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
/* eslint-disable complexity */
2-
import {CullingVolume, Plane, AxisAlignedBoundingBox, BoundingSphere} from '@math.gl/culling';
3-
import {Vector3} from 'math.gl';
2+
import {
3+
CullingVolume,
4+
Plane,
5+
AxisAlignedBoundingBox,
6+
makeOrientedBoundingBoxFromPoints
7+
} from '@math.gl/culling';
48
import {osmTile2lngLat} from './utils';
59

610
const TILE_SIZE = 512;
711
// number of world copies to check
812
const MAX_MAPS = 3;
13+
// for calculating bounding volume of a tile in a non-web-mercator viewport
14+
const REF_POINTS_5 = [[0.5, 0.5], [0, 0], [0, 1], [1, 0], [1, 1]]; // 4 corners and center
15+
const REF_POINTS_9 = REF_POINTS_5.concat([[0, 0.5], [0.5, 0], [1, 0.5], [0.5, 1]]); // 4 corners, center and 4 mid points
916

1017
class OSMNode {
1118
constructor(x, y, z) {
@@ -80,19 +87,25 @@ class OSMNode {
8087
getBoundingVolume(zRange, worldOffset, project) {
8188
if (project) {
8289
// Custom projection
83-
const corner0 = osmTile2lngLat(this.x, this.y, this.z);
84-
const corner1 = osmTile2lngLat(this.x + 1, this.y + 1, this.z);
85-
const center = osmTile2lngLat(this.x + 0.5, this.y + 0.5, this.z);
86-
corner0.z = zRange[1];
87-
corner1.z = zRange[1];
88-
center.z = zRange[0];
89-
90-
const cornerPos0 = project(corner0);
91-
const cornerPos1 = project(corner1);
92-
const centerPos = new Vector3(project(center));
93-
const R = Math.max(centerPos.distance(cornerPos0), centerPos.distance(cornerPos1));
94-
95-
return new BoundingSphere(centerPos, R);
90+
// Estimate bounding box from sample points
91+
// At low zoom level we need more samples to calculate the bounding volume correctly
92+
const refPoints = this.z < 2 ? REF_POINTS_9 : REF_POINTS_5;
93+
94+
// Convert from tile-relative coordinates to common space
95+
const refPointPositions = [];
96+
for (const p of refPoints) {
97+
const lngLat = osmTile2lngLat(this.x + p[0], this.y + p[1], this.z);
98+
lngLat[2] = zRange[0];
99+
refPointPositions.push(project(lngLat));
100+
101+
if (zRange[0] !== zRange[1]) {
102+
// Account for the elevation volume
103+
lngLat[2] = zRange[1];
104+
refPointPositions.push(project(lngLat));
105+
}
106+
}
107+
108+
return makeOrientedBoundingBoxFromPoints(refPointPositions);
96109
}
97110

98111
// Use WebMercator projection

modules/layers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"@loaders.gl/images": "^3.0.8",
3232
"@mapbox/tiny-sdf": "^1.1.0",
33-
"@math.gl/polygon": "^3.5.3",
33+
"@math.gl/polygon": "^3.5.4",
3434
"earcut": "^2.0.6"
3535
},
3636
"peerDependencies": {

test/modules/geo-layers/tile-layer/utils.spec.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,16 @@ const TEST_CASES = [
255255
{
256256
title: 'globe',
257257
viewport: new GlobeView().makeViewport({
258-
width: 800,
259-
height: 800,
258+
width: 400,
259+
height: 400,
260260
viewState: {
261261
longitude: -6,
262262
latitude: 58,
263-
zoom: 0.5
263+
zoom: 1.5
264264
}
265265
}),
266-
tileSize: 256,
267-
output: [
268-
'0,0,2',
269-
'0,1,1',
270-
'0,1,2',
271-
'1,0,2',
272-
'1,1,1',
273-
'1,1,2',
274-
'2,0,2',
275-
'2,1,2',
276-
'3,0,2',
277-
'3,1,2'
278-
]
266+
tileSize: 512,
267+
output: ['0,1,1', '0,1,2', '1,0,2', '1,1,1', '1,1,2', '2,0,2', '2,1,2', '3,1,2']
279268
}
280269
];
281270

yarn.lock

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@
992992
regenerator-runtime "^0.13.2"
993993

994994
"@babel/runtime@^7.12.0":
995-
version "7.12.5"
996-
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
997-
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
995+
version "7.15.3"
996+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.3.tgz#2e1c2880ca118e5b2f9988322bd8a7656a32502b"
997+
integrity sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==
998998
dependencies:
999999
regenerator-runtime "^0.13.4"
10001000

@@ -2371,43 +2371,43 @@
23712371
resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe"
23722372
integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q==
23732373

2374-
"@math.gl/[email protected].3", "@math.gl/core@^3.5.0", "@math.gl/core@^3.5.1":
2375-
version "3.5.3"
2376-
resolved "https://registry.yarnpkg.com/@math.gl/core/-/core-3.5.3.tgz#8f40c374c68cf2731f7e2c2b7609094b10ff767a"
2377-
integrity sha512-TaSnvG0qFh1VxeNW5L58jSx0nJUMWMpUl6zo6Z3ScQzFySG5cicGOBzk/D40RkIZWPazCKCZ+ZThg5npSK9y3g==
2374+
"@math.gl/[email protected].4", "@math.gl/core@^3.5.0", "@math.gl/core@^3.5.1":
2375+
version "3.5.4"
2376+
resolved "https://registry.yarnpkg.com/@math.gl/core/-/core-3.5.4.tgz#dcddb9a774e30e15d30451081e8dbbd84fa882bf"
2377+
integrity sha512-P+Ya0TKe13tnrti+8VVFvzArTZ7zcSzZeyrHeV+IlnLCOcqYArvi/0nmeBRc524qXqTOfUYLfT2uSI+pEHXsTw==
23782378
dependencies:
23792379
"@babel/runtime" "^7.12.0"
23802380
gl-matrix "^3.0.0"
23812381

2382-
"@math.gl/culling@^3.5.1", "@math.gl/culling@^3.5.3":
2383-
version "3.5.3"
2384-
resolved "https://registry.yarnpkg.com/@math.gl/culling/-/culling-3.5.3.tgz#5b87646b42b76d1bba1a8f41e0d65447944a43fd"
2385-
integrity sha512-ABpAcrvoIOLSm1EUkwgDem4RfO28HWPBs/+taZ/ZSpJG6KiVPklpKU1NCK+05HuJStkpFZ+XlWtehWU6FAMCyA==
2382+
"@math.gl/culling@3.5.4", "@math.gl/culling@^3.5.1", "@math.gl/culling@^3.5.4":
2383+
version "3.5.4"
2384+
resolved "https://registry.yarnpkg.com/@math.gl/culling/-/culling-3.5.4.tgz#f7b60e7e4259f28bc04d505c1602b5160a64588b"
2385+
integrity sha512-P2XOAxZEm08FjAlwqW5ONcLuMDit88cdiQJ5z6mvmAmJ5kwfKw1L4d6jIEA1YJ3auSuI19iaVdUvCqJUmXLH3Q==
23862386
dependencies:
23872387
"@babel/runtime" "^7.12.0"
2388-
"@math.gl/core" "3.5.3"
2388+
"@math.gl/core" "3.5.4"
23892389
gl-matrix "^3.0.0"
23902390

2391-
"@math.gl/geospatial@^3.5.1":
2392-
version "3.5.3"
2393-
resolved "https://registry.yarnpkg.com/@math.gl/geospatial/-/geospatial-3.5.3.tgz#90a39fea16bca6c32a471cd89699c3831fb347e7"
2394-
integrity sha512-cnc8VMQrt30JmlG200VDJmmvSjaGW57gY9KEZ+raapxyyFyfDNuAuIrIxe+zbK66FbvFWTbJlDaNmKqVG+ohyw==
2391+
"@math.gl/geospatial@3.5.4", "@math.gl/geospatial@^3.5.1":
2392+
version "3.5.4"
2393+
resolved "https://registry.yarnpkg.com/@math.gl/geospatial/-/geospatial-3.5.4.tgz#7f5aa00b512604b659aeea0d599cf9901275351a"
2394+
integrity sha512-iuEz19OXlPs9RxZ1t47B+7t+9hpJ/9LzmceNg8FMXuotZEakF0XVV3Ddi3hG4sy5tTBhbDBt+K22pbEVgwCgtQ==
23952395
dependencies:
23962396
"@babel/runtime" "^7.12.0"
2397-
"@math.gl/core" "3.5.3"
2397+
"@math.gl/core" "3.5.4"
23982398
gl-matrix "^3.0.0"
23992399

2400-
"@math.gl/polygon@^3.5.1", "@math.gl/polygon@^3.5.3":
2401-
version "3.5.3"
2402-
resolved "https://registry.yarnpkg.com/@math.gl/polygon/-/polygon-3.5.3.tgz#5cdd6ad623e3a9652ed25eb52bb9941c657ee78d"
2403-
integrity sha512-VktscmyQg/Rd56nJk0Nj/UyvnPDbsnZNMWCdl3G5AYenYzLWy6h4FEWhLx8pD+Xw7VuFot8LR4WAK2TPzXzrWw==
2400+
"@math.gl/polygon@3.5.4", "@math.gl/polygon@^3.5.1", "@math.gl/polygon@^3.5.4":
2401+
version "3.5.4"
2402+
resolved "https://registry.yarnpkg.com/@math.gl/polygon/-/polygon-3.5.4.tgz#61e2545015725d69f5eb382b1a935315e8d8eb94"
2403+
integrity sha512-Qco432yukFC+mJum/CgCVX2AT0JOmSlOhwC2mHQWUJlDLe9mSYZ9SmIKHfxSsY8uRxkzqQAxBJoHPKgyoTJbag==
24042404
dependencies:
2405-
"@math.gl/core" "3.5.3"
2405+
"@math.gl/core" "3.5.4"
24062406

2407-
"@math.gl/web-mercator@^3.1.3", "@math.gl/web-mercator@^3.5.1", "@math.gl/web-mercator@^3.5.3":
2408-
version "3.5.3"
2409-
resolved "https://registry.yarnpkg.com/@math.gl/web-mercator/-/web-mercator-3.5.3.tgz#4cc7ba98a48580a18ad683206a6f6002fa9d2d7e"
2410-
integrity sha512-WZE9ALeTS4n3HDgkqTxcNLBU7DL0mjmPXSrcqSZIUeDY00+LCtNvMQWUAwqolpB7nD71vD6HLW8delzVuy4teA==
2407+
"@math.gl/web-mercator@3.5.4", "@math.gl/web-mercator@^3.1.3", "@math.gl/web-mercator@^3.5.1", "@math.gl/web-mercator@^3.5.4":
2408+
version "3.5.4"
2409+
resolved "https://registry.yarnpkg.com/@math.gl/web-mercator/-/web-mercator-3.5.4.tgz#2eca3136d33a66be665c08de01671c2ebd46867b"
2410+
integrity sha512-oSicpji8Rdyil2xWC5G3UrVVONl3vEvH8F0f6HgZHyQDw1LDiauthnTNIUbdWIvm6TF+WGd+GZ/mMLCmlKs+6w==
24112411
dependencies:
24122412
"@babel/runtime" "^7.12.0"
24132413
gl-matrix "^3.0.0"
@@ -6235,9 +6235,9 @@ [email protected]:
62356235
integrity sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=
62366236

62376237
gl-matrix@^3.0.0:
6238-
version "3.1.0"
6239-
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.1.0.tgz#f5b2de17d8fed95a79e5025b10cded0ab9ccbed0"
6240-
integrity sha512-526NA+3EA+ztAQi0IZpSWiM0fyQXIp7IbRvfJ4wS/TjjQD0uv0fVybXwwqqSOlq33UckivI0yMDlVtboWm3k7A==
6238+
version "3.3.0"
6239+
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.3.0.tgz#232eef60b1c8b30a28cbbe75b2caf6c48fd6358b"
6240+
integrity sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==
62416241

62426242
gl@^4.9.0:
62436243
version "4.9.0"
@@ -7928,12 +7928,12 @@ mapbox-gl@^1.0.0, mapbox-gl@^1.2.1:
79287928
tinyqueue "^2.0.0"
79297929
vt-pbf "^3.1.1"
79307930

7931-
math.gl@^3.5.3:
7932-
version "3.5.3"
7933-
resolved "https://registry.yarnpkg.com/math.gl/-/math.gl-3.5.3.tgz#aeb6745ece33bb9207c74d866ab6a265a74ddd06"
7934-
integrity sha512-cRQRZlc+XvNHd3bIfu3kdPPPAW0vwDelZJmkjn2TDvCyPcmyDtAiZ2Poo1aFoINP7HzN6oHYxapc/0wV3q6Opg==
7931+
[email protected].4, math.gl@^3.5.4:
7932+
version "3.5.4"
7933+
resolved "https://registry.yarnpkg.com/math.gl/-/math.gl-3.5.4.tgz#80ecebb5268394ab141e4c83c02170d9b8956d3c"
7934+
integrity sha512-WD4PwQ7WoYBcCMDKJUHdYeC+aye0OMrtsp1zHlTXVKpc+r7r0QCfgvoWDSRPeH6hQQt3CipT9HE/zWoM5xu1LA==
79357935
dependencies:
7936-
"@math.gl/core" "3.5.3"
7936+
"@math.gl/core" "3.5.4"
79377937

79387938
md5.js@^1.3.4:
79397939
version "1.3.5"
@@ -10030,9 +10030,9 @@ regenerator-runtime@^0.13.2:
1003010030
integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==
1003110031

1003210032
regenerator-runtime@^0.13.4:
10033-
version "0.13.5"
10034-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
10035-
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==
10033+
version "0.13.9"
10034+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
10035+
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
1003610036

1003710037
regenerator-transform@^0.14.2:
1003810038
version "0.14.5"

0 commit comments

Comments
 (0)