@deck.gl/carto 8.8.0-alpha.3 → 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 +130 -25
- package/dist/es5/layers/carto-layer.js +3 -1
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/h3-tile-layer.js +14 -3
- package/dist/es5/layers/h3-tile-layer.js.map +1 -1
- package/dist/es5/layers/h3-tileset-2d.js +21 -11
- package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
- package/dist/es5/layers/quadkey-tile-layer.js +9 -3
- package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/es5/layers/spatial-index-tile-layer.js +92 -0
- package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -0
- package/dist/esm/layers/carto-layer.js +3 -1
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/h3-tile-layer.js +12 -4
- package/dist/esm/layers/h3-tile-layer.js.map +1 -1
- package/dist/esm/layers/h3-tileset-2d.js +27 -12
- package/dist/esm/layers/h3-tileset-2d.js.map +1 -1
- package/dist/esm/layers/quadkey-tile-layer.js +8 -6
- package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/esm/layers/spatial-index-tile-layer.js +57 -0
- package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -0
- package/dist.min.js +4 -4
- package/package.json +2 -2
- package/src/layers/carto-layer.ts +7 -1
- package/src/layers/h3-tile-layer.js +12 -4
- package/src/layers/h3-tileset-2d.js +35 -9
- package/src/layers/quadkey-tile-layer.js +9 -4
- package/src/layers/spatial-index-tile-layer.js +48 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/carto",
|
|
3
3
|
"description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.8.0-alpha.
|
|
5
|
+
"version": "8.8.0-alpha.4",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"@deck.gl/layers": "^8.0.0",
|
|
59
59
|
"@loaders.gl/core": "^3.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "608c74fff3c955142c4e1f5e77b9e21ebbf690f7"
|
|
62
62
|
}
|
|
@@ -57,7 +57,13 @@ const defaultProps = {
|
|
|
57
57
|
geoColumn: null,
|
|
58
58
|
|
|
59
59
|
// (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
|
|
60
|
-
columns: {type: 'array', value: null}
|
|
60
|
+
columns: {type: 'array', value: null},
|
|
61
|
+
|
|
62
|
+
// (String, optional): aggregration SQL expression. Only used for spatial index datasets
|
|
63
|
+
aggregationExp: null,
|
|
64
|
+
|
|
65
|
+
// (Number, optional): aggregration resolution level. Only used for spatial index datasets, defaults to 6 for quadkeys, 4 for h3
|
|
66
|
+
aggregationResLevel: null
|
|
61
67
|
};
|
|
62
68
|
|
|
63
69
|
export interface CartoLayerProps<DataT = any> extends CompositeLayerProps<DataT> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {CompositeLayer} from '@deck.gl/core';
|
|
2
|
-
import {H3HexagonLayer
|
|
2
|
+
import {H3HexagonLayer} from '@deck.gl/geo-layers';
|
|
3
3
|
import H3Tileset2D from './h3-tileset-2d';
|
|
4
|
+
import SpatialIndexTileLayer from './spatial-index-tile-layer';
|
|
4
5
|
|
|
5
6
|
const renderSubLayers = props => {
|
|
6
7
|
const {data} = props;
|
|
@@ -13,6 +14,10 @@ const renderSubLayers = props => {
|
|
|
13
14
|
});
|
|
14
15
|
};
|
|
15
16
|
|
|
17
|
+
const defaultProps = {
|
|
18
|
+
aggregationResLevel: 4
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
export default class H3TileLayer extends CompositeLayer {
|
|
17
22
|
initializeState() {
|
|
18
23
|
this.setState({data: null, tileJSON: null});
|
|
@@ -28,17 +33,20 @@ export default class H3TileLayer extends CompositeLayer {
|
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
renderLayers() {
|
|
31
|
-
const {data} = this.state;
|
|
36
|
+
const {data, tileJSON} = this.state;
|
|
37
|
+
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
32
38
|
return [
|
|
33
|
-
new
|
|
39
|
+
new SpatialIndexTileLayer(this.props, {
|
|
34
40
|
id: 'h3-tile-layer',
|
|
35
41
|
data,
|
|
36
42
|
getHexagon: d => d.id,
|
|
37
43
|
TilesetClass: H3Tileset2D,
|
|
38
|
-
renderSubLayers
|
|
44
|
+
renderSubLayers,
|
|
45
|
+
maxZoom
|
|
39
46
|
})
|
|
40
47
|
];
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
H3TileLayer.layerName = 'H3TileLayer';
|
|
52
|
+
H3TileLayer.defaultProps = defaultProps;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import {_Tileset2D as Tileset2D} from '@deck.gl/geo-layers';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
polyfill,
|
|
4
|
+
getRes0Indexes,
|
|
5
|
+
geoToH3,
|
|
6
|
+
h3GetResolution,
|
|
7
|
+
h3ToGeoBoundary,
|
|
8
|
+
h3ToParent,
|
|
9
|
+
kRing
|
|
10
|
+
} from 'h3-js';
|
|
3
11
|
|
|
4
|
-
|
|
12
|
+
function getHexagonsInBoundingBox({west, north, east, south}, resolution) {
|
|
5
13
|
if (resolution === 0) {
|
|
6
14
|
return getRes0Indexes();
|
|
7
15
|
}
|
|
@@ -15,7 +23,7 @@ export function getHexagonsInBoundingBox({west, north, east, south}, resolution)
|
|
|
15
23
|
|
|
16
24
|
// `polyfill()` fills based on hexagon center, which means tiles vanish
|
|
17
25
|
// prematurely. Get more accurate coverage by oversampling
|
|
18
|
-
const oversample =
|
|
26
|
+
const oversample = 2;
|
|
19
27
|
const h3Indices = polyfill(
|
|
20
28
|
[
|
|
21
29
|
[
|
|
@@ -33,7 +41,7 @@ export function getHexagonsInBoundingBox({west, north, east, south}, resolution)
|
|
|
33
41
|
return oversample ? [...new Set(h3Indices.map(i => h3ToParent(i, resolution)))] : h3Indices;
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
function tileToBoundingBox(index) {
|
|
37
45
|
const coordinates = h3ToGeoBoundary(index);
|
|
38
46
|
const latitudes = coordinates.map(c => c[0]);
|
|
39
47
|
const longitudes = coordinates.map(c => c[1]);
|
|
@@ -44,22 +52,40 @@ export function tileToBoundingBox(index) {
|
|
|
44
52
|
return {west, south, east, north};
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
// Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
56
|
+
// a H3 resolution such that the screen space size of the hexagons is
|
|
57
|
+
// similar
|
|
58
|
+
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
59
|
+
const BIAS = 2;
|
|
60
|
+
function getHexagonResolution(viewport) {
|
|
61
|
+
const hexagonScaleFactor = (2 / 3) * viewport.zoom;
|
|
62
|
+
const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180));
|
|
63
|
+
|
|
64
|
+
// Clip and bias
|
|
65
|
+
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
export default class H3Tileset2D extends Tileset2D {
|
|
48
69
|
getTileIndices({viewport, minZoom, maxZoom}) {
|
|
49
70
|
const [east, south, west, north] = viewport.getBounds();
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
let
|
|
72
|
+
let z = getHexagonResolution(viewport);
|
|
73
|
+
let indices = [];
|
|
53
74
|
if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
|
|
54
75
|
z = minZoom;
|
|
55
76
|
}
|
|
56
77
|
if (typeof maxZoom === 'number' && Number.isFinite(maxZoom) && z > maxZoom) {
|
|
57
78
|
z = maxZoom;
|
|
79
|
+
|
|
80
|
+
// Once we are at max zoom, getHexagonsInBoundingBox doesn't work, simply
|
|
81
|
+
// get a ring centered on the hexagon in the viewport center
|
|
82
|
+
const center = geoToH3(viewport.latitude, viewport.longitude, maxZoom);
|
|
83
|
+
indices = kRing(center, 1);
|
|
84
|
+
} else {
|
|
85
|
+
indices = getHexagonsInBoundingBox({west, north, east, south}, z);
|
|
58
86
|
}
|
|
59
87
|
|
|
60
|
-
|
|
61
|
-
const resolution = Math.max(0, Math.floor((2 * z) / 3) - 2);
|
|
62
|
-
return getHexagonsInBoundingBox({west, north, east, south}, resolution).map(i => ({i}));
|
|
88
|
+
return indices.map(i => ({i}));
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
getTileId({i}) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {CompositeLayer} from '@deck.gl/core';
|
|
2
|
-
import {QuadkeyLayer
|
|
2
|
+
import {QuadkeyLayer} from '@deck.gl/geo-layers';
|
|
3
3
|
import QuadkeyTileset2D from './quadkey-tileset-2d';
|
|
4
|
+
import SpatialIndexTileLayer from './spatial-index-tile-layer';
|
|
4
5
|
|
|
5
6
|
const renderSubLayers = props => {
|
|
6
7
|
const {data} = props;
|
|
@@ -8,6 +9,10 @@ const renderSubLayers = props => {
|
|
|
8
9
|
return new QuadkeyLayer(props);
|
|
9
10
|
};
|
|
10
11
|
|
|
12
|
+
const defaultProps = {
|
|
13
|
+
aggregationResLevel: 6
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
export default class QuadkeyTileLayer extends CompositeLayer {
|
|
12
17
|
initializeState() {
|
|
13
18
|
this.setState({data: null, tileJSON: null});
|
|
@@ -24,10 +29,9 @@ export default class QuadkeyTileLayer extends CompositeLayer {
|
|
|
24
29
|
|
|
25
30
|
renderLayers() {
|
|
26
31
|
const {data, tileJSON} = this.state;
|
|
27
|
-
const
|
|
28
|
-
const maxZoom = maxresolution - this.props.aggregationResLevel;
|
|
32
|
+
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
29
33
|
return [
|
|
30
|
-
new
|
|
34
|
+
new SpatialIndexTileLayer(this.props, {
|
|
31
35
|
id: 'quadkey-tile-layer',
|
|
32
36
|
data,
|
|
33
37
|
getQuadkey: d => d.id,
|
|
@@ -40,3 +44,4 @@ export default class QuadkeyTileLayer extends CompositeLayer {
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
QuadkeyTileLayer.layerName = 'QuadkeyTileLayer';
|
|
47
|
+
QuadkeyTileLayer.defaultProps = defaultProps;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {TileLayer} from '@deck.gl/geo-layers';
|
|
2
|
+
|
|
3
|
+
function isFeatureIdDefined(value) {
|
|
4
|
+
return value !== undefined && value !== null && value !== '';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default class SpatialIndexTileLayer extends TileLayer {
|
|
8
|
+
_updateAutoHighlight(info) {
|
|
9
|
+
const {hoveredFeatureId} = this.state;
|
|
10
|
+
const hoveredFeature = info.object;
|
|
11
|
+
let newHoveredFeatureId;
|
|
12
|
+
|
|
13
|
+
if (hoveredFeature) {
|
|
14
|
+
newHoveredFeatureId = hoveredFeature.id;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (hoveredFeatureId !== newHoveredFeatureId) {
|
|
18
|
+
let {highlightColor} = this.props;
|
|
19
|
+
if (typeof highlightColor === 'function') {
|
|
20
|
+
highlightColor = highlightColor(info);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.setState({
|
|
24
|
+
highlightColor,
|
|
25
|
+
hoveredFeatureId: newHoveredFeatureId
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getSubLayerPropsByTile(tile) {
|
|
31
|
+
return {
|
|
32
|
+
highlightedObjectIndex: this.getHighlightedObjectIndex(tile),
|
|
33
|
+
highlightColor: this.state.highlightColor
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getHighlightedObjectIndex(tile) {
|
|
38
|
+
const {hoveredFeatureId} = this.state;
|
|
39
|
+
const data = tile.content;
|
|
40
|
+
|
|
41
|
+
const isFeatureIdPresent = isFeatureIdDefined(hoveredFeatureId);
|
|
42
|
+
if (!isFeatureIdPresent || !Array.isArray(data)) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return data.findIndex(feature => feature.id === hoveredFeatureId);
|
|
47
|
+
}
|
|
48
|
+
}
|