@deck.gl/carto 8.8.0-beta.5 → 8.8.0
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 +1085 -1077
- package/dist/es5/index.js +20 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +5 -0
- package/typed/api/index.js +3 -0
- package/typed/api/layer-map.js +264 -0
- package/typed/api/maps-api-common.js +50 -0
- package/typed/api/maps-client.js +125 -0
- package/typed/api/maps-v3-client.js +304 -0
- package/typed/api/parseMap.js +178 -0
- package/typed/basemap.js +9 -0
- package/typed/config.js +35 -0
- package/typed/index.d.ts +1 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/index.js +10 -0
- package/typed/layers/carto-layer.js +173 -0
- package/typed/layers/carto-tile-layer.js +105 -0
- package/typed/layers/h3-tile-layer.js +47 -0
- package/typed/layers/h3-tileset-2d.js +85 -0
- package/typed/layers/quadkey-tile-layer.js +42 -0
- package/typed/layers/quadkey-tileset-2d.js +36 -0
- package/typed/layers/schema/carto-tile.js +161 -0
- package/typed/layers/spatial-index-tile-layer.js +40 -0
- package/typed/style/color-bins-style.js +12 -0
- package/typed/style/color-categories-style.js +16 -0
- package/typed/style/color-continuous-style.js +12 -0
- package/typed/style/palette.js +62 -0
- package/typed/style/utils.js +15 -0
- package/typed/utils.js +4 -0
|
@@ -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,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,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,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,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,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.js
ADDED