@deck.gl/carto 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 +33337 -40143
- package/dist/es5/api/layer-map.js +17 -5
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/api/maps-api-common.js +1 -0
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +9 -23
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +14 -3
- package/dist/es5/api/parseMap.js.map +1 -1
- package/dist/es5/index.js +16 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +38 -13
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/h3-tile-layer.js +107 -0
- package/dist/es5/layers/h3-tile-layer.js.map +1 -0
- package/dist/es5/layers/h3-tileset-2d.js +175 -0
- package/dist/es5/layers/h3-tileset-2d.js.map +1 -0
- package/dist/es5/layers/quadkey-tile-layer.js +103 -0
- package/dist/es5/layers/quadkey-tile-layer.js.map +1 -0
- package/dist/es5/layers/quadkey-tileset-2d.js +89 -0
- package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -0
- 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/api/layer-map.js +12 -4
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-api-common.js +1 -0
- package/dist/esm/api/maps-api-common.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +2 -19
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +15 -4
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +37 -8
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/h3-tile-layer.js +69 -0
- package/dist/esm/layers/h3-tile-layer.js.map +1 -0
- package/dist/esm/layers/h3-tileset-2d.js +118 -0
- package/dist/esm/layers/h3-tileset-2d.js.map +1 -0
- package/dist/esm/layers/quadkey-tile-layer.js +63 -0
- package/dist/esm/layers/quadkey-tile-layer.js.map +1 -0
- package/dist/esm/layers/quadkey-tileset-2d.js +48 -0
- package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -0
- 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 +14 -14
- package/package.json +9 -8
- package/src/api/layer-map.ts +14 -4
- package/src/api/maps-api-common.ts +4 -3
- package/src/api/maps-v3-client.ts +3 -19
- package/src/api/parseMap.ts +20 -5
- package/src/index.ts +4 -0
- package/src/layers/{carto-layer.js → carto-layer.ts} +162 -23
- package/src/layers/h3-tile-layer.js +52 -0
- package/src/layers/h3-tileset-2d.js +108 -0
- package/src/layers/quadkey-tile-layer.js +47 -0
- package/src/layers/quadkey-tileset-2d.js +36 -0
- package/src/layers/spatial-index-tile-layer.js +48 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {_Tileset2D as Tileset2D} from '@deck.gl/geo-layers';
|
|
2
|
+
import {
|
|
3
|
+
polyfill,
|
|
4
|
+
getRes0Indexes,
|
|
5
|
+
geoToH3,
|
|
6
|
+
h3GetResolution,
|
|
7
|
+
h3ToGeoBoundary,
|
|
8
|
+
h3ToParent,
|
|
9
|
+
kRing
|
|
10
|
+
} from 'h3-js';
|
|
11
|
+
|
|
12
|
+
function getHexagonsInBoundingBox({west, north, east, south}, resolution) {
|
|
13
|
+
if (resolution === 0) {
|
|
14
|
+
return getRes0Indexes();
|
|
15
|
+
}
|
|
16
|
+
if (east - west > 180) {
|
|
17
|
+
// This is a known issue in h3-js: polyfill does not work correctly
|
|
18
|
+
// when longitude span is larger than 180 degrees.
|
|
19
|
+
return getHexagonsInBoundingBox({west, north, east: 0, south}, resolution).concat(
|
|
20
|
+
getHexagonsInBoundingBox({west: 0, north, east, south}, resolution)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// `polyfill()` fills based on hexagon center, which means tiles vanish
|
|
25
|
+
// prematurely. Get more accurate coverage by oversampling
|
|
26
|
+
const oversample = 2;
|
|
27
|
+
const h3Indices = polyfill(
|
|
28
|
+
[
|
|
29
|
+
[
|
|
30
|
+
[west, north],
|
|
31
|
+
[west, south],
|
|
32
|
+
[east, south],
|
|
33
|
+
[east, north],
|
|
34
|
+
[west, north]
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
resolution + oversample,
|
|
38
|
+
true
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return oversample ? [...new Set(h3Indices.map(i => h3ToParent(i, resolution)))] : h3Indices;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function tileToBoundingBox(index) {
|
|
45
|
+
const coordinates = h3ToGeoBoundary(index);
|
|
46
|
+
const latitudes = coordinates.map(c => c[0]);
|
|
47
|
+
const longitudes = coordinates.map(c => c[1]);
|
|
48
|
+
const west = Math.min(...longitudes);
|
|
49
|
+
const south = Math.min(...latitudes);
|
|
50
|
+
const east = Math.max(...longitudes);
|
|
51
|
+
const north = Math.max(...latitudes);
|
|
52
|
+
return {west, south, east, north};
|
|
53
|
+
}
|
|
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
|
+
|
|
68
|
+
export default class H3Tileset2D extends Tileset2D {
|
|
69
|
+
getTileIndices({viewport, minZoom, maxZoom}) {
|
|
70
|
+
const [east, south, west, north] = viewport.getBounds();
|
|
71
|
+
|
|
72
|
+
let z = getHexagonResolution(viewport);
|
|
73
|
+
let indices = [];
|
|
74
|
+
if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
|
|
75
|
+
z = minZoom;
|
|
76
|
+
}
|
|
77
|
+
if (typeof maxZoom === 'number' && Number.isFinite(maxZoom) && z > maxZoom) {
|
|
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);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return indices.map(i => ({i}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getTileId({i}) {
|
|
92
|
+
return i;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getTileMetadata({i}) {
|
|
96
|
+
return {bbox: tileToBoundingBox(i)};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getTileZoom({i}) {
|
|
100
|
+
return h3GetResolution(i);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getParentIndex(index) {
|
|
104
|
+
const resolution = h3GetResolution(index.i);
|
|
105
|
+
const i = h3ToParent(index.i, resolution - 1);
|
|
106
|
+
return {i};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {CompositeLayer} from '@deck.gl/core';
|
|
2
|
+
import {QuadkeyLayer} from '@deck.gl/geo-layers';
|
|
3
|
+
import QuadkeyTileset2D from './quadkey-tileset-2d';
|
|
4
|
+
import SpatialIndexTileLayer from './spatial-index-tile-layer';
|
|
5
|
+
|
|
6
|
+
const renderSubLayers = props => {
|
|
7
|
+
const {data} = props;
|
|
8
|
+
if (!data || !data.length) return null;
|
|
9
|
+
return new QuadkeyLayer(props);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const defaultProps = {
|
|
13
|
+
aggregationResLevel: 6
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default class QuadkeyTileLayer extends CompositeLayer {
|
|
17
|
+
initializeState() {
|
|
18
|
+
this.setState({data: null, tileJSON: null});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
updateState({props, oldProps, context, changeFlags}) {
|
|
22
|
+
if (changeFlags.dataChanged) {
|
|
23
|
+
let {data} = this.props;
|
|
24
|
+
const tileJSON = data;
|
|
25
|
+
data = tileJSON.tiles;
|
|
26
|
+
this.setState({data, tileJSON});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
renderLayers() {
|
|
31
|
+
const {data, tileJSON} = this.state;
|
|
32
|
+
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
33
|
+
return [
|
|
34
|
+
new SpatialIndexTileLayer(this.props, {
|
|
35
|
+
id: 'quadkey-tile-layer',
|
|
36
|
+
data,
|
|
37
|
+
getQuadkey: d => d.id,
|
|
38
|
+
TilesetClass: QuadkeyTileset2D,
|
|
39
|
+
renderSubLayers,
|
|
40
|
+
maxZoom
|
|
41
|
+
})
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
QuadkeyTileLayer.layerName = 'QuadkeyTileLayer';
|
|
47
|
+
QuadkeyTileLayer.defaultProps = defaultProps;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {_Tileset2D as Tileset2D} from '@deck.gl/geo-layers';
|
|
2
|
+
|
|
3
|
+
function tileToQuadkey(tile) {
|
|
4
|
+
let index = '';
|
|
5
|
+
for (let z = tile.z; z > 0; z--) {
|
|
6
|
+
let b = 0;
|
|
7
|
+
const mask = 1 << (z - 1);
|
|
8
|
+
if ((tile.x & mask) !== 0) b++;
|
|
9
|
+
if ((tile.y & mask) !== 0) b += 2;
|
|
10
|
+
index += b.toString();
|
|
11
|
+
}
|
|
12
|
+
return {i: index};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class QuadkeyTileset2D extends Tileset2D {
|
|
16
|
+
getTileIndices(opts) {
|
|
17
|
+
return super.getTileIndices(opts).map(tileToQuadkey);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getTileId({i}) {
|
|
21
|
+
return i;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getTileMetadata() {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getTileZoom({i}) {
|
|
29
|
+
return i.length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getParentIndex(index) {
|
|
33
|
+
const i = index.i.slice(0, -1);
|
|
34
|
+
return {i};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -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
|
+
}
|