@deck.gl/carto 8.8.4 → 8.8.7
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 +31412 -22945
- package/dist/es5/api/index.js.map +1 -1
- package/dist/es5/api/layer-map.js +104 -17
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +230 -57
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +14 -4
- package/dist/es5/api/parseMap.js.map +1 -1
- package/dist/es5/config.js +11 -2
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +15 -23
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/carto-tile-layer.js +1 -1
- package/dist/es5/layers/carto-tile-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-utils.js +2 -0
- package/dist/es5/layers/quadbin-utils.js.map +1 -1
- package/dist/es5/layers/schema/carto-spatial-tile-loader.js +99 -0
- package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -0
- package/dist/es5/layers/schema/carto-spatial-tile.js +117 -0
- package/dist/es5/layers/schema/carto-spatial-tile.js.map +1 -0
- package/dist/es5/layers/schema/carto-tile.js +5 -1
- package/dist/es5/layers/schema/carto-tile.js.map +1 -1
- package/dist/es5/layers/schema/spatialjson-utils.js +41 -0
- package/dist/es5/layers/schema/spatialjson-utils.js.map +1 -0
- package/dist/es5/layers/spatial-index-tile-layer.js +6 -0
- package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/layer-map.js +79 -14
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-api-common.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +129 -16
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +18 -4
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/config.js +10 -2
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +12 -19
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/carto-tile-layer.js +1 -1
- package/dist/esm/layers/carto-tile-layer.js.map +1 -1
- package/dist/esm/layers/quadbin-utils.js +2 -5
- package/dist/esm/layers/quadbin-utils.js.map +1 -1
- package/dist/esm/layers/schema/carto-spatial-tile-loader.js +56 -0
- package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -0
- package/dist/esm/layers/schema/carto-spatial-tile.js +72 -0
- package/dist/esm/layers/schema/carto-spatial-tile.js.map +1 -0
- package/dist/esm/layers/schema/carto-tile.js +2 -2
- package/dist/esm/layers/schema/carto-tile.js.map +1 -1
- package/dist/esm/layers/schema/spatialjson-utils.js +26 -0
- package/dist/esm/layers/schema/spatialjson-utils.js.map +1 -0
- package/dist/esm/layers/spatial-index-tile-layer.js +3 -0
- package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist.min.js +138 -138
- package/package.json +2 -2
- package/src/api/index.ts +1 -0
- package/src/api/layer-map.ts +76 -13
- package/src/api/maps-api-common.ts +8 -0
- package/src/api/maps-v3-client.ts +148 -21
- package/src/api/parseMap.ts +6 -2
- package/src/config.ts +12 -2
- package/src/index.ts +1 -1
- package/src/layers/carto-layer.ts +26 -33
- package/src/layers/carto-tile-layer.ts +6 -3
- package/src/layers/quadbin-utils.ts +2 -2
- package/src/layers/schema/carto-spatial-tile-loader.ts +59 -0
- package/src/layers/schema/carto-spatial-tile.ts +83 -0
- package/src/layers/schema/carto-tile.ts +6 -6
- package/src/layers/schema/spatialjson-utils.ts +35 -0
- package/src/layers/spatial-index-tile-layer.ts +4 -0
- package/typed/api/index.d.ts +1 -0
- package/typed/api/index.d.ts.map +1 -1
- package/typed/api/layer-map.d.ts +12 -4
- package/typed/api/layer-map.d.ts.map +1 -1
- package/typed/api/maps-api-common.d.ts +4 -0
- package/typed/api/maps-api-common.d.ts.map +1 -1
- package/typed/api/maps-v3-client.d.ts +8 -4
- package/typed/api/maps-v3-client.d.ts.map +1 -1
- package/typed/config.d.ts +2 -0
- package/typed/config.d.ts.map +1 -1
- package/typed/index.d.ts +1 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/layers/carto-layer.d.ts +8 -8
- package/typed/layers/carto-layer.d.ts.map +1 -1
- package/typed/layers/carto-tile-layer.d.ts.map +1 -1
- package/typed/layers/quadbin-utils.d.ts +2 -0
- package/typed/layers/quadbin-utils.d.ts.map +1 -1
- package/typed/layers/schema/carto-spatial-tile-loader.d.ts +4 -0
- package/typed/layers/schema/carto-spatial-tile-loader.d.ts.map +1 -0
- package/typed/layers/schema/carto-spatial-tile.d.ts +21 -0
- package/typed/layers/schema/carto-spatial-tile.d.ts.map +1 -0
- package/typed/layers/schema/carto-tile.d.ts +15 -3
- package/typed/layers/schema/carto-tile.d.ts.map +1 -1
- package/typed/layers/schema/spatialjson-utils.d.ts +25 -0
- package/typed/layers/schema/spatialjson-utils.d.ts.map +1 -0
- package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
- package/typed/api/index.js +0 -3
- package/typed/api/layer-map.js +0 -264
- package/typed/api/maps-api-common.js +0 -50
- package/typed/api/maps-client.js +0 -125
- package/typed/api/maps-v3-client.js +0 -304
- package/typed/api/parseMap.js +0 -178
- package/typed/basemap.js +0 -9
- package/typed/config.js +0 -35
- package/typed/index.js +0 -10
- package/typed/layers/carto-layer.js +0 -173
- package/typed/layers/carto-tile-layer.js +0 -105
- package/typed/layers/h3-tile-layer.js +0 -47
- package/typed/layers/h3-tileset-2d.js +0 -85
- package/typed/layers/quadkey-tile-layer.d.ts +0 -21
- package/typed/layers/quadkey-tile-layer.d.ts.map +0 -1
- package/typed/layers/quadkey-tile-layer.js +0 -42
- package/typed/layers/quadkey-tileset-2d.d.ts +0 -15
- package/typed/layers/quadkey-tileset-2d.d.ts.map +0 -1
- package/typed/layers/quadkey-tileset-2d.js +0 -36
- package/typed/layers/schema/carto-tile.js +0 -161
- package/typed/layers/spatial-index-tile-layer.js +0 -40
- package/typed/style/color-bins-style.js +0 -12
- package/typed/style/color-categories-style.js +0 -16
- package/typed/style/color-continuous-style.js +0 -12
- package/typed/style/palette.js +0 -62
- package/typed/style/utils.js +0 -15
- package/typed/utils.js +0 -4
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { CompositeLayer, log } from '@deck.gl/core';
|
|
2
|
-
import CartoTileLayer from './carto-tile-layer';
|
|
3
|
-
import H3TileLayer from './h3-tile-layer';
|
|
4
|
-
import QuadkeyTileLayer from './quadkey-tile-layer';
|
|
5
|
-
import { MVTLayer } from '@deck.gl/geo-layers';
|
|
6
|
-
import { GeoJsonLayer } from '@deck.gl/layers';
|
|
7
|
-
import { fetchLayerData, getDataV2, API_VERSIONS } from '../api';
|
|
8
|
-
import { COLUMNS_SUPPORT, FORMATS, GEO_COLUMN_SUPPORT, MAP_TYPES, TILE_FORMATS } from '../api/maps-api-common';
|
|
9
|
-
import { getDefaultCredentials } from '../config';
|
|
10
|
-
import { assert } from '../utils';
|
|
11
|
-
const defaultProps = {
|
|
12
|
-
// (String, required): data resource to load. table name, sql query or tileset name.
|
|
13
|
-
data: null,
|
|
14
|
-
// (Enum (MAP_TYPES), required)
|
|
15
|
-
type: null,
|
|
16
|
-
onDataLoad: { type: 'function', value: data => { }, compare: false },
|
|
17
|
-
onDataError: { type: 'function', value: null, compare: false, optional: true },
|
|
18
|
-
uniqueIdProperty: 'cartodb_id',
|
|
19
|
-
// override carto credentials for the layer, set to null to read from default
|
|
20
|
-
credentials: null,
|
|
21
|
-
/*********************/
|
|
22
|
-
/* API v3 PARAMETERS */
|
|
23
|
-
/**********************/
|
|
24
|
-
// (String, required): connection name at CARTO platform
|
|
25
|
-
connection: null,
|
|
26
|
-
// (String, optional): format of data
|
|
27
|
-
format: null,
|
|
28
|
-
// (String, optional): force format of data for tiles
|
|
29
|
-
formatTiles: null,
|
|
30
|
-
// (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.
|
|
31
|
-
clientId: null,
|
|
32
|
-
// (String, optional): name of the `geo_column` in the CARTO platform. Use this override the default column ('geom'), from which the geometry information should be fetched.
|
|
33
|
-
geoColumn: null,
|
|
34
|
-
// (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
|
|
35
|
-
columns: { type: 'array', value: null },
|
|
36
|
-
// (String, optional): aggregration SQL expression. Only used for spatial index datasets
|
|
37
|
-
aggregationExp: null,
|
|
38
|
-
// (Number, optional): aggregration resolution level. Only used for spatial index datasets, defaults to 6 for quadkeys, 4 for h3
|
|
39
|
-
aggregationResLevel: null
|
|
40
|
-
};
|
|
41
|
-
export default class CartoLayer extends CompositeLayer {
|
|
42
|
-
initializeState() {
|
|
43
|
-
this.state = {
|
|
44
|
-
data: null,
|
|
45
|
-
apiVersion: null
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
get isLoaded() {
|
|
49
|
-
return this.getSubLayers().length > 0 && super.isLoaded;
|
|
50
|
-
}
|
|
51
|
-
_checkProps(props) {
|
|
52
|
-
const { type, credentials, connection, geoColumn, columns } = props;
|
|
53
|
-
const localCreds = { ...getDefaultCredentials(), ...credentials };
|
|
54
|
-
const { apiVersion } = localCreds;
|
|
55
|
-
log.assert(Object.values(API_VERSIONS).includes(apiVersion), `Invalid apiVersion ${apiVersion}. Use API_VERSIONS enum.`);
|
|
56
|
-
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
57
|
-
log.assert(type === MAP_TYPES.QUERY || type === MAP_TYPES.TILESET, `Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`);
|
|
58
|
-
log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);
|
|
59
|
-
log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);
|
|
60
|
-
log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);
|
|
61
|
-
}
|
|
62
|
-
else if (apiVersion === API_VERSIONS.V3) {
|
|
63
|
-
log.assert(connection, 'Missing mandatory connection parameter');
|
|
64
|
-
log.assert(Object.values(MAP_TYPES).includes(type), `Invalid type ${type}. Use MAP_TYPES enum.`);
|
|
65
|
-
if (!COLUMNS_SUPPORT.includes(type)) {
|
|
66
|
-
log.assert(!columns, `columns prop is only supported for types: ${COLUMNS_SUPPORT.join()}`);
|
|
67
|
-
}
|
|
68
|
-
if (!GEO_COLUMN_SUPPORT.includes(type)) {
|
|
69
|
-
log.assert(!geoColumn, `geoColumn prop is only supported for types: ${GEO_COLUMN_SUPPORT.join()}`);
|
|
70
|
-
}
|
|
71
|
-
if (columns) {
|
|
72
|
-
log.assert(Array.isArray(columns), 'columns prop must be an Array');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
updateState({ props, oldProps, changeFlags }) {
|
|
77
|
-
this._checkProps(props);
|
|
78
|
-
const shouldUpdateData = changeFlags.dataChanged ||
|
|
79
|
-
props.connection !== oldProps.connection ||
|
|
80
|
-
props.geoColumn !== oldProps.geoColumn ||
|
|
81
|
-
props.format !== oldProps.format ||
|
|
82
|
-
props.formatTiles !== oldProps.formatTiles ||
|
|
83
|
-
props.type !== oldProps.type ||
|
|
84
|
-
JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||
|
|
85
|
-
JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials);
|
|
86
|
-
if (shouldUpdateData) {
|
|
87
|
-
this.setState({ data: null, apiVersion: null });
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
89
|
-
this._updateData();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async _updateData() {
|
|
93
|
-
try {
|
|
94
|
-
const { type, data: source, clientId, credentials, connection, ...rest } = this.props;
|
|
95
|
-
const localConfig = { ...getDefaultCredentials(), ...credentials };
|
|
96
|
-
const { apiVersion } = localConfig;
|
|
97
|
-
let result;
|
|
98
|
-
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
99
|
-
result = {
|
|
100
|
-
data: await getDataV2({ type, source, credentials: credentials })
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
result = await fetchLayerData({
|
|
105
|
-
type,
|
|
106
|
-
source,
|
|
107
|
-
clientId,
|
|
108
|
-
credentials: credentials,
|
|
109
|
-
connection,
|
|
110
|
-
...rest
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
this.setState({ ...result, apiVersion });
|
|
114
|
-
this.props.onDataLoad?.(result.data, {
|
|
115
|
-
propName: 'data',
|
|
116
|
-
layer: this
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
if (this.props.onDataError) {
|
|
121
|
-
this.props.onDataError(err);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
throw err;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
_getSubLayerAndProps() {
|
|
129
|
-
assert(this.state);
|
|
130
|
-
const { data, format, apiVersion } = this.state;
|
|
131
|
-
const { uniqueIdProperty } = defaultProps;
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
133
|
-
const { data: _notUsed, ...propsNoData } = this.props;
|
|
134
|
-
// @ts-expect-error 'uniqueIdProperty' is specified more than once, so this usage will be overwritten.
|
|
135
|
-
const props = { uniqueIdProperty, ...propsNoData };
|
|
136
|
-
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
137
|
-
return [MVTLayer, props];
|
|
138
|
-
}
|
|
139
|
-
if (format === FORMATS.TILEJSON) {
|
|
140
|
-
/* global URL */
|
|
141
|
-
const tileUrl = new URL(data.tiles[0]);
|
|
142
|
-
props.formatTiles =
|
|
143
|
-
props.formatTiles ||
|
|
144
|
-
tileUrl.searchParams.get('formatTiles') ||
|
|
145
|
-
TILE_FORMATS.MVT;
|
|
146
|
-
if (data.scheme === 'h3') {
|
|
147
|
-
return [H3TileLayer, props];
|
|
148
|
-
}
|
|
149
|
-
if (data.scheme === 'quadkey') {
|
|
150
|
-
return [QuadkeyTileLayer, props];
|
|
151
|
-
}
|
|
152
|
-
return props.formatTiles === TILE_FORMATS.MVT ? [MVTLayer, props] : [CartoTileLayer, props];
|
|
153
|
-
}
|
|
154
|
-
// It's a geojson layer
|
|
155
|
-
return [GeoJsonLayer, props];
|
|
156
|
-
}
|
|
157
|
-
renderLayers() {
|
|
158
|
-
assert(this.state);
|
|
159
|
-
const { data } = this.state;
|
|
160
|
-
if (!data)
|
|
161
|
-
return null;
|
|
162
|
-
const { updateTriggers } = this.props;
|
|
163
|
-
const [layer, props] = this._getSubLayerAndProps();
|
|
164
|
-
// eslint-disable-next-line new-cap
|
|
165
|
-
return new layer(props, this.getSubLayerProps({
|
|
166
|
-
id: `carto-${layer.layerName}`,
|
|
167
|
-
data,
|
|
168
|
-
updateTriggers
|
|
169
|
-
}));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
CartoLayer.layerName = 'CartoLayer';
|
|
173
|
-
CartoLayer.defaultProps = defaultProps;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/* global TextDecoder */
|
|
2
|
-
import Protobuf from 'pbf';
|
|
3
|
-
import { log } from '@deck.gl/core';
|
|
4
|
-
import { ClipExtension } from '@deck.gl/extensions';
|
|
5
|
-
import { MVTLayer, _getURLFromTemplate } from '@deck.gl/geo-layers';
|
|
6
|
-
import { GeoJsonLayer } from '@deck.gl/layers';
|
|
7
|
-
import { geojsonToBinary } from '@loaders.gl/gis';
|
|
8
|
-
import { TileReader } from './schema/carto-tile';
|
|
9
|
-
import { TILE_FORMATS } from '../api/maps-api-common';
|
|
10
|
-
function parseJSON(arrayBuffer) {
|
|
11
|
-
return JSON.parse(new TextDecoder().decode(arrayBuffer));
|
|
12
|
-
}
|
|
13
|
-
function parsePbf(buffer) {
|
|
14
|
-
const pbf = new Protobuf(buffer);
|
|
15
|
-
const tile = TileReader.read(pbf);
|
|
16
|
-
return tile;
|
|
17
|
-
}
|
|
18
|
-
function unpackProperties(properties) {
|
|
19
|
-
if (!properties || !properties.length) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
return properties.map(item => {
|
|
23
|
-
const currentRecord = {};
|
|
24
|
-
item.data.forEach(({ key, value }) => {
|
|
25
|
-
currentRecord[key] = value;
|
|
26
|
-
});
|
|
27
|
-
return currentRecord;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function parseCartoTile(arrayBuffer, options) {
|
|
31
|
-
if (!arrayBuffer)
|
|
32
|
-
return null;
|
|
33
|
-
const formatTiles = options && options.cartoTile && options.cartoTile.formatTiles;
|
|
34
|
-
if (formatTiles === TILE_FORMATS.GEOJSON)
|
|
35
|
-
return geojsonToBinary(parseJSON(arrayBuffer).features);
|
|
36
|
-
const tile = parsePbf(arrayBuffer);
|
|
37
|
-
const { points, lines, polygons } = tile;
|
|
38
|
-
const data = {
|
|
39
|
-
points: { ...points, properties: unpackProperties(points.properties) },
|
|
40
|
-
lines: { ...lines, properties: unpackProperties(lines.properties) },
|
|
41
|
-
polygons: { ...polygons, properties: unpackProperties(polygons.properties) }
|
|
42
|
-
};
|
|
43
|
-
// Note: there is slight, difference in `numericProps` type, however geojson/mvtlayer can cope with this
|
|
44
|
-
return data;
|
|
45
|
-
}
|
|
46
|
-
const defaultTileFormat = TILE_FORMATS.BINARY;
|
|
47
|
-
const CartoTileLoader = {
|
|
48
|
-
name: 'CARTO Tile',
|
|
49
|
-
version: '1',
|
|
50
|
-
id: 'cartoTile',
|
|
51
|
-
module: 'carto',
|
|
52
|
-
extensions: ['pbf'],
|
|
53
|
-
mimeTypes: ['application/x-protobuf'],
|
|
54
|
-
category: 'geometry',
|
|
55
|
-
worker: false,
|
|
56
|
-
parse: async (arrayBuffer, options) => parseCartoTile(arrayBuffer, options),
|
|
57
|
-
parseSync: parseCartoTile,
|
|
58
|
-
options: {
|
|
59
|
-
cartoTile: {
|
|
60
|
-
formatTiles: defaultTileFormat
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const defaultProps = {
|
|
65
|
-
...MVTLayer.defaultProps,
|
|
66
|
-
formatTiles: defaultTileFormat,
|
|
67
|
-
loaders: [CartoTileLoader]
|
|
68
|
-
};
|
|
69
|
-
export default class CartoTileLayer extends MVTLayer {
|
|
70
|
-
getTileData(tile) {
|
|
71
|
-
const url = _getURLFromTemplate(this.state.data, tile);
|
|
72
|
-
if (!url) {
|
|
73
|
-
return Promise.reject('Invalid URL');
|
|
74
|
-
}
|
|
75
|
-
let loadOptions = this.getLoadOptions();
|
|
76
|
-
const { fetch, formatTiles } = this.props;
|
|
77
|
-
const { signal } = tile;
|
|
78
|
-
loadOptions = {
|
|
79
|
-
...loadOptions,
|
|
80
|
-
mimeType: 'application/x-protobuf'
|
|
81
|
-
};
|
|
82
|
-
if (formatTiles) {
|
|
83
|
-
log.assert(Object.values(TILE_FORMATS).includes(formatTiles), `Invalid value for formatTiles: ${formatTiles}. Use value from TILE_FORMATS`);
|
|
84
|
-
loadOptions.cartoTile = { formatTiles };
|
|
85
|
-
}
|
|
86
|
-
return fetch(url, { propName: 'data', layer: this, loadOptions, signal });
|
|
87
|
-
}
|
|
88
|
-
renderSubLayers(props) {
|
|
89
|
-
if (props.data === null) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const tileBbox = props.tile.bbox;
|
|
93
|
-
const { west, south, east, north } = tileBbox;
|
|
94
|
-
const subLayerProps = {
|
|
95
|
-
...props,
|
|
96
|
-
autoHighlight: false,
|
|
97
|
-
extensions: [new ClipExtension(), ...(props.extensions || [])],
|
|
98
|
-
clipBounds: [west, south, east, north]
|
|
99
|
-
};
|
|
100
|
-
const subLayer = new GeoJsonLayer(subLayerProps);
|
|
101
|
-
return subLayer;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
CartoTileLayer.layerName = 'CartoTileLayer';
|
|
105
|
-
CartoTileLayer.defaultProps = defaultProps;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { CompositeLayer } from '@deck.gl/core';
|
|
2
|
-
import { H3HexagonLayer } from '@deck.gl/geo-layers';
|
|
3
|
-
import H3Tileset2D from './h3-tileset-2d';
|
|
4
|
-
import SpatialIndexTileLayer from './spatial-index-tile-layer';
|
|
5
|
-
const renderSubLayers = props => {
|
|
6
|
-
const { data } = props;
|
|
7
|
-
const { index } = props.tile;
|
|
8
|
-
if (!data || !data.length)
|
|
9
|
-
return null;
|
|
10
|
-
return new H3HexagonLayer(props, {
|
|
11
|
-
getHexagon: d => d.id,
|
|
12
|
-
centerHexagon: index,
|
|
13
|
-
highPrecision: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
const defaultProps = {
|
|
17
|
-
aggregationResLevel: 4
|
|
18
|
-
};
|
|
19
|
-
export default class H3TileLayer extends CompositeLayer {
|
|
20
|
-
initializeState() {
|
|
21
|
-
this.setState({ data: null, tileJSON: null });
|
|
22
|
-
}
|
|
23
|
-
updateState({ changeFlags }) {
|
|
24
|
-
if (changeFlags.dataChanged) {
|
|
25
|
-
let { data } = this.props;
|
|
26
|
-
const tileJSON = data;
|
|
27
|
-
data = tileJSON.tiles;
|
|
28
|
-
this.setState({ data, tileJSON });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
renderLayers() {
|
|
32
|
-
const { data, tileJSON } = this.state;
|
|
33
|
-
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
34
|
-
return [
|
|
35
|
-
new SpatialIndexTileLayer(this.props, {
|
|
36
|
-
id: `h3-tile-layer-${this.props.id}`,
|
|
37
|
-
data,
|
|
38
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
39
|
-
TilesetClass: H3Tileset2D,
|
|
40
|
-
renderSubLayers,
|
|
41
|
-
maxZoom
|
|
42
|
-
})
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
H3TileLayer.layerName = 'H3TileLayer';
|
|
47
|
-
H3TileLayer.defaultProps = defaultProps;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { _Tileset2D as Tileset2D } from '@deck.gl/geo-layers';
|
|
2
|
-
import { polyfill, geoToH3, h3GetResolution, h3ToGeoBoundary, h3ToParent, kRing } from 'h3-js';
|
|
3
|
-
function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
|
|
4
|
-
if (Math.abs(east - west) > 180) {
|
|
5
|
-
// This is a known issue in h3-js: polyfill does not work correctly
|
|
6
|
-
// when longitude span is larger than 180 degrees.
|
|
7
|
-
return [
|
|
8
|
-
...new Set(getHexagonsInBoundingBox({ west, north, east: 0, south }, resolution).concat(getHexagonsInBoundingBox({ west: 0, north, east, south }, resolution)))
|
|
9
|
-
];
|
|
10
|
-
}
|
|
11
|
-
// `polyfill()` fills based on hexagon center, which means tiles vanish
|
|
12
|
-
// prematurely. Get more accurate coverage by oversampling
|
|
13
|
-
const oversample = 2;
|
|
14
|
-
const h3Indices = polyfill([
|
|
15
|
-
[
|
|
16
|
-
[west, north],
|
|
17
|
-
[west, south],
|
|
18
|
-
[east, south],
|
|
19
|
-
[east, north],
|
|
20
|
-
[west, north]
|
|
21
|
-
]
|
|
22
|
-
], resolution + oversample, true);
|
|
23
|
-
return oversample ? [...new Set(h3Indices.map(i => h3ToParent(i, resolution)))] : h3Indices;
|
|
24
|
-
}
|
|
25
|
-
function tileToBoundingBox(index) {
|
|
26
|
-
const coordinates = h3ToGeoBoundary(index);
|
|
27
|
-
const latitudes = coordinates.map(c => c[0]);
|
|
28
|
-
const longitudes = coordinates.map(c => c[1]);
|
|
29
|
-
const west = Math.min(...longitudes);
|
|
30
|
-
const south = Math.min(...latitudes);
|
|
31
|
-
const east = Math.max(...longitudes);
|
|
32
|
-
const north = Math.max(...latitudes);
|
|
33
|
-
return { west, south, east, north };
|
|
34
|
-
}
|
|
35
|
-
// Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
36
|
-
// a H3 resolution such that the screen space size of the hexagons is
|
|
37
|
-
// similar
|
|
38
|
-
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
39
|
-
const BIAS = 2;
|
|
40
|
-
function getHexagonResolution(viewport) {
|
|
41
|
-
const hexagonScaleFactor = (2 / 3) * viewport.zoom;
|
|
42
|
-
const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180));
|
|
43
|
-
// Clip and bias
|
|
44
|
-
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
45
|
-
}
|
|
46
|
-
export default class H3Tileset2D extends Tileset2D {
|
|
47
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
48
|
-
getTileIndices({ viewport, minZoom, maxZoom }) {
|
|
49
|
-
const [east, south, west, north] = viewport.getBounds();
|
|
50
|
-
let z = getHexagonResolution(viewport);
|
|
51
|
-
let indices;
|
|
52
|
-
if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
|
|
53
|
-
z = minZoom;
|
|
54
|
-
}
|
|
55
|
-
if (typeof maxZoom === 'number' && Number.isFinite(maxZoom) && z > maxZoom) {
|
|
56
|
-
z = maxZoom;
|
|
57
|
-
// Once we are at max zoom, getHexagonsInBoundingBox doesn't work, simply
|
|
58
|
-
// get a ring centered on the hexagon in the viewport center
|
|
59
|
-
const center = geoToH3(viewport.latitude, viewport.longitude, maxZoom);
|
|
60
|
-
indices = kRing(center, 1);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
indices = getHexagonsInBoundingBox({ west, north, east, south }, z);
|
|
64
|
-
}
|
|
65
|
-
return indices.map(i => ({ i }));
|
|
66
|
-
}
|
|
67
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
68
|
-
getTileId({ i }) {
|
|
69
|
-
return i;
|
|
70
|
-
}
|
|
71
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
72
|
-
getTileMetadata({ i }) {
|
|
73
|
-
return { bbox: tileToBoundingBox(i) };
|
|
74
|
-
}
|
|
75
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
76
|
-
getTileZoom({ i }) {
|
|
77
|
-
return h3GetResolution(i);
|
|
78
|
-
}
|
|
79
|
-
// @ts-expect-error Tileset2D should be generic over TileIndex
|
|
80
|
-
getParentIndex(index) {
|
|
81
|
-
const resolution = h3GetResolution(index.i);
|
|
82
|
-
const i = h3ToParent(index.i, resolution - 1);
|
|
83
|
-
return { i };
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CompositeLayer, CompositeLayerProps, Layer, LayersList, UpdateParameters, DefaultProps } from '@deck.gl/core/typed';
|
|
2
|
-
import { QuadkeyLayerProps } from '@deck.gl/geo-layers/typed';
|
|
3
|
-
/** All properties supported by QuadkeyTileLayer. */
|
|
4
|
-
export declare type QuadkeyTileLayerProps<DataT = any> = _QuadkeyTileLayerProps<DataT> & CompositeLayerProps<DataT>;
|
|
5
|
-
/** Properties added by QuadkeyTileLayer. */
|
|
6
|
-
declare type _QuadkeyTileLayerProps<DataT> = QuadkeyLayerProps<DataT> & {
|
|
7
|
-
aggregationResLevel?: number;
|
|
8
|
-
};
|
|
9
|
-
export default class QuadkeyTileLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<ExtraProps & Required<_QuadkeyTileLayerProps<DataT>>> {
|
|
10
|
-
static layerName: string;
|
|
11
|
-
static defaultProps: DefaultProps<QuadkeyTileLayerProps<any>>;
|
|
12
|
-
state: {
|
|
13
|
-
tileJSON: any;
|
|
14
|
-
data: any;
|
|
15
|
-
};
|
|
16
|
-
initializeState(): void;
|
|
17
|
-
updateState({ changeFlags }: UpdateParameters<this>): void;
|
|
18
|
-
renderLayers(): Layer | null | LayersList;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=quadkey-tile-layer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quadkey-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/quadkey-tile-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAe,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAcpE,oDAAoD;AACpD,oBAAY,qBAAqB,CAAC,KAAK,GAAG,GAAG,IAAI,sBAAsB,CAAC,KAAK,CAAC,GAC5E,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAE7B,4CAA4C;AAC5C,aAAK,sBAAsB,CAAC,KAAK,IAAI,iBAAiB,CAAC,KAAK,CAAC,GAAG;IAC9D,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAgB,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,EAAE,CAAE,SAAQ,cAAc,CACxF,UAAU,GAAG,QAAQ,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CACrD;IACC,MAAM,CAAC,SAAS,SAAsB;IACtC,MAAM,CAAC,YAAY,2CAAgB;IAEnC,KAAK,EAAG;QACN,QAAQ,EAAE,GAAG,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;IACF,eAAe,IAAI,IAAI;IAIvB,WAAW,CAAC,EAAC,WAAW,EAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IASxD,YAAY,IAAI,KAAK,GAAG,IAAI,GAAG,UAAU;CAc1C"}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
const renderSubLayers = props => {
|
|
6
|
-
const { data } = props;
|
|
7
|
-
if (!data || !data.length)
|
|
8
|
-
return null;
|
|
9
|
-
return new QuadkeyLayer(props, { getQuadkey: d => d.id });
|
|
10
|
-
};
|
|
11
|
-
const defaultProps = {
|
|
12
|
-
aggregationResLevel: 6
|
|
13
|
-
};
|
|
14
|
-
export default class QuadkeyTileLayer extends CompositeLayer {
|
|
15
|
-
initializeState() {
|
|
16
|
-
this.setState({ data: null, tileJSON: null });
|
|
17
|
-
}
|
|
18
|
-
updateState({ changeFlags }) {
|
|
19
|
-
if (changeFlags.dataChanged) {
|
|
20
|
-
let { data } = this.props;
|
|
21
|
-
const tileJSON = data;
|
|
22
|
-
data = tileJSON.tiles;
|
|
23
|
-
this.setState({ data, tileJSON });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
renderLayers() {
|
|
27
|
-
const { data, tileJSON } = this.state;
|
|
28
|
-
const maxZoom = parseInt(tileJSON?.maxresolution);
|
|
29
|
-
return [
|
|
30
|
-
new SpatialIndexTileLayer(this.props, {
|
|
31
|
-
id: `quadkey-tile-layer-${this.props.id}`,
|
|
32
|
-
data,
|
|
33
|
-
// TODO: Tileset2D should be generic over TileIndex type
|
|
34
|
-
TilesetClass: QuadkeyTileset2D,
|
|
35
|
-
renderSubLayers,
|
|
36
|
-
maxZoom
|
|
37
|
-
})
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
QuadkeyTileLayer.layerName = 'QuadkeyTileLayer';
|
|
42
|
-
QuadkeyTileLayer.defaultProps = defaultProps;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { _Tileset2D as Tileset2D } from '@deck.gl/geo-layers/typed';
|
|
2
|
-
declare type QuadkeyTileIndex = {
|
|
3
|
-
i: string;
|
|
4
|
-
};
|
|
5
|
-
export default class QuadkeyTileset2D extends Tileset2D {
|
|
6
|
-
getTileIndices(opts: any): QuadkeyTileIndex[];
|
|
7
|
-
getTileId({ i }: QuadkeyTileIndex): string;
|
|
8
|
-
getTileMetadata(index: QuadkeyTileIndex): Record<string, any>;
|
|
9
|
-
getTileZoom({ i }: QuadkeyTileIndex): number;
|
|
10
|
-
getParentIndex(index: QuadkeyTileIndex): {
|
|
11
|
-
i: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=quadkey-tileset-2d.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quadkey-tileset-2d.d.ts","sourceRoot":"","sources":["../../src/layers/quadkey-tileset-2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,IAAI,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE5D,aAAK,gBAAgB,GAAG;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AA8BpC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IAErD,cAAc,CAAC,IAAI,KAAA,GAAG,gBAAgB,EAAE;IAKxC,SAAS,CAAC,EAAC,CAAC,EAAC,EAAE,gBAAgB;IAK/B,eAAe,CAAC,KAAK,EAAE,gBAAgB;IAKvC,WAAW,CAAC,EAAC,CAAC,EAAC,EAAE,gBAAgB;IAKjC,cAAc,CAAC,KAAK,EAAE,gBAAgB;;;CAIvC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { _Tileset2D as Tileset2D } from '@deck.gl/geo-layers';
|
|
2
|
-
function tileToQuadkey(tile) {
|
|
3
|
-
let index = '';
|
|
4
|
-
for (let z = tile.z; z > 0; z--) {
|
|
5
|
-
let b = 0;
|
|
6
|
-
const mask = 1 << (z - 1);
|
|
7
|
-
if ((tile.x & mask) !== 0)
|
|
8
|
-
b++;
|
|
9
|
-
if ((tile.y & mask) !== 0)
|
|
10
|
-
b += 2;
|
|
11
|
-
index += b.toString();
|
|
12
|
-
}
|
|
13
|
-
return { i: index };
|
|
14
|
-
}
|
|
15
|
-
export default class QuadkeyTileset2D extends Tileset2D {
|
|
16
|
-
// @ts-expect-error for spatial indices, TileSet2d should be parametrized by TileIndexT
|
|
17
|
-
getTileIndices(opts) {
|
|
18
|
-
return super.getTileIndices(opts).map(tileToQuadkey);
|
|
19
|
-
}
|
|
20
|
-
// @ts-expect-error TileIndex must be generic
|
|
21
|
-
getTileId({ i }) {
|
|
22
|
-
return i;
|
|
23
|
-
}
|
|
24
|
-
getTileMetadata() {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
// @ts-expect-error TileIndex must be generic
|
|
28
|
-
getTileZoom({ i }) {
|
|
29
|
-
return i.length;
|
|
30
|
-
}
|
|
31
|
-
// @ts-expect-error TileIndex must be generic
|
|
32
|
-
getParentIndex(index) {
|
|
33
|
-
const i = index.i.slice(0, -1);
|
|
34
|
-
return { i };
|
|
35
|
-
}
|
|
36
|
-
}
|