@deck.gl/carto 8.8.0-alpha.4 → 8.8.0-beta.1
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 +14087 -14019
- package/dist/es5/api/layer-map.js +7 -5
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/carto-tile-layer.js +17 -12
- package/dist/es5/layers/carto-tile-layer.js.map +1 -1
- package/dist/es5/layers/h3-tile-layer.js +21 -11
- package/dist/es5/layers/h3-tile-layer.js.map +1 -1
- package/dist/es5/layers/h3-tileset-2d.js +4 -8
- package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
- package/dist/es5/layers/quadkey-tile-layer.js +24 -13
- package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -1
- package/dist/es5/layers/schema/carto-tile.js +261 -188
- package/dist/es5/layers/schema/carto-tile.js.map +1 -1
- package/dist/es5/layers/spatial-index-tile-layer.js +3 -0
- package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist/esm/api/layer-map.js +8 -6
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/carto-tile-layer.js +20 -16
- package/dist/esm/layers/carto-tile-layer.js.map +1 -1
- package/dist/esm/layers/h3-tile-layer.js +13 -7
- package/dist/esm/layers/h3-tile-layer.js.map +1 -1
- package/dist/esm/layers/h3-tileset-2d.js +5 -9
- package/dist/esm/layers/h3-tileset-2d.js.map +1 -1
- package/dist/esm/layers/quadkey-tile-layer.js +16 -9
- package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -1
- package/dist/esm/layers/schema/carto-tile.js +174 -189
- package/dist/esm/layers/schema/carto-tile.js.map +1 -1
- 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 +4 -4
- package/package.json +11 -8
- package/src/api/layer-map.ts +16 -7
- package/src/layers/carto-layer.ts +11 -4
- package/src/layers/{carto-tile-layer.js → carto-tile-layer.ts} +63 -26
- package/src/layers/h3-tile-layer.ts +78 -0
- package/src/layers/{h3-tileset-2d.js → h3-tileset-2d.ts} +29 -26
- package/src/layers/quadkey-tile-layer.ts +68 -0
- package/src/layers/{quadkey-tileset-2d.js → quadkey-tileset-2d.ts} +10 -5
- package/src/layers/schema/carto-tile.ts +221 -0
- package/src/layers/{spatial-index-tile-layer.js → spatial-index-tile-layer.ts} +9 -6
- package/typed/api/index.d.ts +4 -0
- package/typed/api/index.d.ts.map +1 -0
- package/typed/api/index.js +3 -0
- package/typed/api/layer-map.d.ts +54 -0
- package/typed/api/layer-map.d.ts.map +1 -0
- package/typed/api/layer-map.js +264 -0
- package/typed/api/maps-api-common.d.ts +65 -0
- package/typed/api/maps-api-common.d.ts.map +1 -0
- package/typed/api/maps-api-common.js +50 -0
- package/typed/api/maps-client.d.ts +18 -0
- package/typed/api/maps-client.d.ts.map +1 -0
- package/typed/api/maps-client.js +125 -0
- package/typed/api/maps-v3-client.d.ts +45 -0
- package/typed/api/maps-v3-client.d.ts.map +1 -0
- package/typed/api/maps-v3-client.js +304 -0
- package/typed/api/parseMap.d.ts +11 -0
- package/typed/api/parseMap.d.ts.map +1 -0
- package/typed/api/parseMap.js +178 -0
- package/typed/basemap.d.ts +10 -0
- package/typed/basemap.d.ts.map +1 -0
- package/typed/basemap.js +9 -0
- package/typed/config.d.ts +26 -0
- package/typed/config.d.ts.map +1 -0
- package/typed/config.js +35 -0
- package/typed/index.d.ts +12 -0
- package/typed/index.d.ts.map +1 -0
- package/typed/index.js +10 -0
- package/typed/layers/carto-layer.d.ts +98 -0
- package/typed/layers/carto-layer.d.ts.map +1 -0
- package/typed/layers/carto-layer.js +173 -0
- package/typed/layers/carto-tile-layer.d.ts +63 -0
- package/typed/layers/carto-tile-layer.d.ts.map +1 -0
- package/typed/layers/carto-tile-layer.js +105 -0
- package/typed/layers/h3-tile-layer.d.ts +23 -0
- package/typed/layers/h3-tile-layer.d.ts.map +1 -0
- package/typed/layers/h3-tile-layer.js +47 -0
- package/typed/layers/h3-tileset-2d.d.ts +18 -0
- package/typed/layers/h3-tileset-2d.d.ts.map +1 -0
- package/typed/layers/h3-tileset-2d.js +85 -0
- package/typed/layers/quadkey-tile-layer.d.ts +23 -0
- package/typed/layers/quadkey-tile-layer.d.ts.map +1 -0
- package/typed/layers/quadkey-tile-layer.js +42 -0
- package/typed/layers/quadkey-tileset-2d.d.ts +15 -0
- package/typed/layers/quadkey-tileset-2d.d.ts.map +1 -0
- package/typed/layers/quadkey-tileset-2d.js +36 -0
- package/typed/layers/schema/carto-tile.d.ts +44 -0
- package/typed/layers/schema/carto-tile.d.ts.map +1 -0
- package/typed/layers/schema/carto-tile.js +161 -0
- package/typed/layers/spatial-index-tile-layer.d.ts +12 -0
- package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -0
- package/typed/layers/spatial-index-tile-layer.js +40 -0
- package/typed/package.json +6 -0
- package/typed/style/color-bins-style.d.ts +9 -0
- package/typed/style/color-bins-style.d.ts.map +1 -0
- package/typed/style/color-bins-style.js +12 -0
- package/typed/style/color-categories-style.d.ts +10 -0
- package/typed/style/color-categories-style.d.ts.map +1 -0
- package/typed/style/color-categories-style.js +16 -0
- package/typed/style/color-continuous-style.d.ts +9 -0
- package/typed/style/color-continuous-style.d.ts.map +1 -0
- package/typed/style/color-continuous-style.js +12 -0
- package/typed/style/palette.d.ts +7 -0
- package/typed/style/palette.d.ts.map +1 -0
- package/typed/style/palette.js +62 -0
- package/typed/style/utils.d.ts +8 -0
- package/typed/style/utils.d.ts.map +1 -0
- package/typed/style/utils.js +15 -0
- package/typed/utils.d.ts +2 -0
- package/typed/utils.d.ts.map +1 -0
- package/typed/utils.js +4 -0
- package/src/layers/h3-tile-layer.js +0 -52
- package/src/layers/quadkey-tile-layer.js +0 -47
- package/src/layers/schema/carto-tile.js +0 -195
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TileLayer } from '@deck.gl/geo-layers';
|
|
2
|
+
function isFeatureIdDefined(value) {
|
|
3
|
+
return value !== undefined && value !== null && value !== '';
|
|
4
|
+
}
|
|
5
|
+
export default class SpatialIndexTileLayer extends TileLayer {
|
|
6
|
+
_updateAutoHighlight(info) {
|
|
7
|
+
const { hoveredFeatureId } = this.state;
|
|
8
|
+
const hoveredFeature = info.object;
|
|
9
|
+
let newHoveredFeatureId;
|
|
10
|
+
if (hoveredFeature) {
|
|
11
|
+
newHoveredFeatureId = hoveredFeature.id;
|
|
12
|
+
}
|
|
13
|
+
if (hoveredFeatureId !== newHoveredFeatureId) {
|
|
14
|
+
let { highlightColor } = this.props;
|
|
15
|
+
if (typeof highlightColor === 'function') {
|
|
16
|
+
highlightColor = highlightColor(info);
|
|
17
|
+
}
|
|
18
|
+
this.setState({
|
|
19
|
+
highlightColor,
|
|
20
|
+
hoveredFeatureId: newHoveredFeatureId
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getSubLayerPropsByTile(tile) {
|
|
25
|
+
return {
|
|
26
|
+
highlightedObjectIndex: this.getHighlightedObjectIndex(tile),
|
|
27
|
+
highlightColor: this.state.highlightColor
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
getHighlightedObjectIndex(tile) {
|
|
31
|
+
const { hoveredFeatureId } = this.state;
|
|
32
|
+
const data = tile.content;
|
|
33
|
+
const isFeatureIdPresent = isFeatureIdDefined(hoveredFeatureId);
|
|
34
|
+
if (!isFeatureIdPresent || !Array.isArray(data)) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
return data.findIndex(feature => feature.id === hoveredFeatureId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
SpatialIndexTileLayer.layerName = 'SpatialIndexTileLayer';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Color } from './palette';
|
|
2
|
+
import { AttributeSelector } from './utils';
|
|
3
|
+
export default function colorBins({ attr, domain, colors, nullColor }: {
|
|
4
|
+
attr: AttributeSelector;
|
|
5
|
+
domain: number[];
|
|
6
|
+
colors?: string | Color[];
|
|
7
|
+
nullColor?: Color;
|
|
8
|
+
}): AttributeSelector;
|
|
9
|
+
//# sourceMappingURL=color-bins-style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-bins-style.d.ts","sourceRoot":"","sources":["../../src/style/color-bins-style.ts"],"names":[],"mappings":"AACA,OAAmB,EAAC,KAAK,EAA8B,MAAM,WAAW,CAAC;AACzE,OAAO,EAAS,iBAAiB,EAAe,MAAM,SAAS,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,MAAwB,EACxB,SAAsB,EACvB,EAAE;IACD,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,GAAG,iBAAiB,CAWpB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { scaleThreshold } from 'd3-scale';
|
|
2
|
+
import getPalette, { DEFAULT_PALETTE, NULL_COLOR } from './palette';
|
|
3
|
+
import { assert, getAttrValue } from './utils';
|
|
4
|
+
export default function colorBins({ attr, domain, colors = DEFAULT_PALETTE, nullColor = NULL_COLOR }) {
|
|
5
|
+
assert(Array.isArray(domain), 'Expected "domain" to be an array of numbers');
|
|
6
|
+
const palette = typeof colors === 'string' ? getPalette(colors, domain.length + 1) : colors;
|
|
7
|
+
const color = scaleThreshold().domain(domain).range(palette);
|
|
8
|
+
return d => {
|
|
9
|
+
const value = getAttrValue(attr, d);
|
|
10
|
+
return typeof value === 'number' && Number.isFinite(value) ? color(value) : nullColor;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Color } from './palette';
|
|
2
|
+
import { AttributeSelector } from './utils';
|
|
3
|
+
export default function colorCategories({ attr, domain, colors, nullColor, othersColor }: {
|
|
4
|
+
attr: AttributeSelector;
|
|
5
|
+
domain: number[];
|
|
6
|
+
colors: string | Color[];
|
|
7
|
+
nullColor?: Color;
|
|
8
|
+
othersColor?: Color;
|
|
9
|
+
}): AttributeSelector;
|
|
10
|
+
//# sourceMappingURL=color-categories-style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-categories-style.d.ts","sourceRoot":"","sources":["../../src/style/color-categories-style.ts"],"names":[],"mappings":"AAAA,OAAmB,EAAC,KAAK,EAA4C,MAAM,WAAW,CAAC;AACvF,OAAO,EAAS,iBAAiB,EAAe,MAAM,SAAS,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,IAAI,EACJ,MAAM,EACN,MAAwB,EACxB,SAAsB,EACtB,WAA0B,EAC3B,EAAE;IACD,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,GAAG,iBAAiB,CAgBpB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import getPalette, { DEFAULT_PALETTE, NULL_COLOR, OTHERS_COLOR } from './palette';
|
|
2
|
+
import { assert, getAttrValue } from './utils';
|
|
3
|
+
export default function colorCategories({ attr, domain, colors = DEFAULT_PALETTE, nullColor = NULL_COLOR, othersColor = OTHERS_COLOR }) {
|
|
4
|
+
assert(Array.isArray(domain), 'Expected "domain" to be an array of numbers or strings');
|
|
5
|
+
const colorsByCategory = {};
|
|
6
|
+
const palette = typeof colors === 'string' ? getPalette(colors, domain.length) : colors;
|
|
7
|
+
for (const [i, c] of domain.entries()) {
|
|
8
|
+
colorsByCategory[c] = palette[i];
|
|
9
|
+
}
|
|
10
|
+
return d => {
|
|
11
|
+
const value = getAttrValue(attr, d);
|
|
12
|
+
return (typeof value === 'number' && Number.isFinite(value)) || typeof value === 'string'
|
|
13
|
+
? colorsByCategory[value] || othersColor
|
|
14
|
+
: nullColor;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Color } from './palette';
|
|
2
|
+
import { AttributeSelector } from './utils';
|
|
3
|
+
export default function colorContinuous({ attr, domain, colors, nullColor }: {
|
|
4
|
+
attr: AttributeSelector;
|
|
5
|
+
domain: number[];
|
|
6
|
+
colors?: string | Color[];
|
|
7
|
+
nullColor?: Color;
|
|
8
|
+
}): AttributeSelector;
|
|
9
|
+
//# sourceMappingURL=color-continuous-style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-continuous-style.d.ts","sourceRoot":"","sources":["../../src/style/color-continuous-style.ts"],"names":[],"mappings":"AACA,OAAmB,EAAC,KAAK,EAA8B,MAAM,WAAW,CAAC;AACzE,OAAO,EAAS,iBAAiB,EAAe,MAAM,SAAS,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,IAAI,EACJ,MAAM,EACN,MAAwB,EACxB,SAAsB,EACvB,EAAE;IACD,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,GAAG,iBAAiB,CAUpB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { scaleLinear } from 'd3-scale';
|
|
2
|
+
import getPalette, { DEFAULT_PALETTE, NULL_COLOR } from './palette';
|
|
3
|
+
import { assert, getAttrValue } from './utils';
|
|
4
|
+
export default function colorContinuous({ attr, domain, colors = DEFAULT_PALETTE, nullColor = NULL_COLOR }) {
|
|
5
|
+
assert(Array.isArray(domain), 'Expected "domain" to be an array of numbers');
|
|
6
|
+
const palette = typeof colors === 'string' ? getPalette(colors, domain.length) : colors;
|
|
7
|
+
const color = scaleLinear().domain(domain).range(palette);
|
|
8
|
+
return d => {
|
|
9
|
+
const value = getAttrValue(attr, d);
|
|
10
|
+
return typeof value === 'number' && Number.isFinite(value) ? color(value) : nullColor;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type Color = [r: number, b: number, g: number, a?: number];
|
|
2
|
+
export declare const DEFAULT_PALETTE = "PurpOr";
|
|
3
|
+
export declare const NULL_COLOR: Color;
|
|
4
|
+
export declare const OTHERS_COLOR: Color;
|
|
5
|
+
export default function getPalette(name: string, numCategories: number): Color[];
|
|
6
|
+
export declare function hexToRgb(hex: string): Color;
|
|
7
|
+
//# sourceMappingURL=palette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/style/palette.ts"],"names":[],"mappings":"AAGA,oBAAY,KAAK,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAElE,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,UAAU,EAAE,KAAuB,CAAC;AACjD,eAAO,MAAM,YAAY,EAAE,KAAuB,CAAC;AAOnD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,KAAK,EAAE,CA0B/E;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CA2C3C"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as cartoColors from 'cartocolor';
|
|
2
|
+
import { assert } from './utils';
|
|
3
|
+
export const DEFAULT_PALETTE = 'PurpOr';
|
|
4
|
+
export const NULL_COLOR = [204, 204, 204];
|
|
5
|
+
export const OTHERS_COLOR = [119, 119, 119];
|
|
6
|
+
export default function getPalette(name, numCategories) {
|
|
7
|
+
const palette = cartoColors[name];
|
|
8
|
+
let paletteIndex = numCategories;
|
|
9
|
+
assert(palette, `Palette "${name}" not found. Expected a CARTOColors string`);
|
|
10
|
+
const palettesColorVariants = Object.keys(palette)
|
|
11
|
+
.filter(p => p !== 'tags')
|
|
12
|
+
.map(Number);
|
|
13
|
+
const longestPaletteIndex = Math.max(...palettesColorVariants);
|
|
14
|
+
const smallestPaletteIndex = Math.min(...palettesColorVariants);
|
|
15
|
+
if (!Number.isInteger(numCategories) || numCategories > longestPaletteIndex) {
|
|
16
|
+
paletteIndex = longestPaletteIndex;
|
|
17
|
+
}
|
|
18
|
+
else if (numCategories < smallestPaletteIndex) {
|
|
19
|
+
paletteIndex = smallestPaletteIndex;
|
|
20
|
+
}
|
|
21
|
+
let colors = palette[paletteIndex];
|
|
22
|
+
if (palette.tags && palette.tags.includes('qualitative')) {
|
|
23
|
+
colors = colors.slice(0, -1);
|
|
24
|
+
}
|
|
25
|
+
return colors.map(c => hexToRgb(c));
|
|
26
|
+
}
|
|
27
|
+
export function hexToRgb(hex) {
|
|
28
|
+
// Evaluate #ABC
|
|
29
|
+
let result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(hex);
|
|
30
|
+
if (result) {
|
|
31
|
+
return [
|
|
32
|
+
parseInt(result[1] + result[1], 16),
|
|
33
|
+
parseInt(result[2] + result[2], 16),
|
|
34
|
+
parseInt(result[3] + result[3], 16),
|
|
35
|
+
255
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
// Evaluate #ABCD
|
|
39
|
+
result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(hex);
|
|
40
|
+
if (result) {
|
|
41
|
+
return [
|
|
42
|
+
parseInt(result[1] + result[1], 16),
|
|
43
|
+
parseInt(result[2] + result[2], 16),
|
|
44
|
+
parseInt(result[3] + result[3], 16),
|
|
45
|
+
parseInt(result[4] + result[4], 16)
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
// Evaluate #ABCDEF
|
|
49
|
+
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
50
|
+
if (result) {
|
|
51
|
+
return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16), 255];
|
|
52
|
+
}
|
|
53
|
+
// Evaluate #ABCDEFAF
|
|
54
|
+
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
55
|
+
assert(result, `Hexadecimal color "${hex}" was not parsed correctly`);
|
|
56
|
+
return [
|
|
57
|
+
parseInt(result[1], 16),
|
|
58
|
+
parseInt(result[2], 16),
|
|
59
|
+
parseInt(result[3], 16),
|
|
60
|
+
parseInt(result[4], 16)
|
|
61
|
+
];
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare type Row = {
|
|
2
|
+
properties: Record<string, unknown>;
|
|
3
|
+
};
|
|
4
|
+
export declare type AttributeSelector = string | ((d: Row) => unknown);
|
|
5
|
+
export declare function getAttrValue(attr: AttributeSelector, d: Row): unknown;
|
|
6
|
+
export declare function assert(condition: any, message?: string): asserts condition;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/style/utils.ts"],"names":[],"mappings":"AAEA,aAAK,GAAG,GAAG;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAC,CAAC;AACjD,oBAAY,iBAAiB,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;AAE/D,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,CASrE;AAED,wBAAgB,MAAM,CAAC,SAAS,KAAA,EAAE,OAAO,SAAK,GAAG,OAAO,CAAC,SAAS,CAIjE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const ALLOWED_ATTR_TYPES = Object.freeze(['function', 'string']);
|
|
2
|
+
export function getAttrValue(attr, d) {
|
|
3
|
+
assert(typeof d === 'object', 'Expected "data" to be an object');
|
|
4
|
+
assert(ALLOWED_ATTR_TYPES.includes(typeof attr), 'Expected "attr" to be a function or string');
|
|
5
|
+
// Is function
|
|
6
|
+
if (typeof attr === 'function') {
|
|
7
|
+
return attr(d);
|
|
8
|
+
}
|
|
9
|
+
return d.properties[attr];
|
|
10
|
+
}
|
|
11
|
+
export function assert(condition, message = '') {
|
|
12
|
+
if (!condition) {
|
|
13
|
+
throw new Error(`CARTO style error: ${message}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/typed/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAE9E"}
|
package/typed/utils.js
ADDED
|
@@ -1,52 +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
|
-
|
|
6
|
-
const renderSubLayers = props => {
|
|
7
|
-
const {data} = props;
|
|
8
|
-
const {index} = props.tile;
|
|
9
|
-
if (!data || !data.length) return null;
|
|
10
|
-
|
|
11
|
-
return new H3HexagonLayer(props, {
|
|
12
|
-
centerHexagon: index,
|
|
13
|
-
highPrecision: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const defaultProps = {
|
|
18
|
-
aggregationResLevel: 4
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default class H3TileLayer extends CompositeLayer {
|
|
22
|
-
initializeState() {
|
|
23
|
-
this.setState({data: null, tileJSON: null});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
updateState({props, oldProps, context, changeFlags}) {
|
|
27
|
-
if (changeFlags.dataChanged) {
|
|
28
|
-
let {data} = this.props;
|
|
29
|
-
const tileJSON = data;
|
|
30
|
-
data = tileJSON.tiles;
|
|
31
|
-
this.setState({data, tileJSON});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
renderLayers() {
|
|
36
|
-
const {data, tileJSON} = this.state;
|
|
37
|
-
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
38
|
-
return [
|
|
39
|
-
new SpatialIndexTileLayer(this.props, {
|
|
40
|
-
id: 'h3-tile-layer',
|
|
41
|
-
data,
|
|
42
|
-
getHexagon: d => d.id,
|
|
43
|
-
TilesetClass: H3Tileset2D,
|
|
44
|
-
renderSubLayers,
|
|
45
|
-
maxZoom
|
|
46
|
-
})
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
H3TileLayer.layerName = 'H3TileLayer';
|
|
52
|
-
H3TileLayer.defaultProps = defaultProps;
|
|
@@ -1,47 +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
|
-
|
|
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;
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// KeyValueObject ========================================
|
|
2
|
-
|
|
3
|
-
const KeyValueObject = {};
|
|
4
|
-
|
|
5
|
-
KeyValueObject.read = function (pbf, end) {
|
|
6
|
-
return pbf.readFields(KeyValueObject._readField, {key: '', value: ''}, end);
|
|
7
|
-
};
|
|
8
|
-
KeyValueObject._readField = function (tag, obj, pbf) {
|
|
9
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
10
|
-
else if (tag === 2) obj.value = pbf.readString();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Properties ========================================
|
|
14
|
-
|
|
15
|
-
const Properties = {};
|
|
16
|
-
|
|
17
|
-
Properties.read = function (pbf, end) {
|
|
18
|
-
return pbf.readFields(Properties._readField, {data: []}, end);
|
|
19
|
-
};
|
|
20
|
-
Properties._readField = function (tag, obj, pbf) {
|
|
21
|
-
if (tag === 1) obj.data.push(KeyValueObject.read(pbf, pbf.readVarint() + pbf.pos));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Doubles ========================================
|
|
25
|
-
|
|
26
|
-
const Doubles = {};
|
|
27
|
-
|
|
28
|
-
Doubles.read = function (pbf, end) {
|
|
29
|
-
// TODO perhaps we can do better and directly map from the source
|
|
30
|
-
// ArrayBuffer using ArrayBuffer.slice()
|
|
31
|
-
const {value, size} = pbf.readFields(Doubles._readField, {value: [], size: 0}, end);
|
|
32
|
-
return {value: new Float32Array(value), size};
|
|
33
|
-
};
|
|
34
|
-
Doubles._readField = function (tag, obj, pbf) {
|
|
35
|
-
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
36
|
-
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Ints ========================================
|
|
40
|
-
|
|
41
|
-
const Ints = {};
|
|
42
|
-
|
|
43
|
-
Ints.read = function (pbf, end) {
|
|
44
|
-
const {value, size} = pbf.readFields(Ints._readField, {value: [], size: 0}, end);
|
|
45
|
-
return {value: new Uint32Array(value), size};
|
|
46
|
-
};
|
|
47
|
-
Ints._readField = function (tag, obj, pbf) {
|
|
48
|
-
if (tag === 1) pbf.readPackedVarint(obj.value);
|
|
49
|
-
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// NumericProp ========================================
|
|
53
|
-
|
|
54
|
-
const NumericProp = {};
|
|
55
|
-
|
|
56
|
-
NumericProp.read = function (pbf, end) {
|
|
57
|
-
return pbf.readFields(NumericProp._readField, {value: []}, end);
|
|
58
|
-
};
|
|
59
|
-
NumericProp._readField = function (tag, obj, pbf) {
|
|
60
|
-
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// NumericPropKeyValue ========================================
|
|
64
|
-
|
|
65
|
-
const NumericPropKeyValue = {};
|
|
66
|
-
|
|
67
|
-
NumericPropKeyValue.read = function (pbf, end) {
|
|
68
|
-
return pbf.readFields(NumericPropKeyValue._readField, {key: '', value: null}, end);
|
|
69
|
-
};
|
|
70
|
-
NumericPropKeyValue._readField = function (tag, obj, pbf) {
|
|
71
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
72
|
-
else if (tag === 2) obj.value = NumericProp.read(pbf, pbf.readVarint() + pbf.pos);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// NumericProp._FieldEntry1 ========================================
|
|
76
|
-
|
|
77
|
-
NumericProp._FieldEntry1 = {};
|
|
78
|
-
|
|
79
|
-
NumericProp._FieldEntry1.read = function (pbf, end) {
|
|
80
|
-
return pbf.readFields(NumericProp._FieldEntry1._readField, {key: '', value: 0}, end);
|
|
81
|
-
};
|
|
82
|
-
NumericProp._FieldEntry1._readField = function (tag, obj, pbf) {
|
|
83
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
84
|
-
else if (tag === 2) obj.value = pbf.readDouble();
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// StringProp ========================================
|
|
88
|
-
|
|
89
|
-
const StringProp = {};
|
|
90
|
-
|
|
91
|
-
StringProp.read = function (pbf, end) {
|
|
92
|
-
return pbf.readFields(StringProp._readField, {value: []}, end);
|
|
93
|
-
};
|
|
94
|
-
StringProp._readField = function (tag, obj, pbf) {
|
|
95
|
-
if (tag === 1) obj.value.push(pbf.readString());
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// Points ========================================
|
|
99
|
-
|
|
100
|
-
const Points = {};
|
|
101
|
-
|
|
102
|
-
Points.read = function (pbf, end) {
|
|
103
|
-
return pbf.readFields(
|
|
104
|
-
Points._readField,
|
|
105
|
-
{positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {}},
|
|
106
|
-
end
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
Points._readField = function (tag, obj, pbf) {
|
|
110
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
111
|
-
else if (tag === 2) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
112
|
-
else if (tag === 3) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
113
|
-
else if (tag === 4) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
114
|
-
else if (tag === 5) {
|
|
115
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
116
|
-
obj.numericProps[entry.key] = entry.value;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Lines ========================================
|
|
121
|
-
|
|
122
|
-
const Lines = {};
|
|
123
|
-
|
|
124
|
-
Lines.read = function (pbf, end) {
|
|
125
|
-
return pbf.readFields(
|
|
126
|
-
Lines._readField,
|
|
127
|
-
{
|
|
128
|
-
positions: null,
|
|
129
|
-
pathIndices: null,
|
|
130
|
-
globalFeatureIds: null,
|
|
131
|
-
featureIds: null,
|
|
132
|
-
properties: [],
|
|
133
|
-
numericProps: {}
|
|
134
|
-
},
|
|
135
|
-
end
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
Lines._readField = function (tag, obj, pbf) {
|
|
139
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
140
|
-
else if (tag === 2) obj.pathIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
141
|
-
else if (tag === 3) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
142
|
-
else if (tag === 4) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
143
|
-
else if (tag === 5) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
144
|
-
else if (tag === 6) {
|
|
145
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
146
|
-
obj.numericProps[entry.key] = entry.value;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Polygons ========================================
|
|
151
|
-
|
|
152
|
-
const Polygons = {};
|
|
153
|
-
|
|
154
|
-
Polygons.read = function (pbf, end) {
|
|
155
|
-
return pbf.readFields(
|
|
156
|
-
Polygons._readField,
|
|
157
|
-
{
|
|
158
|
-
positions: null,
|
|
159
|
-
polygonIndices: null,
|
|
160
|
-
globalFeatureIds: null,
|
|
161
|
-
featureIds: null,
|
|
162
|
-
primitivePolygonIndices: null,
|
|
163
|
-
triangles: null,
|
|
164
|
-
properties: [],
|
|
165
|
-
numericProps: {}
|
|
166
|
-
},
|
|
167
|
-
end
|
|
168
|
-
);
|
|
169
|
-
};
|
|
170
|
-
Polygons._readField = function (tag, obj, pbf) {
|
|
171
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
172
|
-
else if (tag === 2) obj.polygonIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
173
|
-
else if (tag === 3) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
174
|
-
else if (tag === 4) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
175
|
-
else if (tag === 5) obj.primitivePolygonIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
176
|
-
else if (tag === 6) obj.triangles = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
177
|
-
else if (tag === 7) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
178
|
-
else if (tag === 8) {
|
|
179
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
180
|
-
obj.numericProps[entry.key] = entry.value;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// Tile ========================================
|
|
185
|
-
|
|
186
|
-
export const Tile = {};
|
|
187
|
-
|
|
188
|
-
Tile.read = function (pbf, end) {
|
|
189
|
-
return pbf.readFields(Tile._readField, {points: null, lines: null, polygons: null}, end);
|
|
190
|
-
};
|
|
191
|
-
Tile._readField = function (tag, obj, pbf) {
|
|
192
|
-
if (tag === 1) obj.points = Points.read(pbf, pbf.readVarint() + pbf.pos);
|
|
193
|
-
else if (tag === 2) obj.lines = Lines.read(pbf, pbf.readVarint() + pbf.pos);
|
|
194
|
-
else if (tag === 3) obj.polygons = Polygons.read(pbf, pbf.readVarint() + pbf.pos);
|
|
195
|
-
};
|