@deck.gl/geo-layers 8.8.0-alpha.3 → 8.8.0-alpha.6
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 +837 -20701
- 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/coordinate-transform.js.map +1 -1
- package/dist/es5/mvt-layer/find-index-binary.js +7 -5
- package/dist/es5/mvt-layer/find-index-binary.js.map +1 -1
- package/dist/es5/mvt-layer/mvt-layer.js +35 -25
- package/dist/es5/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/es5/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/es5/tile-layer/tile-2d-header.js.map +1 -1
- package/dist/es5/tile-layer/tile-layer.js +0 -4
- package/dist/es5/tile-layer/tile-layer.js.map +1 -1
- package/dist/es5/tile-layer/tileset-2d.js +1 -6
- package/dist/es5/tile-layer/tileset-2d.js.map +1 -1
- package/dist/es5/tile-layer/utils.js +5 -0
- package/dist/es5/tile-layer/utils.js.map +1 -1
- 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/coordinate-transform.js.map +1 -1
- package/dist/esm/mvt-layer/find-index-binary.js +1 -1
- package/dist/esm/mvt-layer/find-index-binary.js.map +1 -1
- package/dist/esm/mvt-layer/mvt-layer.js +40 -33
- package/dist/esm/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/esm/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/esm/tile-layer/tile-2d-header.js.map +1 -1
- package/dist/esm/tile-layer/tile-layer.js +1 -5
- package/dist/esm/tile-layer/tile-layer.js.map +1 -1
- package/dist/esm/tile-layer/tileset-2d.js +1 -5
- package/dist/esm/tile-layer/tileset-2d.js.map +1 -1
- package/dist/esm/tile-layer/utils.js +3 -0
- package/dist/esm/tile-layer/utils.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +9 -6
- package/src/geo-cell-layer/GeoCellLayer.ts +3 -2
- package/src/index.ts +4 -1
- package/src/mvt-layer/{coordinate-transform.js → coordinate-transform.ts} +10 -8
- package/src/mvt-layer/{find-index-binary.js → find-index-binary.ts} +41 -10
- package/src/mvt-layer/{mvt-layer.js → mvt-layer.ts} +143 -58
- package/src/quadkey-layer/quadkey-layer.ts +7 -6
- package/src/tile-layer/tile-2d-header.ts +15 -14
- package/src/tile-layer/tile-layer.ts +28 -29
- package/src/tile-layer/tileset-2d.ts +14 -14
- package/src/tile-layer/types.ts +5 -1
- package/src/tile-layer/utils.ts +10 -1
- package/typed/geo-cell-layer/GeoCellLayer.d.ts +47 -0
- package/typed/geo-cell-layer/GeoCellLayer.d.ts.map +1 -0
- package/typed/great-circle-layer/great-circle-layer.d.ts +15 -0
- package/typed/great-circle-layer/great-circle-layer.d.ts.map +1 -0
- package/typed/h3-layers/h3-cluster-layer.d.ts +16 -0
- package/typed/h3-layers/h3-cluster-layer.d.ts.map +1 -0
- package/typed/h3-layers/h3-hexagon-layer.d.ts +107 -0
- package/typed/h3-layers/h3-hexagon-layer.d.ts.map +1 -0
- package/typed/index.d.ts +19 -0
- package/typed/index.d.ts.map +1 -0
- package/typed/mesh-layer/mesh-layer-fragment.glsl.d.ts +3 -0
- package/typed/mesh-layer/mesh-layer-fragment.glsl.d.ts.map +1 -0
- package/typed/mesh-layer/mesh-layer-vertex.glsl.d.ts +3 -0
- package/typed/mesh-layer/mesh-layer-vertex.glsl.d.ts.map +1 -0
- package/typed/mesh-layer/mesh-layer.d.ts +27 -0
- package/typed/mesh-layer/mesh-layer.d.ts.map +1 -0
- package/typed/mvt-layer/coordinate-transform.d.ts +4 -0
- package/typed/mvt-layer/coordinate-transform.d.ts.map +1 -0
- package/typed/mvt-layer/find-index-binary.d.ts +12 -0
- package/typed/mvt-layer/find-index-binary.d.ts.map +1 -0
- package/typed/mvt-layer/mvt-layer.d.ts +102 -0
- package/typed/mvt-layer/mvt-layer.d.ts.map +1 -0
- package/typed/package.json +6 -0
- package/typed/quadkey-layer/quadkey-layer.d.ts +20 -0
- package/typed/quadkey-layer/quadkey-layer.d.ts.map +1 -0
- package/typed/quadkey-layer/quadkey-utils.d.ts +3 -0
- package/typed/quadkey-layer/quadkey-utils.d.ts.map +1 -0
- package/typed/s2-layer/s2-geometry.d.ts +11 -0
- package/typed/s2-layer/s2-geometry.d.ts.map +1 -0
- package/typed/s2-layer/s2-layer.d.ts +16 -0
- package/typed/s2-layer/s2-layer.d.ts.map +1 -0
- package/typed/s2-layer/s2-utils.d.ts +10 -0
- package/typed/s2-layer/s2-utils.d.ts.map +1 -0
- package/typed/terrain-layer/terrain-layer.d.ts +28 -0
- package/typed/terrain-layer/terrain-layer.d.ts.map +1 -0
- package/typed/tile-3d-layer/tile-3d-layer.d.ts +70 -0
- package/typed/tile-3d-layer/tile-3d-layer.d.ts.map +1 -0
- package/typed/tile-layer/tile-2d-header.d.ts +40 -0
- package/typed/tile-layer/tile-2d-header.d.ts.map +1 -0
- package/typed/tile-layer/tile-2d-traversal.d.ts +4 -0
- package/typed/tile-layer/tile-2d-traversal.d.ts.map +1 -0
- package/typed/tile-layer/tile-layer.d.ts +118 -0
- package/typed/tile-layer/tile-layer.d.ts.map +1 -0
- package/typed/tile-layer/tileset-2d.d.ts +87 -0
- package/typed/tile-layer/tileset-2d.d.ts.map +1 -0
- package/typed/tile-layer/types.d.ts +29 -0
- package/typed/tile-layer/types.d.ts.map +1 -0
- package/typed/tile-layer/utils.d.ts +37 -0
- package/typed/tile-layer/utils.d.ts.map +1 -0
- package/typed/trips-layer/trips-layer.d.ts +32 -0
- package/typed/trips-layer/trips-layer.d.ts.map +1 -0
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.8.0-alpha.
|
|
5
|
+
"version": "8.8.0-alpha.6",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
23
|
"src",
|
|
24
|
+
"typed",
|
|
24
25
|
"dist.min.js"
|
|
25
26
|
],
|
|
26
27
|
"sideEffects": false,
|
|
@@ -33,12 +34,14 @@
|
|
|
33
34
|
"@loaders.gl/gis": "^3.2.0-alpha.4",
|
|
34
35
|
"@loaders.gl/loader-utils": "^3.2.0-alpha.4",
|
|
35
36
|
"@loaders.gl/mvt": "^3.2.0-alpha.4",
|
|
37
|
+
"@loaders.gl/schema": "^3.2.0-alpha.4",
|
|
36
38
|
"@loaders.gl/terrain": "^3.2.0-alpha.4",
|
|
37
39
|
"@loaders.gl/tiles": "^3.2.0-alpha.4",
|
|
38
|
-
"@luma.gl/experimental": "^8.5.
|
|
39
|
-
"@math.gl/core": "3.6.0-alpha.
|
|
40
|
-
"@math.gl/culling": "3.6.0-alpha.
|
|
41
|
-
"@math.gl/web-mercator": "3.6.0-alpha.
|
|
40
|
+
"@luma.gl/experimental": "^8.5.13",
|
|
41
|
+
"@math.gl/core": "3.6.0-alpha.8",
|
|
42
|
+
"@math.gl/culling": "3.6.0-alpha.8",
|
|
43
|
+
"@math.gl/web-mercator": "3.6.0-alpha.8",
|
|
44
|
+
"@types/geojson": "^7946.0.8",
|
|
42
45
|
"h3-js": "^3.6.0",
|
|
43
46
|
"long": "^3.2.0"
|
|
44
47
|
},
|
|
@@ -49,5 +52,5 @@
|
|
|
49
52
|
"@deck.gl/mesh-layers": "^8.0.0",
|
|
50
53
|
"@loaders.gl/core": "^3.0.0"
|
|
51
54
|
},
|
|
52
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "6885ccab01c91a7632385f566c9377f8ae387e7c"
|
|
53
56
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {CompositeLayer, Layer, LayersList} from '@deck.gl/core';
|
|
1
|
+
import {CompositeLayer, CompositeLayerProps, Layer, LayersList} from '@deck.gl/core';
|
|
2
2
|
import {PolygonLayer, PolygonLayerProps} from '@deck.gl/layers';
|
|
3
3
|
|
|
4
4
|
const defaultProps = {
|
|
5
5
|
...PolygonLayer.defaultProps
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** All properties supported by GeoCellLayer. */
|
|
9
|
+
export type GeoCellLayerProps<DataT = any> = PolygonLayerProps<DataT> & CompositeLayerProps<DataT>;
|
|
9
10
|
|
|
10
11
|
export default class GeoCellLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<
|
|
11
12
|
Required<GeoCellLayerProps<DataT>> & ExtraProps
|
package/src/index.ts
CHANGED
|
@@ -32,8 +32,11 @@ export {default as MVTLayer} from './mvt-layer/mvt-layer';
|
|
|
32
32
|
|
|
33
33
|
export {getURLFromTemplate as _getURLFromTemplate} from './tile-layer/utils';
|
|
34
34
|
export {default as _Tileset2D} from './tile-layer/tileset-2d';
|
|
35
|
+
export {default as _Tile2DHeader} from './tile-layer/tile-2d-header';
|
|
35
36
|
|
|
36
37
|
// Types
|
|
37
|
-
|
|
38
38
|
export type {TileLayerProps} from './tile-layer/tile-layer';
|
|
39
|
+
export type {GeoBoundingBox} from './tile-layer/types';
|
|
39
40
|
export type {QuadkeyLayerProps} from './quadkey-layer/quadkey-layer';
|
|
41
|
+
export type {TileLoadProps as _TileLoadProps} from './tile-layer/types';
|
|
42
|
+
export type {MVTLayerProps} from './mvt-layer/mvt-layer';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import {Viewport} from '@deck.gl/core';
|
|
1
2
|
import {lerp} from '@math.gl/core';
|
|
3
|
+
import {GeoBoundingBox} from '../tile-layer/types';
|
|
2
4
|
|
|
3
5
|
const availableTransformations = {
|
|
4
6
|
Point,
|
|
@@ -9,38 +11,38 @@ const availableTransformations = {
|
|
|
9
11
|
MultiPolygon
|
|
10
12
|
};
|
|
11
13
|
|
|
12
|
-
function Point([pointX, pointY], [nw, se], viewport) {
|
|
14
|
+
function Point([pointX, pointY]: [number, number], [nw, se]: number[][], viewport: Viewport) {
|
|
13
15
|
const x = lerp(nw[0], se[0], pointX);
|
|
14
16
|
const y = lerp(nw[1], se[1], pointY);
|
|
15
17
|
|
|
16
18
|
return viewport.unprojectFlat([x, y]);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
function getPoints(geometry, bbox, viewport) {
|
|
21
|
+
function getPoints(geometry, bbox: number[][], viewport: Viewport) {
|
|
20
22
|
return geometry.map(g => Point(g, bbox, viewport));
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
function MultiPoint(multiPoint, bbox, viewport) {
|
|
25
|
+
function MultiPoint(multiPoint, bbox: number[][], viewport: Viewport) {
|
|
24
26
|
return getPoints(multiPoint, bbox, viewport);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
function LineString(line, bbox, viewport) {
|
|
29
|
+
function LineString(line, bbox: number[][], viewport: Viewport) {
|
|
28
30
|
return getPoints(line, bbox, viewport);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function MultiLineString(multiLineString, bbox, viewport) {
|
|
33
|
+
function MultiLineString(multiLineString, bbox: number[][], viewport: Viewport) {
|
|
32
34
|
return multiLineString.map(lineString => LineString(lineString, bbox, viewport));
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function Polygon(polygon, bbox, viewport) {
|
|
37
|
+
function Polygon(polygon, bbox: number[][], viewport: Viewport) {
|
|
36
38
|
return polygon.map(polygonRing => getPoints(polygonRing, bbox, viewport));
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
function MultiPolygon(multiPolygon, bbox, viewport) {
|
|
41
|
+
function MultiPolygon(multiPolygon, bbox: number[][], viewport: Viewport) {
|
|
40
42
|
return multiPolygon.map(polygon => Polygon(polygon, bbox, viewport));
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
export function transform(geometry, bbox, viewport) {
|
|
45
|
+
export function transform(geometry, bbox: GeoBoundingBox, viewport: Viewport) {
|
|
44
46
|
const nw = viewport.projectFlat([bbox.west, bbox.north]);
|
|
45
47
|
const se = viewport.projectFlat([bbox.east, bbox.south]);
|
|
46
48
|
const projectedBbox = [nw, se];
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BinaryFeatures,
|
|
3
|
+
BinaryLineFeatures,
|
|
4
|
+
BinaryPointFeatures,
|
|
5
|
+
BinaryPolygonFeatures
|
|
6
|
+
} from '@loaders.gl/schema';
|
|
7
|
+
|
|
8
|
+
type FeatureTypes = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures;
|
|
9
|
+
|
|
1
10
|
const GEOM_TYPES = ['points', 'lines', 'polygons'];
|
|
2
11
|
/**
|
|
3
12
|
* Return the index of feature (numericProps or featureIds) for given feature id
|
|
@@ -8,7 +17,12 @@ const GEOM_TYPES = ['points', 'lines', 'polygons'];
|
|
|
8
17
|
* @param {Number|String} featureId - feature id to find
|
|
9
18
|
* @param {String} layerName - the layer to search in
|
|
10
19
|
*/
|
|
11
|
-
export default function findIndexBinary(
|
|
20
|
+
export default function findIndexBinary(
|
|
21
|
+
data: BinaryFeatures,
|
|
22
|
+
uniqueIdProperty: string,
|
|
23
|
+
featureId: string | number,
|
|
24
|
+
layerName: string
|
|
25
|
+
): number {
|
|
12
26
|
for (const gt of GEOM_TYPES) {
|
|
13
27
|
const index = data[gt] && findIndexByType(data[gt], uniqueIdProperty, featureId, layerName);
|
|
14
28
|
if (index >= 0) {
|
|
@@ -19,7 +33,12 @@ export default function findIndexBinary(data, uniqueIdProperty, featureId, layer
|
|
|
19
33
|
return -1;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
|
-
function findIndexByType(
|
|
36
|
+
function findIndexByType(
|
|
37
|
+
geomData: FeatureTypes,
|
|
38
|
+
uniqueIdProperty: string,
|
|
39
|
+
featureId: string | number,
|
|
40
|
+
layerName: string
|
|
41
|
+
): number {
|
|
23
42
|
const featureIds = geomData.featureIds.value;
|
|
24
43
|
|
|
25
44
|
if (!featureIds.length) {
|
|
@@ -53,10 +72,10 @@ function findIndexByType(geomData, uniqueIdProperty, featureId, layerName) {
|
|
|
53
72
|
startFeatureIndex,
|
|
54
73
|
endFeatureIndex
|
|
55
74
|
);
|
|
56
|
-
} else {
|
|
75
|
+
} else if (geomData.fields) {
|
|
57
76
|
featureIndex = findIndex(
|
|
58
77
|
geomData.fields,
|
|
59
|
-
elem => elem.id === featureId,
|
|
78
|
+
(elem: any) => elem.id === featureId,
|
|
60
79
|
startFeatureIndex,
|
|
61
80
|
endFeatureIndex
|
|
62
81
|
);
|
|
@@ -64,15 +83,22 @@ function findIndexByType(geomData, uniqueIdProperty, featureId, layerName) {
|
|
|
64
83
|
return featureIndex >= 0 ? getGlobalFeatureId(geomData, featureIndex) : -1;
|
|
65
84
|
}
|
|
66
85
|
|
|
86
|
+
type LayerRange = [firstFeatureIndex: number, lastFeatureIndex: number];
|
|
87
|
+
|
|
67
88
|
// Returns [firstFeatureIndex, lastFeatureIndex]
|
|
68
89
|
// MVTLoader parses tiles layer-by-layer, so each layer is a continuous range
|
|
69
|
-
function getLayerRange(
|
|
90
|
+
function getLayerRange(
|
|
91
|
+
geomData: FeatureTypes & {
|
|
92
|
+
__layers?: Record<string, LayerRange>;
|
|
93
|
+
},
|
|
94
|
+
layerName: string
|
|
95
|
+
): LayerRange | undefined {
|
|
70
96
|
if (!geomData.__layers) {
|
|
71
97
|
// Cache a map from properties.layerName to index ranges
|
|
72
|
-
const layerNames = {};
|
|
98
|
+
const layerNames: Record<string, LayerRange> = {};
|
|
73
99
|
const {properties} = geomData;
|
|
74
100
|
for (let i = 0; i < properties.length; i++) {
|
|
75
|
-
const {layerName: key} = properties[i]
|
|
101
|
+
const {layerName: key} = properties[i] as Record<string, any>;
|
|
76
102
|
if (!key) {
|
|
77
103
|
// ignore
|
|
78
104
|
} else if (layerNames[key]) {
|
|
@@ -87,10 +113,10 @@ function getLayerRange(geomData, layerName) {
|
|
|
87
113
|
}
|
|
88
114
|
|
|
89
115
|
// Returns global feature id
|
|
90
|
-
function getGlobalFeatureId(geomData, featureIndex) {
|
|
116
|
+
function getGlobalFeatureId(geomData, featureIndex: number) {
|
|
91
117
|
if (!geomData.__ids) {
|
|
92
118
|
// Cache a map from featureId to globalFeatureId
|
|
93
|
-
const result = [];
|
|
119
|
+
const result: string[] = [];
|
|
94
120
|
const featureIds = geomData.featureIds.value;
|
|
95
121
|
const globalFeatureIds = geomData.globalFeatureIds.value;
|
|
96
122
|
for (let i = 0; i < featureIds.length; i++) {
|
|
@@ -102,7 +128,12 @@ function getGlobalFeatureId(geomData, featureIndex) {
|
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
// Like array.findIndex, but only search within a range
|
|
105
|
-
function findIndex(
|
|
131
|
+
function findIndex<T>(
|
|
132
|
+
array: T[],
|
|
133
|
+
predicate: (v: T, index: number) => boolean,
|
|
134
|
+
startIndex: number,
|
|
135
|
+
endIndex: number
|
|
136
|
+
): number {
|
|
106
137
|
for (let i = startIndex; i < endIndex; i++) {
|
|
107
138
|
if (predicate(array[i], i)) {
|
|
108
139
|
return i;
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Layer,
|
|
3
|
+
LayersList,
|
|
4
|
+
log,
|
|
5
|
+
PickingInfo,
|
|
6
|
+
UpdateParameters,
|
|
7
|
+
GetPickingInfoParams,
|
|
8
|
+
Viewport,
|
|
9
|
+
COORDINATE_SYSTEM
|
|
10
|
+
} from '@deck.gl/core';
|
|
11
|
+
import {GeoJsonLayer, GeoJsonLayerProps} from '@deck.gl/layers';
|
|
2
12
|
import {Matrix4} from '@math.gl/core';
|
|
3
13
|
import {MVTWorkerLoader} from '@loaders.gl/mvt';
|
|
4
14
|
import {binaryToGeojson} from '@loaders.gl/gis';
|
|
5
|
-
import {COORDINATE_SYSTEM} from '@deck.gl/core';
|
|
6
15
|
import {ClipExtension} from '@deck.gl/extensions';
|
|
7
16
|
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
17
|
+
import type {Loader} from '@loaders.gl/loader-utils';
|
|
18
|
+
import type {BinaryFeatures} from '@loaders.gl/schema';
|
|
19
|
+
import type {Feature} from 'geojson';
|
|
20
|
+
|
|
21
|
+
import TileLayer, {TiledPickingInfo, TileLayerProps} from '../tile-layer/tile-layer';
|
|
22
|
+
import Tileset2D, {Tileset2DProps} from '../tile-layer/tileset-2d';
|
|
23
|
+
import {getURLFromTemplate, isGeoBoundingBox, isURLTemplate} from '../tile-layer/utils';
|
|
24
|
+
import {GeoBoundingBox, TileLoadProps} from '../tile-layer/types';
|
|
25
|
+
import Tile2DHeader from '../tile-layer/tile-2d-header';
|
|
10
26
|
import {transform} from './coordinate-transform';
|
|
11
27
|
import findIndexBinary from './find-index-binary';
|
|
12
28
|
|
|
13
|
-
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
14
|
-
|
|
15
29
|
const WORLD_SIZE = 512;
|
|
16
30
|
|
|
17
31
|
const defaultProps = {
|
|
@@ -22,8 +36,61 @@ const defaultProps = {
|
|
|
22
36
|
binary: true
|
|
23
37
|
};
|
|
24
38
|
|
|
25
|
-
export
|
|
26
|
-
|
|
39
|
+
export type TileJson = {
|
|
40
|
+
tilejson: string;
|
|
41
|
+
tiles: string[];
|
|
42
|
+
// eslint-disable-next-line camelcase
|
|
43
|
+
vector_layers: any[];
|
|
44
|
+
attribution?: string;
|
|
45
|
+
scheme?: string;
|
|
46
|
+
maxzoom?: number;
|
|
47
|
+
minzoom?: number;
|
|
48
|
+
version?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type ParsedMvtTile = Feature[] | BinaryFeatures;
|
|
52
|
+
|
|
53
|
+
/** All props supported by the MVTLayer */
|
|
54
|
+
export type MVTLayerProps<DataT extends Feature = Feature> = _MVTLayerProps &
|
|
55
|
+
GeoJsonLayerProps<DataT> &
|
|
56
|
+
TileLayerProps<ParsedMvtTile>;
|
|
57
|
+
|
|
58
|
+
/** Props added by the MVTLayer */
|
|
59
|
+
export type _MVTLayerProps = {
|
|
60
|
+
/** Called if `data` is a TileJSON URL when it is successfully fetched. */
|
|
61
|
+
onDataLoad?: ((tilejson: TileJson | null) => void) | null;
|
|
62
|
+
|
|
63
|
+
/** Needed for highlighting a feature split across two or more tiles. */
|
|
64
|
+
uniqueIdProperty?: string;
|
|
65
|
+
|
|
66
|
+
/** A feature with ID corresponding to the supplied value will be highlighted. */
|
|
67
|
+
highlightedFeatureId?: string | null;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Use tile data in binary format.
|
|
71
|
+
*
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
binary?: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Loaders used to transform tiles into `data` property passed to `renderSubLayers`.
|
|
78
|
+
*
|
|
79
|
+
* @default [MVTWorkerLoader] from `@loaders.gl/mvt`
|
|
80
|
+
*/
|
|
81
|
+
loaders?: Loader[];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
type ContentWGS84Cache = {_contentWGS84?: Feature[]};
|
|
85
|
+
|
|
86
|
+
export default class MVTLayer<DataT extends Feature = Feature, ExtraProps = {}> extends TileLayer<
|
|
87
|
+
ParsedMvtTile,
|
|
88
|
+
Required<_MVTLayerProps> & ExtraProps
|
|
89
|
+
> {
|
|
90
|
+
static layerName = 'MVTLayer';
|
|
91
|
+
static defaultProps = defaultProps;
|
|
92
|
+
|
|
93
|
+
initializeState(): void {
|
|
27
94
|
super.initializeState();
|
|
28
95
|
// GlobeView doesn't work well with binary data
|
|
29
96
|
const binary = this.context.viewport.resolution !== undefined ? false : this.props.binary;
|
|
@@ -34,16 +101,17 @@ export default class MVTLayer extends TileLayer {
|
|
|
34
101
|
});
|
|
35
102
|
}
|
|
36
103
|
|
|
37
|
-
get isLoaded() {
|
|
38
|
-
return this.state.data && this.state.tileset && super.isLoaded;
|
|
104
|
+
get isLoaded(): boolean {
|
|
105
|
+
return this.state && this.state.data && this.state.tileset && super.isLoaded;
|
|
39
106
|
}
|
|
40
107
|
|
|
41
|
-
updateState({props, oldProps, context, changeFlags}) {
|
|
108
|
+
updateState({props, oldProps, context, changeFlags}: UpdateParameters<this>) {
|
|
42
109
|
if (changeFlags.dataChanged) {
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
43
111
|
this._updateTileData();
|
|
44
112
|
}
|
|
45
113
|
|
|
46
|
-
if (this.state
|
|
114
|
+
if (this.state?.data) {
|
|
47
115
|
super.updateState({props, oldProps, context, changeFlags});
|
|
48
116
|
this._setWGS84PropertyForTiles();
|
|
49
117
|
}
|
|
@@ -54,22 +122,22 @@ export default class MVTLayer extends TileLayer {
|
|
|
54
122
|
}
|
|
55
123
|
|
|
56
124
|
/* eslint-disable complexity */
|
|
57
|
-
async _updateTileData() {
|
|
58
|
-
let
|
|
59
|
-
let tileJSON = null;
|
|
125
|
+
private async _updateTileData(): Promise<void> {
|
|
126
|
+
let data: any = this.props.data;
|
|
127
|
+
let tileJSON: any = null;
|
|
60
128
|
|
|
61
129
|
if (typeof data === 'string' && !isURLTemplate(data)) {
|
|
62
130
|
const {onDataLoad, fetch} = this.props;
|
|
63
131
|
this.setState({data: null, tileJSON: null});
|
|
64
132
|
try {
|
|
65
133
|
tileJSON = await fetch(data, {propName: 'data', layer: this, loaders: []});
|
|
66
|
-
} catch (error) {
|
|
134
|
+
} catch (error: any) {
|
|
67
135
|
this.raiseError(error, 'loading TileJSON');
|
|
68
136
|
data = null;
|
|
69
137
|
}
|
|
70
138
|
|
|
71
139
|
if (onDataLoad) {
|
|
72
|
-
onDataLoad(tileJSON);
|
|
140
|
+
onDataLoad(tileJSON, {propName: 'data', layer: this});
|
|
73
141
|
}
|
|
74
142
|
} else if (data.tilejson) {
|
|
75
143
|
tileJSON = data;
|
|
@@ -82,21 +150,21 @@ export default class MVTLayer extends TileLayer {
|
|
|
82
150
|
this.setState({data, tileJSON});
|
|
83
151
|
}
|
|
84
152
|
|
|
85
|
-
_getTilesetOptions() {
|
|
153
|
+
_getTilesetOptions(): Tileset2DProps {
|
|
86
154
|
const opts = super._getTilesetOptions();
|
|
87
|
-
const
|
|
155
|
+
const tileJSON: TileJson | null | undefined = this.state.tileJSON;
|
|
88
156
|
const {minZoom, maxZoom} = this.props;
|
|
89
157
|
|
|
90
158
|
if (tileJSON) {
|
|
91
|
-
if (Number.isFinite(tileJSON.minzoom) && tileJSON.minzoom > minZoom) {
|
|
92
|
-
opts.minZoom = tileJSON.minzoom;
|
|
159
|
+
if (Number.isFinite(tileJSON.minzoom) && (tileJSON.minzoom as number) > (minZoom as number)) {
|
|
160
|
+
opts.minZoom = tileJSON.minzoom as number;
|
|
93
161
|
}
|
|
94
162
|
|
|
95
163
|
if (
|
|
96
164
|
Number.isFinite(tileJSON.maxzoom) &&
|
|
97
|
-
(!Number.isFinite(maxZoom) || tileJSON.maxzoom < maxZoom)
|
|
165
|
+
(!Number.isFinite(maxZoom) || (tileJSON.maxzoom as number) < (maxZoom as number))
|
|
98
166
|
) {
|
|
99
|
-
opts.maxZoom = tileJSON.maxzoom;
|
|
167
|
+
opts.maxZoom = tileJSON.maxzoom as number;
|
|
100
168
|
}
|
|
101
169
|
}
|
|
102
170
|
return opts;
|
|
@@ -104,20 +172,21 @@ export default class MVTLayer extends TileLayer {
|
|
|
104
172
|
|
|
105
173
|
/* eslint-disable complexity */
|
|
106
174
|
|
|
107
|
-
renderLayers() {
|
|
108
|
-
if (!this.state
|
|
175
|
+
renderLayers(): Layer | null | LayersList {
|
|
176
|
+
if (!this.state?.data) return null;
|
|
109
177
|
return super.renderLayers();
|
|
110
178
|
}
|
|
111
179
|
|
|
112
|
-
getTileData(
|
|
113
|
-
const
|
|
180
|
+
getTileData(loadProps: TileLoadProps): Promise<ParsedMvtTile> {
|
|
181
|
+
const {data, binary} = this.state;
|
|
182
|
+
const {index, signal} = loadProps;
|
|
183
|
+
|
|
184
|
+
const url = getURLFromTemplate(data, loadProps);
|
|
114
185
|
if (!url) {
|
|
115
186
|
return Promise.reject('Invalid URL');
|
|
116
187
|
}
|
|
117
188
|
let loadOptions = this.getLoadOptions();
|
|
118
|
-
const {binary} = this.state;
|
|
119
189
|
const {fetch} = this.props;
|
|
120
|
-
const {signal, index} = tile;
|
|
121
190
|
loadOptions = {
|
|
122
191
|
...loadOptions,
|
|
123
192
|
mimeType: 'application/x-protobuf',
|
|
@@ -135,7 +204,14 @@ export default class MVTLayer extends TileLayer {
|
|
|
135
204
|
return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
|
|
136
205
|
}
|
|
137
206
|
|
|
138
|
-
renderSubLayers(
|
|
207
|
+
renderSubLayers(
|
|
208
|
+
props: TileLayer['props'] & {
|
|
209
|
+
id: string;
|
|
210
|
+
data: ParsedMvtTile;
|
|
211
|
+
_offset: number;
|
|
212
|
+
tile: Tile2DHeader<ParsedMvtTile>;
|
|
213
|
+
}
|
|
214
|
+
): Layer | null | LayersList {
|
|
139
215
|
const {x, y, z} = props.tile.index;
|
|
140
216
|
const worldScale = Math.pow(2, z);
|
|
141
217
|
|
|
@@ -165,7 +241,7 @@ export default class MVTLayer extends TileLayer {
|
|
|
165
241
|
return subLayers;
|
|
166
242
|
}
|
|
167
243
|
|
|
168
|
-
_updateAutoHighlight(info) {
|
|
244
|
+
protected _updateAutoHighlight(info: PickingInfo): void {
|
|
169
245
|
const {uniqueIdProperty} = this.props;
|
|
170
246
|
|
|
171
247
|
const {hoveredFeatureId, hoveredFeatureLayerName} = this.state;
|
|
@@ -194,30 +270,34 @@ export default class MVTLayer extends TileLayer {
|
|
|
194
270
|
}
|
|
195
271
|
}
|
|
196
272
|
|
|
197
|
-
getPickingInfo(params) {
|
|
273
|
+
getPickingInfo(params: GetPickingInfoParams): TiledPickingInfo {
|
|
198
274
|
const info = super.getPickingInfo(params);
|
|
199
275
|
|
|
200
|
-
const isWGS84 = this.context.viewport.resolution;
|
|
276
|
+
const isWGS84 = Boolean(this.context.viewport.resolution);
|
|
201
277
|
|
|
202
278
|
if (this.state.binary && info.index !== -1) {
|
|
203
|
-
const {data} = params.sourceLayer
|
|
204
|
-
info.object = binaryToGeojson(data, {globalFeatureId: info.index});
|
|
279
|
+
const {data} = params.sourceLayer!.props;
|
|
280
|
+
info.object = binaryToGeojson(data as BinaryFeatures, {globalFeatureId: info.index}) as DataT;
|
|
205
281
|
}
|
|
206
282
|
if (info.object && !isWGS84) {
|
|
207
|
-
info.object = transformTileCoordsToWGS84(
|
|
283
|
+
info.object = transformTileCoordsToWGS84(
|
|
284
|
+
info.object,
|
|
285
|
+
info.tile!.bbox as GeoBoundingBox,
|
|
286
|
+
this.context.viewport
|
|
287
|
+
);
|
|
208
288
|
}
|
|
209
289
|
|
|
210
290
|
return info;
|
|
211
291
|
}
|
|
212
292
|
|
|
213
|
-
getSubLayerPropsByTile(tile) {
|
|
293
|
+
getSubLayerPropsByTile(tile: Tile2DHeader<ParsedMvtTile>): Record<string, any> {
|
|
214
294
|
return {
|
|
215
295
|
highlightedObjectIndex: this.getHighlightedObjectIndex(tile),
|
|
216
296
|
highlightColor: this.state.highlightColor
|
|
217
297
|
};
|
|
218
298
|
}
|
|
219
299
|
|
|
220
|
-
getHighlightedObjectIndex(tile) {
|
|
300
|
+
private getHighlightedObjectIndex(tile: Tile2DHeader<ParsedMvtTile>): number {
|
|
221
301
|
const {hoveredFeatureId, hoveredFeatureLayerName, binary} = this.state;
|
|
222
302
|
const {uniqueIdProperty, highlightedFeatureId} = this.props;
|
|
223
303
|
const data = tile.content;
|
|
@@ -254,42 +334,44 @@ export default class MVTLayer extends TileLayer {
|
|
|
254
334
|
return -1;
|
|
255
335
|
}
|
|
256
336
|
|
|
257
|
-
_pickObjects(maxObjects) {
|
|
337
|
+
private _pickObjects(maxObjects: number | null): PickingInfo[] {
|
|
258
338
|
const {deck, viewport} = this.context;
|
|
259
339
|
const width = viewport.width;
|
|
260
340
|
const height = viewport.height;
|
|
261
341
|
const x = viewport.x;
|
|
262
342
|
const y = viewport.y;
|
|
263
343
|
const layerIds = [this.id];
|
|
264
|
-
return deck
|
|
344
|
+
return deck!.pickObjects({x, y, width, height, layerIds, maxObjects});
|
|
265
345
|
}
|
|
266
346
|
|
|
267
|
-
|
|
347
|
+
/** Get the rendered features in the current viewport. */
|
|
348
|
+
getRenderedFeatures(maxFeatures: number | null = null): DataT[] {
|
|
268
349
|
const features = this._pickObjects(maxFeatures);
|
|
269
350
|
const featureCache = new Set();
|
|
270
|
-
const renderedFeatures = [];
|
|
351
|
+
const renderedFeatures: DataT[] = [];
|
|
271
352
|
|
|
272
353
|
for (const f of features) {
|
|
273
354
|
const featureId = getFeatureUniqueId(f.object, this.props.uniqueIdProperty);
|
|
274
355
|
|
|
275
356
|
if (featureId === undefined) {
|
|
276
357
|
// we have no id for the feature, we just add to the list
|
|
277
|
-
renderedFeatures.push(f.object);
|
|
358
|
+
renderedFeatures.push(f.object as DataT);
|
|
278
359
|
} else if (!featureCache.has(featureId)) {
|
|
279
360
|
// Add removing duplicates
|
|
280
361
|
featureCache.add(featureId);
|
|
281
|
-
renderedFeatures.push(f.object);
|
|
362
|
+
renderedFeatures.push(f.object as DataT);
|
|
282
363
|
}
|
|
283
364
|
}
|
|
284
365
|
|
|
285
366
|
return renderedFeatures;
|
|
286
367
|
}
|
|
287
368
|
|
|
288
|
-
_setWGS84PropertyForTiles() {
|
|
369
|
+
private _setWGS84PropertyForTiles(): void {
|
|
289
370
|
const propName = 'dataInWGS84';
|
|
290
|
-
const
|
|
371
|
+
const tileset: Tileset2D = this.state.tileset;
|
|
291
372
|
|
|
292
|
-
|
|
373
|
+
// @ts-expect-error selectedTiles are always initialized when tile is being processed
|
|
374
|
+
tileset.selectedTiles.forEach((tile: Tile2DHeader & ContentWGS84Cache) => {
|
|
293
375
|
if (!tile.hasOwnProperty(propName)) {
|
|
294
376
|
// eslint-disable-next-line accessor-pairs
|
|
295
377
|
Object.defineProperty(tile, propName, {
|
|
@@ -305,11 +387,13 @@ export default class MVTLayer extends TileLayer {
|
|
|
305
387
|
return [];
|
|
306
388
|
}
|
|
307
389
|
|
|
308
|
-
|
|
390
|
+
const {bbox} = tile;
|
|
391
|
+
if (tile._contentWGS84 === undefined && isGeoBoundingBox(bbox)) {
|
|
309
392
|
// Create a cache to transform only once
|
|
393
|
+
|
|
310
394
|
const content = this.state.binary ? binaryToGeojson(tile.content) : tile.content;
|
|
311
395
|
tile._contentWGS84 = content.map(feature =>
|
|
312
|
-
transformTileCoordsToWGS84(feature,
|
|
396
|
+
transformTileCoordsToWGS84(feature, bbox, this.context.viewport)
|
|
313
397
|
);
|
|
314
398
|
}
|
|
315
399
|
return tile._contentWGS84;
|
|
@@ -320,8 +404,8 @@ export default class MVTLayer extends TileLayer {
|
|
|
320
404
|
}
|
|
321
405
|
}
|
|
322
406
|
|
|
323
|
-
function getFeatureUniqueId(feature, uniqueIdProperty) {
|
|
324
|
-
if (uniqueIdProperty) {
|
|
407
|
+
function getFeatureUniqueId(feature: Feature, uniqueIdProperty: string | undefined) {
|
|
408
|
+
if (feature.properties && uniqueIdProperty) {
|
|
325
409
|
return feature.properties[uniqueIdProperty];
|
|
326
410
|
}
|
|
327
411
|
|
|
@@ -332,15 +416,19 @@ function getFeatureUniqueId(feature, uniqueIdProperty) {
|
|
|
332
416
|
return undefined;
|
|
333
417
|
}
|
|
334
418
|
|
|
335
|
-
function getFeatureLayerName(feature) {
|
|
419
|
+
function getFeatureLayerName(feature: Feature): string | null {
|
|
336
420
|
return feature.properties?.layerName || null;
|
|
337
421
|
}
|
|
338
422
|
|
|
339
|
-
function isFeatureIdDefined(value) {
|
|
423
|
+
function isFeatureIdDefined(value: unknown): boolean {
|
|
340
424
|
return value !== undefined && value !== null && value !== '';
|
|
341
425
|
}
|
|
342
426
|
|
|
343
|
-
function transformTileCoordsToWGS84(
|
|
427
|
+
function transformTileCoordsToWGS84(
|
|
428
|
+
object: Feature,
|
|
429
|
+
bbox: GeoBoundingBox,
|
|
430
|
+
viewport: Viewport
|
|
431
|
+
): Feature {
|
|
344
432
|
const feature = {
|
|
345
433
|
...object,
|
|
346
434
|
geometry: {
|
|
@@ -356,8 +444,5 @@ function transformTileCoordsToWGS84(object, bbox, viewport) {
|
|
|
356
444
|
}
|
|
357
445
|
});
|
|
358
446
|
|
|
359
|
-
return feature;
|
|
447
|
+
return feature as Feature;
|
|
360
448
|
}
|
|
361
|
-
|
|
362
|
-
MVTLayer.layerName = 'MVTLayer';
|
|
363
|
-
MVTLayer.defaultProps = defaultProps;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {AccessorFunction} from '@deck.gl/core';
|
|
2
|
-
import GeoCellLayer from '../geo-cell-layer/GeoCellLayer';
|
|
2
|
+
import GeoCellLayer, {GeoCellLayerProps} from '../geo-cell-layer/GeoCellLayer';
|
|
3
3
|
import {getQuadkeyPolygon} from './quadkey-utils';
|
|
4
4
|
|
|
5
5
|
const defaultProps = {
|
|
6
6
|
getQuadkey: {type: 'accessor', value: d => d.quadkey}
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/** All properties supported by QuadkeyLayer. */
|
|
10
|
+
export type QuadkeyLayerProps<DataT = any> = _QuadkeyLayerProps<DataT> & GeoCellLayerProps<DataT>;
|
|
11
|
+
|
|
12
|
+
/** Properties added by QuadkeyLayer. */
|
|
13
|
+
type _QuadkeyLayerProps<DataT = any> = {
|
|
13
14
|
/**
|
|
14
15
|
* Called for each data object to retrieve the quadkey string identifier.
|
|
15
16
|
*
|
|
@@ -20,7 +21,7 @@ type QuadkeyLayerProps<DataT = any> = {
|
|
|
20
21
|
|
|
21
22
|
export default class QuadkeyLayer<DataT = any, ExtraProps = {}> extends GeoCellLayer<
|
|
22
23
|
DataT,
|
|
23
|
-
Required<
|
|
24
|
+
Required<_QuadkeyLayerProps> & ExtraProps
|
|
24
25
|
> {
|
|
25
26
|
static layerName = 'QuadkeyLayer';
|
|
26
27
|
static defaultProps: any = defaultProps;
|