@deck.gl/carto 8.9.5 → 8.9.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 +61 -48
- package/dist.min.js +22 -22
- package/package.json +2 -2
- 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.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
- package/typed/layers/schema/carto-spa-tile.d.ts +0 -57
- package/typed/layers/schema/carto-spa-tile.d.ts.map +0 -1
|
@@ -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
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export namespace Doubles {
|
|
2
|
-
function read(pbf: any, end: any): any;
|
|
3
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
4
|
-
}
|
|
5
|
-
export namespace Ints {
|
|
6
|
-
function read(pbf: any, end: any): any;
|
|
7
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
8
|
-
}
|
|
9
|
-
export namespace Id {
|
|
10
|
-
function read(pbf: any, end: any): any;
|
|
11
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
12
|
-
}
|
|
13
|
-
export namespace NumericProp {
|
|
14
|
-
function read(pbf: any, end: any): any;
|
|
15
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
16
|
-
}
|
|
17
|
-
export namespace StringProp {
|
|
18
|
-
function read(pbf: any, end: any): any;
|
|
19
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
20
|
-
}
|
|
21
|
-
export namespace Points {
|
|
22
|
-
function read(pbf: any, end: any): any;
|
|
23
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
24
|
-
namespace _FieldEntry5 {
|
|
25
|
-
function read(pbf: any, end: any): any;
|
|
26
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export namespace Lines {
|
|
30
|
-
function read(pbf: any, end: any): any;
|
|
31
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
32
|
-
namespace _FieldEntry6 {
|
|
33
|
-
function read(pbf: any, end: any): any;
|
|
34
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export namespace Polygons {
|
|
38
|
-
function read(pbf: any, end: any): any;
|
|
39
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
40
|
-
namespace _FieldEntry8 {
|
|
41
|
-
function read(pbf: any, end: any): any;
|
|
42
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export namespace Tile {
|
|
46
|
-
function read(pbf: any, end: any): any;
|
|
47
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
48
|
-
}
|
|
49
|
-
export namespace Properties {
|
|
50
|
-
function read(pbf: any, end: any): any;
|
|
51
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
52
|
-
}
|
|
53
|
-
export namespace KeyValueObject {
|
|
54
|
-
function read(pbf: any, end: any): any;
|
|
55
|
-
function _readField(tag: any, obj: any, pbf: any): void;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=carto-spa-tile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"carto-spa-tile.d.ts","sourceRoot":"","sources":["../../../src/layers/schema/carto-spa-tile.js"],"names":[],"mappings":";IAMA,uCAEC;IACD,wDAGC;;;IAMD,uCAEC;IACD,wDAGC;;;IAMD,uCAEC;IACD,wDAEC;;;IAMD,uCAEC;IACD,wDAEC;;;IAMD,uCAEC;IACD,wDAEC;;;IAMD,uCAaC;IACD,wDASC;;QAMD,uCAEC;QACD,wDAGC;;;;IAMD,uCAcC;IACD,wDAUC;;QAMD,uCAEC;QACD,wDAGC;;;;IAMD,uCAgBC;IACD,wDAYC;;QAMD,uCAEC;QACD,wDAGC;;;;IAMD,uCAEC;IACD,wDAIC;;;IAMD,uCAEC;IACD,wDAEC;;;IAMD,uCAEC;IACD,wDAGC"}
|