@deck.gl/carto 8.9.14 → 8.9.15

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.
@@ -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
@@ -0,0 +1,4 @@
1
+ import { log } from '@deck.gl/core';
2
+ export function assert(condition, message) {
3
+ log.assert(condition, message);
4
+ }
package/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2020 Urban Computing Foundation
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -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"}