@deck.gl/geo-layers 8.9.22 → 8.9.24
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/LICENSE +1 -1
- package/dist/dist.dev.js +2 -1
- package/dist/es5/tile-layer/tile-layer.js +2 -1
- package/dist/es5/tile-layer/tile-layer.js.map +1 -1
- package/dist/esm/tile-layer/tile-layer.js +2 -1
- package/dist/esm/tile-layer/tile-layer.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +2 -2
- package/src/tile-layer/tile-layer.ts +2 -1
- package/typed/tile-layer/tile-layer.d.ts.map +1 -1
- package/typed/geo-cell-layer/GeoCellLayer.js +0 -49
- package/typed/great-circle-layer/great-circle-layer.js +0 -29
- package/typed/h3-layers/h3-cluster-layer.js +0 -33
- package/typed/h3-layers/h3-hexagon-layer.js +0 -251
- package/typed/imagery-layer/imagery-layer.d.ts +0 -53
- package/typed/imagery-layer/imagery-layer.d.ts.map +0 -1
- package/typed/index.js +0 -33
- package/typed/mesh-layer/mesh-layer-fragment.glsl.js +0 -55
- package/typed/mesh-layer/mesh-layer-vertex.glsl.js +0 -80
- package/typed/mesh-layer/mesh-layer.js +0 -110
- package/typed/mvt-layer/coordinate-transform.js +0 -41
- package/typed/mvt-layer/find-index-binary.js +0 -96
- package/typed/mvt-layer/mvt-layer.js +0 -297
- package/typed/quadkey-layer/quadkey-layer.js +0 -18
- package/typed/quadkey-layer/quadkey-utils.js +0 -26
- package/typed/s2-layer/s2-geometry.js +0 -123
- package/typed/s2-layer/s2-layer.js +0 -37
- package/typed/s2-layer/s2-utils.js +0 -88
- package/typed/terrain-layer/terrain-layer.js +0 -226
- package/typed/tile-3d-layer/tile-3d-layer.js +0 -294
- package/typed/tile-layer/tile-2d-header.d.ts +0 -40
- package/typed/tile-layer/tile-2d-header.d.ts.map +0 -1
- package/typed/tile-layer/tile-2d-header.js +0 -113
- package/typed/tile-layer/tile-2d-traversal.d.ts +0 -4
- package/typed/tile-layer/tile-2d-traversal.d.ts.map +0 -1
- package/typed/tile-layer/tile-2d-traversal.js +0 -181
- package/typed/tile-layer/tile-layer.js +0 -192
- package/typed/tile-layer/tileset-2d.d.ts +0 -96
- package/typed/tile-layer/tileset-2d.d.ts.map +0 -1
- package/typed/tile-layer/tileset-2d.js +0 -399
- package/typed/tile-layer/types.d.ts +0 -30
- package/typed/tile-layer/types.d.ts.map +0 -1
- package/typed/tile-layer/types.js +0 -1
- package/typed/tile-layer/utils.d.ts +0 -51
- package/typed/tile-layer/utils.d.ts.map +0 -1
- package/typed/tile-layer/utils.js +0 -197
- package/typed/trips-layer/trips-layer.js +0 -92
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
import { log } from '@deck.gl/core';
|
|
3
|
-
export default class Tile2DHeader {
|
|
4
|
-
constructor(index) {
|
|
5
|
-
this.index = index;
|
|
6
|
-
this.isVisible = false;
|
|
7
|
-
this.isSelected = false;
|
|
8
|
-
this.parent = null;
|
|
9
|
-
this.children = [];
|
|
10
|
-
this.content = null;
|
|
11
|
-
this._loader = undefined;
|
|
12
|
-
this._abortController = null;
|
|
13
|
-
this._loaderId = 0;
|
|
14
|
-
this._isLoaded = false;
|
|
15
|
-
this._isCancelled = false;
|
|
16
|
-
this._needsReload = false;
|
|
17
|
-
}
|
|
18
|
-
get data() {
|
|
19
|
-
return this.isLoading && this._loader ? this._loader.then(() => this.data) : this.content;
|
|
20
|
-
}
|
|
21
|
-
get isLoaded() {
|
|
22
|
-
return this._isLoaded && !this._needsReload;
|
|
23
|
-
}
|
|
24
|
-
get isLoading() {
|
|
25
|
-
return Boolean(this._loader) && !this._isCancelled;
|
|
26
|
-
}
|
|
27
|
-
get needsReload() {
|
|
28
|
-
return this._needsReload || this._isCancelled;
|
|
29
|
-
}
|
|
30
|
-
get byteLength() {
|
|
31
|
-
const result = this.content ? this.content.byteLength : 0;
|
|
32
|
-
if (!Number.isFinite(result)) {
|
|
33
|
-
log.error('byteLength not defined in tile data')();
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
/* eslint-disable max-statements */
|
|
38
|
-
async _loadData({ getData, requestScheduler, onLoad, onError }) {
|
|
39
|
-
const { index, id, bbox, userData, zoom } = this;
|
|
40
|
-
const loaderId = this._loaderId;
|
|
41
|
-
this._abortController = new AbortController();
|
|
42
|
-
const { signal } = this._abortController;
|
|
43
|
-
// @ts-expect-error (2345) Argument of type '(tile: any) => 1 | -1' is not assignable ...
|
|
44
|
-
const requestToken = await requestScheduler.scheduleRequest(this, tile => {
|
|
45
|
-
return tile.isSelected ? 1 : -1;
|
|
46
|
-
});
|
|
47
|
-
if (!requestToken) {
|
|
48
|
-
this._isCancelled = true;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// A tile can be cancelled while being scheduled
|
|
52
|
-
if (this._isCancelled) {
|
|
53
|
-
requestToken.done();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let tileData = null;
|
|
57
|
-
let error;
|
|
58
|
-
try {
|
|
59
|
-
tileData = await getData({ index, id, bbox, userData, zoom, signal });
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
error = err || true;
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
requestToken.done();
|
|
66
|
-
}
|
|
67
|
-
// If loadData has been called with a newer version, discard the result from this operation
|
|
68
|
-
if (loaderId !== this._loaderId) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// Clear the `isLoading` flag
|
|
72
|
-
this._loader = undefined;
|
|
73
|
-
// Rewrite tile content with the result of getTileData if successful, or `null` in case of
|
|
74
|
-
// error or cancellation
|
|
75
|
-
this.content = tileData;
|
|
76
|
-
// If cancelled, do not invoke the callbacks
|
|
77
|
-
// Consider it loaded if we tried to cancel but `getTileData` still returned data
|
|
78
|
-
if (this._isCancelled && !tileData) {
|
|
79
|
-
this._isLoaded = false;
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this._isLoaded = true;
|
|
83
|
-
this._isCancelled = false;
|
|
84
|
-
if (error) {
|
|
85
|
-
onError(error, this);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
onLoad(this);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
loadData(opts) {
|
|
92
|
-
this._isLoaded = false;
|
|
93
|
-
this._isCancelled = false;
|
|
94
|
-
this._needsReload = false;
|
|
95
|
-
this._loaderId++;
|
|
96
|
-
this._loader = this._loadData(opts);
|
|
97
|
-
return this._loader;
|
|
98
|
-
}
|
|
99
|
-
setNeedsReload() {
|
|
100
|
-
if (this.isLoading) {
|
|
101
|
-
this.abort();
|
|
102
|
-
this._loader = undefined;
|
|
103
|
-
}
|
|
104
|
-
this._needsReload = true;
|
|
105
|
-
}
|
|
106
|
-
abort() {
|
|
107
|
-
if (this.isLoaded) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this._isCancelled = true;
|
|
111
|
-
this._abortController?.abort();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Viewport } from '@deck.gl/core/typed';
|
|
2
|
-
import { Bounds, TileIndex, ZRange } from './types';
|
|
3
|
-
export declare function getOSMTileIndices(viewport: Viewport, maxZ: number, zRange: ZRange | undefined, bounds?: Bounds): TileIndex[];
|
|
4
|
-
//# sourceMappingURL=tile-2d-traversal.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tile-2d-traversal.d.ts","sourceRoot":"","sources":["../../src/tile-layer/tile-2d-traversal.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAsC,MAAM,eAAe,CAAC;AAQ5E,OAAO,EAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AA2KlD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,CAAC,EAAE,MAAM,GACd,SAAS,EAAE,CAiEb"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
|
-
import { WebMercatorViewport, _GlobeViewport } from '@deck.gl/core';
|
|
3
|
-
import { CullingVolume, Plane, AxisAlignedBoundingBox, makeOrientedBoundingBoxFromPoints } from '@math.gl/culling';
|
|
4
|
-
import { lngLatToWorld } from '@math.gl/web-mercator';
|
|
5
|
-
import { osmTile2lngLat } from './utils';
|
|
6
|
-
const TILE_SIZE = 512;
|
|
7
|
-
// number of world copies to check
|
|
8
|
-
const MAX_MAPS = 3;
|
|
9
|
-
// for calculating bounding volume of a tile in a non-web-mercator viewport
|
|
10
|
-
const REF_POINTS_5 = [
|
|
11
|
-
[0.5, 0.5],
|
|
12
|
-
[0, 0],
|
|
13
|
-
[0, 1],
|
|
14
|
-
[1, 0],
|
|
15
|
-
[1, 1]
|
|
16
|
-
]; // 4 corners and center
|
|
17
|
-
const REF_POINTS_9 = REF_POINTS_5.concat([
|
|
18
|
-
[0, 0.5],
|
|
19
|
-
[0.5, 0],
|
|
20
|
-
[1, 0.5],
|
|
21
|
-
[0.5, 1]
|
|
22
|
-
]); // 4 corners, center and 4 mid points
|
|
23
|
-
const REF_POINTS_11 = REF_POINTS_9.concat([
|
|
24
|
-
[0.25, 0.5],
|
|
25
|
-
[0.75, 0.5]
|
|
26
|
-
]); // 2 additional points on equator for top tile
|
|
27
|
-
class OSMNode {
|
|
28
|
-
constructor(x, y, z) {
|
|
29
|
-
this.x = x;
|
|
30
|
-
this.y = y;
|
|
31
|
-
this.z = z;
|
|
32
|
-
}
|
|
33
|
-
get children() {
|
|
34
|
-
if (!this._children) {
|
|
35
|
-
const x = this.x * 2;
|
|
36
|
-
const y = this.y * 2;
|
|
37
|
-
const z = this.z + 1;
|
|
38
|
-
this._children = [
|
|
39
|
-
new OSMNode(x, y, z),
|
|
40
|
-
new OSMNode(x, y + 1, z),
|
|
41
|
-
new OSMNode(x + 1, y, z),
|
|
42
|
-
new OSMNode(x + 1, y + 1, z)
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
return this._children;
|
|
46
|
-
}
|
|
47
|
-
update(params) {
|
|
48
|
-
const { viewport, cullingVolume, elevationBounds, minZ, maxZ, bounds, offset, project } = params;
|
|
49
|
-
const boundingVolume = this.getBoundingVolume(elevationBounds, offset, project);
|
|
50
|
-
// First, check if this tile is visible
|
|
51
|
-
if (bounds && !this.insideBounds(bounds)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
const isInside = cullingVolume.computeVisibility(boundingVolume);
|
|
55
|
-
if (isInside < 0) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
// Avoid loading overlapping tiles - if a descendant is requested, do not request the ancester
|
|
59
|
-
if (!this.childVisible) {
|
|
60
|
-
let { z } = this;
|
|
61
|
-
if (z < maxZ && z >= minZ) {
|
|
62
|
-
// Adjust LOD
|
|
63
|
-
// If the tile is far enough from the camera, accept a lower zoom level
|
|
64
|
-
const distance = (boundingVolume.distanceTo(viewport.cameraPosition) * viewport.scale) / viewport.height;
|
|
65
|
-
z += Math.floor(Math.log2(distance));
|
|
66
|
-
}
|
|
67
|
-
if (z >= maxZ) {
|
|
68
|
-
// LOD is acceptable
|
|
69
|
-
this.selected = true;
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// LOD is not enough, recursively test child tiles
|
|
74
|
-
this.selected = false;
|
|
75
|
-
this.childVisible = true;
|
|
76
|
-
for (const child of this.children) {
|
|
77
|
-
child.update(params);
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
getSelected(result = []) {
|
|
82
|
-
if (this.selected) {
|
|
83
|
-
result.push(this);
|
|
84
|
-
}
|
|
85
|
-
if (this._children) {
|
|
86
|
-
for (const node of this._children) {
|
|
87
|
-
node.getSelected(result);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
insideBounds([minX, minY, maxX, maxY]) {
|
|
93
|
-
const scale = Math.pow(2, this.z);
|
|
94
|
-
const extent = TILE_SIZE / scale;
|
|
95
|
-
return (this.x * extent < maxX &&
|
|
96
|
-
this.y * extent < maxY &&
|
|
97
|
-
(this.x + 1) * extent > minX &&
|
|
98
|
-
(this.y + 1) * extent > minY);
|
|
99
|
-
}
|
|
100
|
-
getBoundingVolume(zRange, worldOffset, project) {
|
|
101
|
-
if (project) {
|
|
102
|
-
// Custom projection
|
|
103
|
-
// Estimate bounding box from sample points
|
|
104
|
-
// At low zoom level we need more samples to calculate the bounding volume correctly
|
|
105
|
-
const refPoints = this.z < 1 ? REF_POINTS_11 : this.z < 2 ? REF_POINTS_9 : REF_POINTS_5;
|
|
106
|
-
// Convert from tile-relative coordinates to common space
|
|
107
|
-
const refPointPositions = [];
|
|
108
|
-
for (const p of refPoints) {
|
|
109
|
-
const lngLat = osmTile2lngLat(this.x + p[0], this.y + p[1], this.z);
|
|
110
|
-
lngLat[2] = zRange[0];
|
|
111
|
-
refPointPositions.push(project(lngLat));
|
|
112
|
-
if (zRange[0] !== zRange[1]) {
|
|
113
|
-
// Account for the elevation volume
|
|
114
|
-
lngLat[2] = zRange[1];
|
|
115
|
-
refPointPositions.push(project(lngLat));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return makeOrientedBoundingBoxFromPoints(refPointPositions);
|
|
119
|
-
}
|
|
120
|
-
// Use WebMercator projection
|
|
121
|
-
const scale = Math.pow(2, this.z);
|
|
122
|
-
const extent = TILE_SIZE / scale;
|
|
123
|
-
const originX = this.x * extent + worldOffset * TILE_SIZE;
|
|
124
|
-
// deck's common space is y-flipped
|
|
125
|
-
const originY = TILE_SIZE - (this.y + 1) * extent;
|
|
126
|
-
return new AxisAlignedBoundingBox([originX, originY, zRange[0]], [originX + extent, originY + extent, zRange[1]]);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export function getOSMTileIndices(viewport, maxZ, zRange, bounds) {
|
|
130
|
-
const project = viewport instanceof _GlobeViewport && viewport.resolution
|
|
131
|
-
? // eslint-disable-next-line @typescript-eslint/unbound-method
|
|
132
|
-
viewport.projectPosition
|
|
133
|
-
: null;
|
|
134
|
-
// Get the culling volume of the current camera
|
|
135
|
-
const planes = Object.values(viewport.getFrustumPlanes()).map(({ normal, distance }) => new Plane(normal.clone().negate(), distance));
|
|
136
|
-
const cullingVolume = new CullingVolume(planes);
|
|
137
|
-
// Project zRange from meters to common space
|
|
138
|
-
const unitsPerMeter = viewport.distanceScales.unitsPerMeter[2];
|
|
139
|
-
const elevationMin = (zRange && zRange[0] * unitsPerMeter) || 0;
|
|
140
|
-
const elevationMax = (zRange && zRange[1] * unitsPerMeter) || 0;
|
|
141
|
-
// Always load at the current zoom level if pitch is small
|
|
142
|
-
const minZ = viewport instanceof WebMercatorViewport && viewport.pitch <= 60 ? maxZ : 0;
|
|
143
|
-
// Map extent to OSM position
|
|
144
|
-
if (bounds) {
|
|
145
|
-
const [minLng, minLat, maxLng, maxLat] = bounds;
|
|
146
|
-
const topLeft = lngLatToWorld([minLng, maxLat]);
|
|
147
|
-
const bottomRight = lngLatToWorld([maxLng, minLat]);
|
|
148
|
-
bounds = [topLeft[0], TILE_SIZE - topLeft[1], bottomRight[0], TILE_SIZE - bottomRight[1]];
|
|
149
|
-
}
|
|
150
|
-
const root = new OSMNode(0, 0, 0);
|
|
151
|
-
const traversalParams = {
|
|
152
|
-
viewport,
|
|
153
|
-
project,
|
|
154
|
-
cullingVolume,
|
|
155
|
-
elevationBounds: [elevationMin, elevationMax],
|
|
156
|
-
minZ,
|
|
157
|
-
maxZ,
|
|
158
|
-
bounds,
|
|
159
|
-
// num. of worlds from the center. For repeated maps
|
|
160
|
-
offset: 0
|
|
161
|
-
};
|
|
162
|
-
root.update(traversalParams);
|
|
163
|
-
if (viewport instanceof WebMercatorViewport &&
|
|
164
|
-
viewport.subViewports &&
|
|
165
|
-
viewport.subViewports.length > 1) {
|
|
166
|
-
// Check worlds in repeated maps
|
|
167
|
-
traversalParams.offset = -1;
|
|
168
|
-
while (root.update(traversalParams)) {
|
|
169
|
-
if (--traversalParams.offset < -MAX_MAPS) {
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
traversalParams.offset = 1;
|
|
174
|
-
while (root.update(traversalParams)) {
|
|
175
|
-
if (++traversalParams.offset > MAX_MAPS) {
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return root.getSelected();
|
|
181
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { CompositeLayer, _flatten as flatten } from '@deck.gl/core';
|
|
2
|
-
import { GeoJsonLayer } from '@deck.gl/layers';
|
|
3
|
-
import Tileset2D, { STRATEGY_DEFAULT } from './tileset-2d';
|
|
4
|
-
import { urlType, getURLFromTemplate } from './utils';
|
|
5
|
-
const defaultProps = {
|
|
6
|
-
TilesetClass: Tileset2D,
|
|
7
|
-
data: [],
|
|
8
|
-
dataComparator: urlType.equals,
|
|
9
|
-
renderSubLayers: { type: 'function', value: props => new GeoJsonLayer(props), compare: false },
|
|
10
|
-
getTileData: { type: 'function', optional: true, value: null, compare: false },
|
|
11
|
-
// TODO - change to onViewportLoad to align with Tile3DLayer
|
|
12
|
-
onViewportLoad: { type: 'function', optional: true, value: null, compare: false },
|
|
13
|
-
onTileLoad: { type: 'function', value: tile => { }, compare: false },
|
|
14
|
-
onTileUnload: { type: 'function', value: tile => { }, compare: false },
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
onTileError: { type: 'function', value: err => console.error(err), compare: false },
|
|
17
|
-
extent: { type: 'array', optional: true, value: null, compare: true },
|
|
18
|
-
tileSize: 512,
|
|
19
|
-
maxZoom: null,
|
|
20
|
-
minZoom: 0,
|
|
21
|
-
maxCacheSize: null,
|
|
22
|
-
maxCacheByteSize: null,
|
|
23
|
-
refinementStrategy: STRATEGY_DEFAULT,
|
|
24
|
-
zRange: null,
|
|
25
|
-
maxRequests: 6,
|
|
26
|
-
zoomOffset: 0
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* The TileLayer is a composite layer that makes it possible to visualize very large datasets.
|
|
30
|
-
*
|
|
31
|
-
* Instead of fetching the entire dataset, it only loads and renders what's visible in the current viewport.
|
|
32
|
-
*/
|
|
33
|
-
export default class TileLayer extends CompositeLayer {
|
|
34
|
-
initializeState() {
|
|
35
|
-
this.state = {
|
|
36
|
-
tileset: null,
|
|
37
|
-
isLoaded: false
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
finalizeState() {
|
|
41
|
-
this.state?.tileset?.finalize();
|
|
42
|
-
}
|
|
43
|
-
get isLoaded() {
|
|
44
|
-
return this.state?.tileset?.selectedTiles.every(tile => tile.isLoaded && tile.layers && tile.layers.every(layer => layer.isLoaded));
|
|
45
|
-
}
|
|
46
|
-
shouldUpdateState({ changeFlags }) {
|
|
47
|
-
return changeFlags.somethingChanged;
|
|
48
|
-
}
|
|
49
|
-
updateState({ changeFlags }) {
|
|
50
|
-
let { tileset } = this.state;
|
|
51
|
-
const propsChanged = changeFlags.propsOrDataChanged || changeFlags.updateTriggersChanged;
|
|
52
|
-
const dataChanged = changeFlags.dataChanged ||
|
|
53
|
-
(changeFlags.updateTriggersChanged &&
|
|
54
|
-
(changeFlags.updateTriggersChanged.all || changeFlags.updateTriggersChanged.getTileData));
|
|
55
|
-
if (!tileset) {
|
|
56
|
-
tileset = new this.props.TilesetClass(this._getTilesetOptions());
|
|
57
|
-
this.setState({ tileset });
|
|
58
|
-
}
|
|
59
|
-
else if (propsChanged) {
|
|
60
|
-
tileset.setOptions(this._getTilesetOptions());
|
|
61
|
-
if (dataChanged) {
|
|
62
|
-
// reload all tiles
|
|
63
|
-
// use cached layers until new content is loaded
|
|
64
|
-
tileset.reloadAll();
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// some render options changed, regenerate sub layers now
|
|
68
|
-
this.state.tileset.tiles.forEach(tile => {
|
|
69
|
-
tile.layers = null;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
this._updateTileset();
|
|
74
|
-
}
|
|
75
|
-
_getTilesetOptions() {
|
|
76
|
-
const { tileSize, maxCacheSize, maxCacheByteSize, refinementStrategy, extent, maxZoom, minZoom, maxRequests, zoomOffset } = this.props;
|
|
77
|
-
return {
|
|
78
|
-
maxCacheSize,
|
|
79
|
-
maxCacheByteSize,
|
|
80
|
-
maxZoom,
|
|
81
|
-
minZoom,
|
|
82
|
-
tileSize,
|
|
83
|
-
refinementStrategy,
|
|
84
|
-
extent,
|
|
85
|
-
maxRequests,
|
|
86
|
-
zoomOffset,
|
|
87
|
-
getTileData: this.getTileData.bind(this),
|
|
88
|
-
onTileLoad: this._onTileLoad.bind(this),
|
|
89
|
-
onTileError: this._onTileError.bind(this),
|
|
90
|
-
onTileUnload: this._onTileUnload.bind(this)
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
_updateTileset() {
|
|
94
|
-
const { tileset } = this.state;
|
|
95
|
-
const { zRange, modelMatrix } = this.props;
|
|
96
|
-
const frameNumber = tileset.update(this.context.viewport, { zRange, modelMatrix });
|
|
97
|
-
const { isLoaded } = tileset;
|
|
98
|
-
const loadingStateChanged = this.state.isLoaded !== isLoaded;
|
|
99
|
-
const tilesetChanged = this.state.frameNumber !== frameNumber;
|
|
100
|
-
if (isLoaded && (loadingStateChanged || tilesetChanged)) {
|
|
101
|
-
this._onViewportLoad();
|
|
102
|
-
}
|
|
103
|
-
if (tilesetChanged) {
|
|
104
|
-
// Save the tileset frame number - trigger a rerender
|
|
105
|
-
this.setState({ frameNumber });
|
|
106
|
-
}
|
|
107
|
-
// Save the loaded state - should not trigger a rerender
|
|
108
|
-
this.state.isLoaded = isLoaded;
|
|
109
|
-
}
|
|
110
|
-
_onViewportLoad() {
|
|
111
|
-
const { tileset } = this.state;
|
|
112
|
-
const { onViewportLoad } = this.props;
|
|
113
|
-
if (onViewportLoad) {
|
|
114
|
-
onViewportLoad(tileset.selectedTiles);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
_onTileLoad(tile) {
|
|
118
|
-
this.props.onTileLoad(tile);
|
|
119
|
-
tile.layers = null;
|
|
120
|
-
this.setNeedsUpdate();
|
|
121
|
-
}
|
|
122
|
-
_onTileError(error, tile) {
|
|
123
|
-
this.props.onTileError(error);
|
|
124
|
-
tile.layers = null;
|
|
125
|
-
this.setNeedsUpdate();
|
|
126
|
-
}
|
|
127
|
-
_onTileUnload(tile) {
|
|
128
|
-
this.props.onTileUnload(tile);
|
|
129
|
-
}
|
|
130
|
-
// Methods for subclass to override
|
|
131
|
-
getTileData(tile) {
|
|
132
|
-
const { data, getTileData, fetch } = this.props;
|
|
133
|
-
const { signal } = tile;
|
|
134
|
-
tile.url =
|
|
135
|
-
typeof data === 'string' || Array.isArray(data) ? getURLFromTemplate(data, tile) : null;
|
|
136
|
-
if (getTileData) {
|
|
137
|
-
return getTileData(tile);
|
|
138
|
-
}
|
|
139
|
-
if (fetch && tile.url) {
|
|
140
|
-
return fetch(tile.url, { propName: 'data', layer: this, signal });
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
renderSubLayers(props) {
|
|
145
|
-
return this.props.renderSubLayers(props);
|
|
146
|
-
}
|
|
147
|
-
getSubLayerPropsByTile(tile) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
getPickingInfo({ info, sourceLayer }) {
|
|
151
|
-
info.tile = sourceLayer.props.tile;
|
|
152
|
-
return info;
|
|
153
|
-
}
|
|
154
|
-
_updateAutoHighlight(info) {
|
|
155
|
-
if (info.sourceLayer) {
|
|
156
|
-
info.sourceLayer.updateAutoHighlight(info);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
renderLayers() {
|
|
160
|
-
return this.state.tileset.tiles.map((tile) => {
|
|
161
|
-
const subLayerProps = this.getSubLayerPropsByTile(tile);
|
|
162
|
-
// cache the rendered layer in the tile
|
|
163
|
-
if (!tile.isLoaded && !tile.content) {
|
|
164
|
-
// nothing to show
|
|
165
|
-
}
|
|
166
|
-
else if (!tile.layers) {
|
|
167
|
-
const layers = this.renderSubLayers({
|
|
168
|
-
...this.props,
|
|
169
|
-
id: `${this.id}-${tile.id}`,
|
|
170
|
-
data: tile.content,
|
|
171
|
-
_offset: 0,
|
|
172
|
-
tile
|
|
173
|
-
});
|
|
174
|
-
tile.layers = flatten(layers, Boolean).map(layer => layer.clone({
|
|
175
|
-
tile,
|
|
176
|
-
...subLayerProps
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
else if (subLayerProps &&
|
|
180
|
-
tile.layers[0] &&
|
|
181
|
-
Object.keys(subLayerProps).some(propName => tile.layers[0].props[propName] !== subLayerProps[propName])) {
|
|
182
|
-
tile.layers = tile.layers.map(layer => layer.clone(subLayerProps));
|
|
183
|
-
}
|
|
184
|
-
return tile.layers;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
filterSubLayer({ layer }) {
|
|
188
|
-
return layer.props.tile.isVisible;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
TileLayer.defaultProps = defaultProps;
|
|
192
|
-
TileLayer.layerName = 'TileLayer';
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import Tile2DHeader from './tile-2d-header';
|
|
2
|
-
import { Matrix4 } from '@math.gl/core';
|
|
3
|
-
import { Viewport } from '@deck.gl/core/typed';
|
|
4
|
-
import { TileIndex, ZRange } from './types';
|
|
5
|
-
import { TileLayerProps } from './tile-layer';
|
|
6
|
-
export declare const STRATEGY_NEVER = "never";
|
|
7
|
-
export declare const STRATEGY_REPLACE = "no-overlap";
|
|
8
|
-
export declare const STRATEGY_DEFAULT = "best-available";
|
|
9
|
-
export declare type RefinementStrategyFunction = (tiles: Tile2DHeader[]) => void;
|
|
10
|
-
export declare type RefinementStrategy = typeof STRATEGY_NEVER | typeof STRATEGY_REPLACE | typeof STRATEGY_DEFAULT | RefinementStrategyFunction;
|
|
11
|
-
export declare type Tileset2DProps = Pick<Required<TileLayerProps>, 'tileSize' | 'maxCacheSize' | 'maxCacheByteSize' | 'refinementStrategy' | 'extent' | 'maxZoom' | 'minZoom' | 'maxRequests' | 'zoomOffset'> & {
|
|
12
|
-
getTileData: NonNullable<TileLayerProps['getTileData']>;
|
|
13
|
-
onTileLoad: (tile: Tile2DHeader) => void;
|
|
14
|
-
onTileUnload: (tile: Tile2DHeader) => void;
|
|
15
|
-
onTileError: (error: any, tile: Tile2DHeader) => void;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Manages loading and purging of tile data. This class caches recently visited tiles
|
|
19
|
-
* and only creates new tiles if they are present.
|
|
20
|
-
*/
|
|
21
|
-
export default class Tileset2D {
|
|
22
|
-
private opts;
|
|
23
|
-
private _requestScheduler;
|
|
24
|
-
private _cache;
|
|
25
|
-
private _dirty;
|
|
26
|
-
private _tiles;
|
|
27
|
-
private _cacheByteSize;
|
|
28
|
-
private _viewport;
|
|
29
|
-
private _zRange?;
|
|
30
|
-
private _selectedTiles;
|
|
31
|
-
private _frameNumber;
|
|
32
|
-
private _modelMatrix;
|
|
33
|
-
private _modelMatrixInverse;
|
|
34
|
-
private _maxZoom?;
|
|
35
|
-
private _minZoom?;
|
|
36
|
-
private onTileLoad;
|
|
37
|
-
/**
|
|
38
|
-
* Takes in a function that returns tile data, a cache size, and a max and a min zoom level.
|
|
39
|
-
* Cache size defaults to 5 * number of tiles in the current viewport
|
|
40
|
-
*/
|
|
41
|
-
constructor(opts: Tileset2DProps);
|
|
42
|
-
get tiles(): Tile2DHeader<any>[];
|
|
43
|
-
get selectedTiles(): Tile2DHeader[] | null;
|
|
44
|
-
get isLoaded(): boolean;
|
|
45
|
-
get needsReload(): boolean;
|
|
46
|
-
setOptions(opts: Tileset2DProps): void;
|
|
47
|
-
finalize(): void;
|
|
48
|
-
reloadAll(): void;
|
|
49
|
-
/**
|
|
50
|
-
* Update the cache with the given viewport and model matrix and triggers callback onUpdate.
|
|
51
|
-
*/
|
|
52
|
-
update(viewport: Viewport, { zRange, modelMatrix }?: {
|
|
53
|
-
zRange?: ZRange;
|
|
54
|
-
modelMatrix?: Matrix4;
|
|
55
|
-
}): number;
|
|
56
|
-
isTileVisible(tile: Tile2DHeader, cullRect?: {
|
|
57
|
-
x: number;
|
|
58
|
-
y: number;
|
|
59
|
-
width: number;
|
|
60
|
-
height: number;
|
|
61
|
-
}): boolean;
|
|
62
|
-
/** Returns array of tile indices in the current viewport */
|
|
63
|
-
getTileIndices({ viewport, maxZoom, minZoom, zRange, modelMatrix, modelMatrixInverse }: {
|
|
64
|
-
viewport: Viewport;
|
|
65
|
-
maxZoom?: number;
|
|
66
|
-
minZoom?: number;
|
|
67
|
-
zRange: ZRange | undefined;
|
|
68
|
-
tileSize?: number;
|
|
69
|
-
modelMatrix?: Matrix4;
|
|
70
|
-
modelMatrixInverse?: Matrix4;
|
|
71
|
-
zoomOffset?: number;
|
|
72
|
-
}): TileIndex[];
|
|
73
|
-
/** Returns unique string key for a tile index */
|
|
74
|
-
getTileId(index: TileIndex): string;
|
|
75
|
-
/** Returns a zoom level for a tile index */
|
|
76
|
-
getTileZoom(index: TileIndex): number;
|
|
77
|
-
/** Returns additional metadata to add to tile, bbox by default */
|
|
78
|
-
getTileMetadata(index: TileIndex): Record<string, any>;
|
|
79
|
-
/** Returns index of the parent tile */
|
|
80
|
-
getParentIndex(index: TileIndex): {
|
|
81
|
-
x: number;
|
|
82
|
-
y: number;
|
|
83
|
-
z: number;
|
|
84
|
-
};
|
|
85
|
-
private updateTileStates;
|
|
86
|
-
private _getCullBounds;
|
|
87
|
-
private _pruneRequests;
|
|
88
|
-
private _rebuildTree;
|
|
89
|
-
/**
|
|
90
|
-
* Clear tiles that are not visible when the cache is full
|
|
91
|
-
*/
|
|
92
|
-
private _resizeCache;
|
|
93
|
-
private _getTile;
|
|
94
|
-
_getNearestAncestor(tile: Tile2DHeader): Tile2DHeader | null;
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=tileset-2d.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tileset-2d.d.ts","sourceRoot":"","sources":["../../src/tile-layer/tileset-2d.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAC,OAAO,EAAS,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAS,SAAS,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAyB5C,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD,oBAAY,0BAA0B,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;AACzE,oBAAY,kBAAkB,GAC1B,OAAO,cAAc,GACrB,OAAO,gBAAgB,GACvB,OAAO,gBAAgB,GACvB,0BAA0B,CAAC;AAU/B,oBAAY,cAAc,GAAG,IAAI,CAC/B,QAAQ,CAAC,cAAc,CAAC,EACtB,UAAU,GACV,cAAc,GACd,kBAAkB,GAClB,oBAAoB,GACpB,QAAQ,GACR,SAAS,GACT,SAAS,GACT,aAAa,GACb,YAAY,CACf,GAAG;IACF,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC;IACxD,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,KAAK,EAAE,GAAG,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