@deck.gl/geo-layers 8.7.10 → 8.8.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +62999 -30700
- package/dist/es5/geo-cell-layer/GeoCellLayer.js +3 -3
- package/dist/es5/geo-cell-layer/GeoCellLayer.js.map +1 -1
- package/dist/es5/index.js +8 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mvt-layer/mvt-layer.js +19 -19
- package/dist/es5/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/es5/quadkey-layer/quadkey-layer.js +4 -2
- package/dist/es5/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/es5/quadkey-layer/quadkey-utils.js.map +1 -1
- package/dist/es5/tile-3d-layer/tile-3d-layer.js +13 -10
- package/dist/es5/tile-3d-layer/tile-3d-layer.js.map +1 -1
- package/dist/es5/tile-layer/tile-2d-header.js +36 -17
- package/dist/es5/tile-layer/tile-2d-header.js.map +1 -1
- package/dist/es5/tile-layer/tile-2d-traversal.js +13 -3
- package/dist/es5/tile-layer/tile-2d-traversal.js.map +1 -1
- package/dist/es5/tile-layer/tile-layer.js +38 -32
- package/dist/es5/tile-layer/tile-layer.js.map +1 -1
- package/dist/es5/tile-layer/tileset-2d.js +122 -96
- package/dist/es5/tile-layer/tileset-2d.js.map +1 -1
- package/dist/es5/tile-layer/types.js +2 -0
- package/dist/es5/tile-layer/types.js.map +1 -0
- package/dist/es5/tile-layer/utils.js +27 -9
- package/dist/es5/tile-layer/utils.js.map +1 -1
- package/dist/esm/geo-cell-layer/GeoCellLayer.js +6 -3
- package/dist/esm/geo-cell-layer/GeoCellLayer.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mvt-layer/mvt-layer.js +17 -17
- package/dist/esm/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/esm/quadkey-layer/quadkey-layer.js +5 -2
- package/dist/esm/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/esm/quadkey-layer/quadkey-utils.js.map +1 -1
- package/dist/esm/tile-3d-layer/tile-3d-layer.js +8 -7
- package/dist/esm/tile-3d-layer/tile-3d-layer.js.map +1 -1
- package/dist/esm/tile-layer/tile-2d-header.js +54 -18
- package/dist/esm/tile-layer/tile-2d-header.js.map +1 -1
- package/dist/esm/tile-layer/tile-2d-traversal.js +17 -3
- package/dist/esm/tile-layer/tile-2d-traversal.js.map +1 -1
- package/dist/esm/tile-layer/tile-layer.js +23 -17
- package/dist/esm/tile-layer/tile-layer.js.map +1 -1
- package/dist/esm/tile-layer/tileset-2d.js +88 -54
- package/dist/esm/tile-layer/tileset-2d.js.map +1 -1
- package/dist/esm/tile-layer/types.js +2 -0
- package/dist/esm/tile-layer/types.js.map +1 -0
- package/dist/esm/tile-layer/utils.js +26 -11
- package/dist/esm/tile-layer/utils.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +11 -11
- package/src/geo-cell-layer/{GeoCellLayer.js → GeoCellLayer.ts} +14 -10
- package/src/index.ts +6 -0
- package/src/mvt-layer/mvt-layer.js +11 -10
- package/src/quadkey-layer/quadkey-layer.ts +39 -0
- package/src/quadkey-layer/{quadkey-utils.js → quadkey-utils.ts} +2 -2
- package/src/tile-3d-layer/tile-3d-layer.js +6 -5
- package/src/tile-layer/{tile-2d-header.js → tile-2d-header.ts} +50 -16
- package/src/tile-layer/{tile-2d-traversal.js → tile-2d-traversal.ts} +49 -12
- package/src/tile-layer/{tile-layer.js → tile-layer.ts} +153 -31
- package/src/tile-layer/{tileset-2d.js → tileset-2d.ts} +143 -66
- package/src/tile-layer/types.ts +17 -0
- package/src/tile-layer/{utils.js → utils.ts} +67 -25
- package/src/quadkey-layer/quadkey-layer.js +0 -22
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/geo-layers",
|
|
3
3
|
"description": "deck.gl layers supporting geospatial use cases and GIS formats",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.8.0-alpha.4",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@loaders.gl/3d-tiles": "^3.
|
|
33
|
-
"@loaders.gl/gis": "^3.
|
|
34
|
-
"@loaders.gl/loader-utils": "^3.
|
|
35
|
-
"@loaders.gl/mvt": "^3.
|
|
36
|
-
"@loaders.gl/terrain": "^3.
|
|
37
|
-
"@loaders.gl/tiles": "^3.
|
|
32
|
+
"@loaders.gl/3d-tiles": "^3.2.0-alpha.4",
|
|
33
|
+
"@loaders.gl/gis": "^3.2.0-alpha.4",
|
|
34
|
+
"@loaders.gl/loader-utils": "^3.2.0-alpha.4",
|
|
35
|
+
"@loaders.gl/mvt": "^3.2.0-alpha.4",
|
|
36
|
+
"@loaders.gl/terrain": "^3.2.0-alpha.4",
|
|
37
|
+
"@loaders.gl/tiles": "^3.2.0-alpha.4",
|
|
38
38
|
"@luma.gl/experimental": "^8.5.10",
|
|
39
|
-
"@math.gl/core": "
|
|
40
|
-
"@math.gl/culling": "
|
|
41
|
-
"@math.gl/web-mercator": "
|
|
39
|
+
"@math.gl/core": "3.6.0-alpha.5",
|
|
40
|
+
"@math.gl/culling": "3.6.0-alpha.5",
|
|
41
|
+
"@math.gl/web-mercator": "3.6.0-alpha.5",
|
|
42
42
|
"h3-js": "^3.6.0",
|
|
43
43
|
"long": "^3.2.0"
|
|
44
44
|
},
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@deck.gl/mesh-layers": "^8.0.0",
|
|
50
50
|
"@loaders.gl/core": "^3.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "608c74fff3c955142c4e1f5e77b9e21ebbf690f7"
|
|
53
53
|
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import {CompositeLayer} from '@deck.gl/core';
|
|
2
|
-
import {PolygonLayer} from '@deck.gl/layers';
|
|
1
|
+
import {CompositeLayer, Layer, LayersList} from '@deck.gl/core';
|
|
2
|
+
import {PolygonLayer, PolygonLayerProps} from '@deck.gl/layers';
|
|
3
3
|
|
|
4
4
|
const defaultProps = {
|
|
5
5
|
...PolygonLayer.defaultProps
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export type GeoCellLayerProps<DataT = any> = PolygonLayerProps<DataT>;
|
|
9
|
+
|
|
10
|
+
export default class GeoCellLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<
|
|
11
|
+
Required<GeoCellLayerProps<DataT>> & ExtraProps
|
|
12
|
+
> {
|
|
13
|
+
static layerName = 'GeoCellLayer';
|
|
14
|
+
static defaultProps = defaultProps;
|
|
15
|
+
|
|
16
|
+
/** Implement to generate props to create geometry. */
|
|
17
|
+
indexToBounds(): Partial<GeoCellLayer['props']> | null {
|
|
11
18
|
return null;
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
renderLayers() {
|
|
21
|
+
renderLayers(): Layer | null | LayersList {
|
|
15
22
|
// Rendering props underlying layer
|
|
16
23
|
const {
|
|
17
24
|
elevationScale,
|
|
@@ -64,7 +71,7 @@ export default class GeoCellLayer extends CompositeLayer {
|
|
|
64
71
|
},
|
|
65
72
|
this.getSubLayerProps({
|
|
66
73
|
id: 'cell',
|
|
67
|
-
updateTriggers: {
|
|
74
|
+
updateTriggers: updateTriggers && {
|
|
68
75
|
getElevation: updateTriggers.getElevation,
|
|
69
76
|
getFillColor: updateTriggers.getFillColor,
|
|
70
77
|
getLineColor: updateTriggers.getLineColor,
|
|
@@ -75,6 +82,3 @@ export default class GeoCellLayer extends CompositeLayer {
|
|
|
75
82
|
);
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
|
-
|
|
79
|
-
GeoCellLayer.layerName = 'GeoCellLayer';
|
|
80
|
-
GeoCellLayer.defaultProps = defaultProps;
|
package/src/index.ts
CHANGED
|
@@ -31,3 +31,9 @@ export {default as TerrainLayer} from './terrain-layer/terrain-layer';
|
|
|
31
31
|
export {default as MVTLayer} from './mvt-layer/mvt-layer';
|
|
32
32
|
|
|
33
33
|
export {getURLFromTemplate as _getURLFromTemplate} from './tile-layer/utils';
|
|
34
|
+
export {default as _Tileset2D} from './tile-layer/tileset-2d';
|
|
35
|
+
|
|
36
|
+
// Types
|
|
37
|
+
|
|
38
|
+
export type {TileLayerProps} from './tile-layer/tile-layer';
|
|
39
|
+
export type {QuadkeyLayerProps} from './quadkey-layer/quadkey-layer';
|
|
@@ -82,18 +82,19 @@ export default class MVTLayer extends TileLayer {
|
|
|
82
82
|
this.setState({data, tileJSON});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
_getTilesetOptions(
|
|
86
|
-
const opts = super._getTilesetOptions(
|
|
85
|
+
_getTilesetOptions() {
|
|
86
|
+
const opts = super._getTilesetOptions();
|
|
87
87
|
const {tileJSON} = this.state;
|
|
88
|
+
const {minZoom, maxZoom} = this.props;
|
|
88
89
|
|
|
89
90
|
if (tileJSON) {
|
|
90
|
-
if (Number.isFinite(tileJSON.minzoom) && tileJSON.minzoom >
|
|
91
|
+
if (Number.isFinite(tileJSON.minzoom) && tileJSON.minzoom > minZoom) {
|
|
91
92
|
opts.minZoom = tileJSON.minzoom;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
if (
|
|
95
96
|
Number.isFinite(tileJSON.maxzoom) &&
|
|
96
|
-
(!Number.isFinite(
|
|
97
|
+
(!Number.isFinite(maxZoom) || tileJSON.maxzoom < maxZoom)
|
|
97
98
|
) {
|
|
98
99
|
opts.maxZoom = tileJSON.maxzoom;
|
|
99
100
|
}
|
|
@@ -116,14 +117,14 @@ export default class MVTLayer extends TileLayer {
|
|
|
116
117
|
let loadOptions = this.getLoadOptions();
|
|
117
118
|
const {binary} = this.state;
|
|
118
119
|
const {fetch} = this.props;
|
|
119
|
-
const {signal,
|
|
120
|
+
const {signal, index} = tile;
|
|
120
121
|
loadOptions = {
|
|
121
122
|
...loadOptions,
|
|
122
123
|
mimeType: 'application/x-protobuf',
|
|
123
124
|
mvt: {
|
|
124
125
|
...loadOptions?.mvt,
|
|
125
126
|
coordinates: this.context.viewport.resolution ? 'wgs84' : 'local',
|
|
126
|
-
tileIndex:
|
|
127
|
+
tileIndex: index
|
|
127
128
|
// Local worker debug
|
|
128
129
|
// workerUrl: `modules/mvt/dist/mvt-loader.worker.js`
|
|
129
130
|
// Set worker to null to skip web workers
|
|
@@ -135,14 +136,14 @@ export default class MVTLayer extends TileLayer {
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
renderSubLayers(props) {
|
|
138
|
-
const {
|
|
139
|
-
const worldScale = Math.pow(2,
|
|
139
|
+
const {x, y, z} = props.tile.index;
|
|
140
|
+
const worldScale = Math.pow(2, z);
|
|
140
141
|
|
|
141
142
|
const xScale = WORLD_SIZE / worldScale;
|
|
142
143
|
const yScale = -xScale;
|
|
143
144
|
|
|
144
|
-
const xOffset = (WORLD_SIZE *
|
|
145
|
-
const yOffset = WORLD_SIZE * (1 -
|
|
145
|
+
const xOffset = (WORLD_SIZE * x) / worldScale;
|
|
146
|
+
const yOffset = WORLD_SIZE * (1 - y / worldScale);
|
|
146
147
|
|
|
147
148
|
const modelMatrix = new Matrix4().scale([xScale, yScale, 1]);
|
|
148
149
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {AccessorFunction} from '@deck.gl/core';
|
|
2
|
+
import GeoCellLayer from '../geo-cell-layer/GeoCellLayer';
|
|
3
|
+
import {getQuadkeyPolygon} from './quadkey-utils';
|
|
4
|
+
|
|
5
|
+
const defaultProps = {
|
|
6
|
+
getQuadkey: {type: 'accessor', value: d => d.quadkey}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Properties of `QuadkeyLayer`.
|
|
11
|
+
*/
|
|
12
|
+
type QuadkeyLayerProps<DataT = any> = {
|
|
13
|
+
/**
|
|
14
|
+
* Called for each data object to retrieve the quadkey string identifier.
|
|
15
|
+
*
|
|
16
|
+
* By default, it reads `quadkey` property of data object.
|
|
17
|
+
*/
|
|
18
|
+
getQuadkey?: AccessorFunction<DataT, string>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default class QuadkeyLayer<DataT = any, ExtraProps = {}> extends GeoCellLayer<
|
|
22
|
+
DataT,
|
|
23
|
+
Required<QuadkeyLayerProps> & ExtraProps
|
|
24
|
+
> {
|
|
25
|
+
static layerName = 'QuadkeyLayer';
|
|
26
|
+
static defaultProps: any = defaultProps;
|
|
27
|
+
|
|
28
|
+
indexToBounds(): Partial<GeoCellLayer['props']> | null {
|
|
29
|
+
const {data, getQuadkey} = this.props;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
data,
|
|
33
|
+
_normalize: false,
|
|
34
|
+
positionFormat: 'XY',
|
|
35
|
+
|
|
36
|
+
getPolygon: (x: DataT, objectInfo) => getQuadkeyPolygon(getQuadkey(x, objectInfo))
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -2,7 +2,7 @@ import {worldToLngLat} from '@math.gl/web-mercator';
|
|
|
2
2
|
|
|
3
3
|
const TILE_SIZE = 512;
|
|
4
4
|
|
|
5
|
-
export function quadkeyToWorldBounds(quadkey) {
|
|
5
|
+
export function quadkeyToWorldBounds(quadkey: string): [number[], number[]] {
|
|
6
6
|
let x = 0;
|
|
7
7
|
let y = 0;
|
|
8
8
|
let mask = 1 << quadkey.length;
|
|
@@ -20,7 +20,7 @@ export function quadkeyToWorldBounds(quadkey) {
|
|
|
20
20
|
];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function getQuadkeyPolygon(quadkey) {
|
|
23
|
+
export function getQuadkeyPolygon(quadkey: string): number[] {
|
|
24
24
|
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
25
25
|
const [w, n] = worldToLngLat(topLeft);
|
|
26
26
|
const [e, s] = worldToLngLat(bottomRight);
|
|
@@ -167,11 +167,12 @@ export default class Tile3DLayer extends CompositeLayer {
|
|
|
167
167
|
if (!timeline || !viewportsNumber || !tileset3d) {
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
tileset3d.selectTiles(Object.values(viewports)).then(frameNumber => {
|
|
171
|
+
const tilesetChanged = this.state.frameNumber !== frameNumber;
|
|
172
|
+
if (tilesetChanged) {
|
|
173
|
+
this.setState({frameNumber});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
_getSubLayer(tileHeader, oldLayer) {
|
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
|
-
import {log} from '@deck.gl/core';
|
|
3
|
-
|
|
2
|
+
import {Layer, log} from '@deck.gl/core';
|
|
3
|
+
import {RequestScheduler} from '@loaders.gl/loader-utils';
|
|
4
|
+
import {TileBoundingBox, TileIndex, TileLoadProps} from './types';
|
|
5
|
+
|
|
6
|
+
export type TileLoadDataProps = {
|
|
7
|
+
requestScheduler: RequestScheduler;
|
|
8
|
+
getData: (props: TileLoadProps) => Promise<any>;
|
|
9
|
+
onLoad: (tile: Tile2DHeader) => void;
|
|
10
|
+
onError: (error: any, tile: Tile2DHeader) => void;
|
|
11
|
+
};
|
|
4
12
|
export default class Tile2DHeader {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
index: TileIndex;
|
|
14
|
+
isVisible: boolean;
|
|
15
|
+
isSelected: boolean;
|
|
16
|
+
parent: Tile2DHeader | null;
|
|
17
|
+
children: Tile2DHeader[] | null;
|
|
18
|
+
content: any;
|
|
19
|
+
state?: number;
|
|
20
|
+
layers?: Layer[] | null;
|
|
21
|
+
|
|
22
|
+
id!: string; // assigned _always_ with result of `getTileId`
|
|
23
|
+
bbox!: TileBoundingBox; // assigned _always_ with result of `getTileMetadata`
|
|
24
|
+
zoom!: number; // assigned _always_ with result of `getTileZoom`
|
|
25
|
+
userData?: Record<string, any>; // _may be_ assigned with result of `getTileMetadata`
|
|
26
|
+
|
|
27
|
+
private _abortController: AbortController | null;
|
|
28
|
+
private _loader: Promise<void> | undefined;
|
|
29
|
+
private _loaderId: number;
|
|
30
|
+
private _isLoaded: boolean;
|
|
31
|
+
private _isCancelled: boolean;
|
|
32
|
+
private _needsReload: boolean;
|
|
33
|
+
|
|
34
|
+
constructor(index: TileIndex) {
|
|
35
|
+
this.index = index;
|
|
9
36
|
this.isVisible = false;
|
|
10
37
|
this.isSelected = false;
|
|
11
38
|
this.parent = null;
|
|
@@ -13,6 +40,8 @@ export default class Tile2DHeader {
|
|
|
13
40
|
|
|
14
41
|
this.content = null;
|
|
15
42
|
|
|
43
|
+
this._loader = undefined;
|
|
44
|
+
this._abortController = null;
|
|
16
45
|
this._loaderId = 0;
|
|
17
46
|
this._isLoaded = false;
|
|
18
47
|
this._isCancelled = false;
|
|
@@ -20,7 +49,7 @@ export default class Tile2DHeader {
|
|
|
20
49
|
}
|
|
21
50
|
|
|
22
51
|
get data() {
|
|
23
|
-
return this.isLoading ? this._loader.then(() => this.data) : this.content;
|
|
52
|
+
return this.isLoading && this._loader ? this._loader.then(() => this.data) : this.content;
|
|
24
53
|
}
|
|
25
54
|
|
|
26
55
|
get isLoaded() {
|
|
@@ -44,13 +73,19 @@ export default class Tile2DHeader {
|
|
|
44
73
|
}
|
|
45
74
|
|
|
46
75
|
/* eslint-disable max-statements */
|
|
47
|
-
async _loadData({
|
|
48
|
-
|
|
76
|
+
private async _loadData({
|
|
77
|
+
getData,
|
|
78
|
+
requestScheduler,
|
|
79
|
+
onLoad,
|
|
80
|
+
onError
|
|
81
|
+
}: TileLoadDataProps): Promise<void> {
|
|
82
|
+
const {index, id, bbox, userData, zoom} = this;
|
|
49
83
|
const loaderId = this._loaderId;
|
|
50
84
|
|
|
51
|
-
this._abortController = new AbortController();
|
|
85
|
+
this._abortController = new AbortController();
|
|
52
86
|
const {signal} = this._abortController;
|
|
53
87
|
|
|
88
|
+
// @ts-expect-error (2345) Argument of type '(tile: any) => 1 | -1' is not assignable ...
|
|
54
89
|
const requestToken = await requestScheduler.scheduleRequest(this, tile => {
|
|
55
90
|
return tile.isSelected ? 1 : -1;
|
|
56
91
|
});
|
|
@@ -68,7 +103,7 @@ export default class Tile2DHeader {
|
|
|
68
103
|
let tileData = null;
|
|
69
104
|
let error;
|
|
70
105
|
try {
|
|
71
|
-
tileData = await getData({
|
|
106
|
+
tileData = await getData({index, id, bbox, userData, zoom, signal});
|
|
72
107
|
} catch (err) {
|
|
73
108
|
error = err || true;
|
|
74
109
|
} finally {
|
|
@@ -99,9 +134,8 @@ export default class Tile2DHeader {
|
|
|
99
134
|
onLoad(this);
|
|
100
135
|
}
|
|
101
136
|
}
|
|
102
|
-
/* eslint-enable max-statements */
|
|
103
137
|
|
|
104
|
-
loadData(opts) {
|
|
138
|
+
loadData(opts: TileLoadDataProps): Promise<void> {
|
|
105
139
|
this._isLoaded = false;
|
|
106
140
|
this._isCancelled = false;
|
|
107
141
|
this._needsReload = false;
|
|
@@ -110,7 +144,7 @@ export default class Tile2DHeader {
|
|
|
110
144
|
return this._loader;
|
|
111
145
|
}
|
|
112
146
|
|
|
113
|
-
setNeedsReload() {
|
|
147
|
+
setNeedsReload(): void {
|
|
114
148
|
if (this.isLoading) {
|
|
115
149
|
this.abort();
|
|
116
150
|
this._loader = undefined;
|
|
@@ -118,12 +152,12 @@ export default class Tile2DHeader {
|
|
|
118
152
|
this._needsReload = true;
|
|
119
153
|
}
|
|
120
154
|
|
|
121
|
-
abort() {
|
|
155
|
+
abort(): void {
|
|
122
156
|
if (this.isLoaded) {
|
|
123
157
|
return;
|
|
124
158
|
}
|
|
125
159
|
|
|
126
160
|
this._isCancelled = true;
|
|
127
|
-
this._abortController
|
|
161
|
+
this._abortController?.abort();
|
|
128
162
|
}
|
|
129
163
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable complexity */
|
|
2
|
+
import {Viewport, WebMercatorViewport, _GlobeViewport} from '@deck.gl/core';
|
|
2
3
|
import {
|
|
3
4
|
CullingVolume,
|
|
4
5
|
Plane,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
makeOrientedBoundingBoxFromPoints
|
|
7
8
|
} from '@math.gl/culling';
|
|
8
9
|
import {lngLatToWorld} from '@math.gl/web-mercator';
|
|
10
|
+
import {Bounds, TileIndex, ZRange} from './types';
|
|
9
11
|
import {osmTile2lngLat} from './utils';
|
|
10
12
|
|
|
11
13
|
const TILE_SIZE = 512;
|
|
@@ -31,6 +33,15 @@ const REF_POINTS_11 = REF_POINTS_9.concat([
|
|
|
31
33
|
]); // 2 additional points on equator for top tile
|
|
32
34
|
|
|
33
35
|
class OSMNode {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
z: number;
|
|
39
|
+
|
|
40
|
+
private childVisible?: boolean;
|
|
41
|
+
private selected?: boolean;
|
|
42
|
+
|
|
43
|
+
private _children?: OSMNode[];
|
|
44
|
+
|
|
34
45
|
constructor(x, y, z) {
|
|
35
46
|
this.x = x;
|
|
36
47
|
this.y = y;
|
|
@@ -52,7 +63,16 @@ class OSMNode {
|
|
|
52
63
|
return this._children;
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
update(params
|
|
66
|
+
update(params: {
|
|
67
|
+
viewport: Viewport;
|
|
68
|
+
project: ((xyz: number[]) => number[]) | null;
|
|
69
|
+
cullingVolume: CullingVolume;
|
|
70
|
+
elevationBounds: ZRange;
|
|
71
|
+
minZ: number;
|
|
72
|
+
maxZ: number;
|
|
73
|
+
bounds?: Bounds;
|
|
74
|
+
offset: number;
|
|
75
|
+
}) {
|
|
56
76
|
const {viewport, cullingVolume, elevationBounds, minZ, maxZ, bounds, offset, project} = params;
|
|
57
77
|
const boundingVolume = this.getBoundingVolume(elevationBounds, offset, project);
|
|
58
78
|
|
|
@@ -92,7 +112,7 @@ class OSMNode {
|
|
|
92
112
|
return true;
|
|
93
113
|
}
|
|
94
114
|
|
|
95
|
-
getSelected(result = []) {
|
|
115
|
+
getSelected(result: OSMNode[] = []): OSMNode[] {
|
|
96
116
|
if (this.selected) {
|
|
97
117
|
result.push(this);
|
|
98
118
|
}
|
|
@@ -104,7 +124,7 @@ class OSMNode {
|
|
|
104
124
|
return result;
|
|
105
125
|
}
|
|
106
126
|
|
|
107
|
-
insideBounds([minX, minY, maxX, maxY]) {
|
|
127
|
+
insideBounds([minX, minY, maxX, maxY]: Bounds): boolean {
|
|
108
128
|
const scale = Math.pow(2, this.z);
|
|
109
129
|
const extent = TILE_SIZE / scale;
|
|
110
130
|
|
|
@@ -116,7 +136,11 @@ class OSMNode {
|
|
|
116
136
|
);
|
|
117
137
|
}
|
|
118
138
|
|
|
119
|
-
getBoundingVolume(
|
|
139
|
+
getBoundingVolume(
|
|
140
|
+
zRange: ZRange,
|
|
141
|
+
worldOffset: number,
|
|
142
|
+
project: ((xyz: number[]) => number[]) | null
|
|
143
|
+
) {
|
|
120
144
|
if (project) {
|
|
121
145
|
// Custom projection
|
|
122
146
|
// Estimate bounding box from sample points
|
|
@@ -124,9 +148,9 @@ class OSMNode {
|
|
|
124
148
|
const refPoints = this.z < 1 ? REF_POINTS_11 : this.z < 2 ? REF_POINTS_9 : REF_POINTS_5;
|
|
125
149
|
|
|
126
150
|
// Convert from tile-relative coordinates to common space
|
|
127
|
-
const refPointPositions = [];
|
|
151
|
+
const refPointPositions: number[][] = [];
|
|
128
152
|
for (const p of refPoints) {
|
|
129
|
-
const lngLat = osmTile2lngLat(this.x + p[0], this.y + p[1], this.z);
|
|
153
|
+
const lngLat: number[] = osmTile2lngLat(this.x + p[0], this.y + p[1], this.z);
|
|
130
154
|
lngLat[2] = zRange[0];
|
|
131
155
|
refPointPositions.push(project(lngLat));
|
|
132
156
|
|
|
@@ -154,11 +178,20 @@ class OSMNode {
|
|
|
154
178
|
}
|
|
155
179
|
}
|
|
156
180
|
|
|
157
|
-
export function getOSMTileIndices(
|
|
158
|
-
|
|
181
|
+
export function getOSMTileIndices(
|
|
182
|
+
viewport: Viewport,
|
|
183
|
+
maxZ: number,
|
|
184
|
+
zRange: ZRange | undefined,
|
|
185
|
+
bounds?: Bounds
|
|
186
|
+
): TileIndex[] {
|
|
187
|
+
const project: ((xyz: number[]) => number[]) | null =
|
|
188
|
+
viewport instanceof _GlobeViewport && viewport.resolution
|
|
189
|
+
? // eslint-disable-next-line @typescript-eslint/unbound-method
|
|
190
|
+
viewport.projectPosition
|
|
191
|
+
: null;
|
|
159
192
|
|
|
160
193
|
// Get the culling volume of the current camera
|
|
161
|
-
const planes = Object.values(viewport.getFrustumPlanes()).map(
|
|
194
|
+
const planes: Plane[] = Object.values(viewport.getFrustumPlanes()).map(
|
|
162
195
|
({normal, distance}) => new Plane(normal.clone().negate(), distance)
|
|
163
196
|
);
|
|
164
197
|
const cullingVolume = new CullingVolume(planes);
|
|
@@ -169,7 +202,7 @@ export function getOSMTileIndices(viewport, maxZ, zRange, bounds) {
|
|
|
169
202
|
const elevationMax = (zRange && zRange[1] * unitsPerMeter) || 0;
|
|
170
203
|
|
|
171
204
|
// Always load at the current zoom level if pitch is small
|
|
172
|
-
const minZ = viewport.pitch <= 60 ? maxZ : 0;
|
|
205
|
+
const minZ = viewport instanceof WebMercatorViewport && viewport.pitch <= 60 ? maxZ : 0;
|
|
173
206
|
|
|
174
207
|
// Map extent to OSM position
|
|
175
208
|
if (bounds) {
|
|
@@ -184,7 +217,7 @@ export function getOSMTileIndices(viewport, maxZ, zRange, bounds) {
|
|
|
184
217
|
viewport,
|
|
185
218
|
project,
|
|
186
219
|
cullingVolume,
|
|
187
|
-
elevationBounds: [elevationMin, elevationMax],
|
|
220
|
+
elevationBounds: [elevationMin, elevationMax] as ZRange,
|
|
188
221
|
minZ,
|
|
189
222
|
maxZ,
|
|
190
223
|
bounds,
|
|
@@ -194,7 +227,11 @@ export function getOSMTileIndices(viewport, maxZ, zRange, bounds) {
|
|
|
194
227
|
|
|
195
228
|
root.update(traversalParams);
|
|
196
229
|
|
|
197
|
-
if (
|
|
230
|
+
if (
|
|
231
|
+
viewport instanceof WebMercatorViewport &&
|
|
232
|
+
viewport.subViewports &&
|
|
233
|
+
viewport.subViewports.length > 1
|
|
234
|
+
) {
|
|
198
235
|
// Check worlds in repeated maps
|
|
199
236
|
traversalParams.offset = -1;
|
|
200
237
|
while (root.update(traversalParams)) {
|