@deck.gl/carto 8.8.0-alpha.5 → 8.8.0-beta.2

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.
Files changed (109) hide show
  1. package/dist/dist.dev.js +13886 -13809
  2. package/dist/es5/api/layer-map.js +7 -5
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/layers/carto-layer.js.map +1 -1
  5. package/dist/es5/layers/carto-tile-layer.js.map +1 -1
  6. package/dist/es5/layers/h3-tile-layer.js +20 -10
  7. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  8. package/dist/es5/layers/h3-tileset-2d.js +4 -8
  9. package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
  10. package/dist/es5/layers/quadkey-tile-layer.js +23 -12
  11. package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
  12. package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -1
  13. package/dist/es5/layers/spatial-index-tile-layer.js +3 -0
  14. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  15. package/dist/esm/api/layer-map.js +8 -6
  16. package/dist/esm/api/layer-map.js.map +1 -1
  17. package/dist/esm/layers/carto-layer.js.map +1 -1
  18. package/dist/esm/layers/carto-tile-layer.js.map +1 -1
  19. package/dist/esm/layers/h3-tile-layer.js +12 -6
  20. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  21. package/dist/esm/layers/h3-tileset-2d.js +5 -9
  22. package/dist/esm/layers/h3-tileset-2d.js.map +1 -1
  23. package/dist/esm/layers/quadkey-tile-layer.js +15 -8
  24. package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
  25. package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -1
  26. package/dist/esm/layers/spatial-index-tile-layer.js +3 -0
  27. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  28. package/dist.min.js +4 -4
  29. package/package.json +10 -9
  30. package/src/api/layer-map.ts +16 -7
  31. package/src/layers/carto-layer.ts +19 -7
  32. package/src/layers/carto-tile-layer.ts +3 -3
  33. package/src/layers/h3-tile-layer.ts +79 -0
  34. package/src/layers/{h3-tileset-2d.js → h3-tileset-2d.ts} +29 -26
  35. package/src/layers/quadkey-tile-layer.ts +69 -0
  36. package/src/layers/{quadkey-tileset-2d.js → quadkey-tileset-2d.ts} +10 -5
  37. package/src/layers/{spatial-index-tile-layer.js → spatial-index-tile-layer.ts} +9 -6
  38. package/typed/api/index.d.ts +4 -0
  39. package/typed/api/index.d.ts.map +1 -0
  40. package/typed/api/index.js +3 -0
  41. package/typed/api/layer-map.d.ts +54 -0
  42. package/typed/api/layer-map.d.ts.map +1 -0
  43. package/typed/api/layer-map.js +264 -0
  44. package/typed/api/maps-api-common.d.ts +65 -0
  45. package/typed/api/maps-api-common.d.ts.map +1 -0
  46. package/typed/api/maps-api-common.js +50 -0
  47. package/typed/api/maps-client.d.ts +18 -0
  48. package/typed/api/maps-client.d.ts.map +1 -0
  49. package/typed/api/maps-client.js +125 -0
  50. package/typed/api/maps-v3-client.d.ts +45 -0
  51. package/typed/api/maps-v3-client.d.ts.map +1 -0
  52. package/typed/api/maps-v3-client.js +304 -0
  53. package/typed/api/parseMap.d.ts +11 -0
  54. package/typed/api/parseMap.d.ts.map +1 -0
  55. package/typed/api/parseMap.js +178 -0
  56. package/typed/basemap.d.ts +10 -0
  57. package/typed/basemap.d.ts.map +1 -0
  58. package/typed/basemap.js +9 -0
  59. package/typed/config.d.ts +26 -0
  60. package/typed/config.d.ts.map +1 -0
  61. package/typed/config.js +35 -0
  62. package/typed/index.d.ts +12 -0
  63. package/typed/index.d.ts.map +1 -0
  64. package/typed/index.js +10 -0
  65. package/typed/layers/carto-layer.d.ts +96 -0
  66. package/typed/layers/carto-layer.d.ts.map +1 -0
  67. package/typed/layers/carto-layer.js +173 -0
  68. package/typed/layers/carto-tile-layer.d.ts +30 -0
  69. package/typed/layers/carto-tile-layer.d.ts.map +1 -0
  70. package/typed/layers/carto-tile-layer.js +105 -0
  71. package/typed/layers/h3-tile-layer.d.ts +21 -0
  72. package/typed/layers/h3-tile-layer.d.ts.map +1 -0
  73. package/typed/layers/h3-tile-layer.js +47 -0
  74. package/typed/layers/h3-tileset-2d.d.ts +18 -0
  75. package/typed/layers/h3-tileset-2d.d.ts.map +1 -0
  76. package/typed/layers/h3-tileset-2d.js +85 -0
  77. package/typed/layers/quadkey-tile-layer.d.ts +21 -0
  78. package/typed/layers/quadkey-tile-layer.d.ts.map +1 -0
  79. package/typed/layers/quadkey-tile-layer.js +42 -0
  80. package/typed/layers/quadkey-tileset-2d.d.ts +15 -0
  81. package/typed/layers/quadkey-tileset-2d.d.ts.map +1 -0
  82. package/typed/layers/quadkey-tileset-2d.js +36 -0
  83. package/typed/layers/schema/carto-tile.d.ts +44 -0
  84. package/typed/layers/schema/carto-tile.d.ts.map +1 -0
  85. package/typed/layers/schema/carto-tile.js +161 -0
  86. package/typed/layers/spatial-index-tile-layer.d.ts +12 -0
  87. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -0
  88. package/typed/layers/spatial-index-tile-layer.js +40 -0
  89. package/typed/package.json +6 -0
  90. package/typed/style/color-bins-style.d.ts +9 -0
  91. package/typed/style/color-bins-style.d.ts.map +1 -0
  92. package/typed/style/color-bins-style.js +12 -0
  93. package/typed/style/color-categories-style.d.ts +10 -0
  94. package/typed/style/color-categories-style.d.ts.map +1 -0
  95. package/typed/style/color-categories-style.js +16 -0
  96. package/typed/style/color-continuous-style.d.ts +9 -0
  97. package/typed/style/color-continuous-style.d.ts.map +1 -0
  98. package/typed/style/color-continuous-style.js +12 -0
  99. package/typed/style/palette.d.ts +7 -0
  100. package/typed/style/palette.d.ts.map +1 -0
  101. package/typed/style/palette.js +62 -0
  102. package/typed/style/utils.d.ts +8 -0
  103. package/typed/style/utils.d.ts.map +1 -0
  104. package/typed/style/utils.js +15 -0
  105. package/typed/utils.d.ts +2 -0
  106. package/typed/utils.d.ts.map +1 -0
  107. package/typed/utils.js +4 -0
  108. package/src/layers/h3-tile-layer.js +0 -52
  109. package/src/layers/quadkey-tile-layer.js +0 -47
@@ -0,0 +1,15 @@
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(): {};
9
+ getTileZoom({ i }: QuadkeyTileIndex): number;
10
+ getParentIndex(index: QuadkeyTileIndex): {
11
+ i: string;
12
+ };
13
+ }
14
+ export {};
15
+ //# sourceMappingURL=quadkey-tileset-2d.d.ts.map
@@ -0,0 +1 @@
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;AAapC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IAErD,cAAc,CAAC,IAAI,KAAA,GAAG,gBAAgB,EAAE;IAKxC,SAAS,CAAC,EAAC,CAAC,EAAC,EAAE,gBAAgB;IAI/B,eAAe;IAKf,WAAW,CAAC,EAAC,CAAC,EAAC,EAAE,gBAAgB;IAKjC,cAAc,CAAC,KAAK,EAAE,gBAAgB;;;CAIvC"}
@@ -0,0 +1,36 @@
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
+ }
@@ -0,0 +1,44 @@
1
+ interface KeyValueObject {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ export interface Properties {
6
+ data: KeyValueObject[];
7
+ }
8
+ interface Doubles {
9
+ value: Float32Array;
10
+ size: number;
11
+ }
12
+ interface Ints {
13
+ value: Uint32Array;
14
+ size: number;
15
+ }
16
+ interface NumericProp {
17
+ value: number[];
18
+ }
19
+ interface Points {
20
+ positions: Doubles;
21
+ globalFeatureIds: Ints;
22
+ featureIds: Ints;
23
+ properties: Properties[];
24
+ numericProps: Record<string, NumericProp>;
25
+ }
26
+ interface Lines extends Points {
27
+ pathIndices: Ints;
28
+ }
29
+ interface Polygons extends Points {
30
+ polygonIndices: Ints;
31
+ primitivePolygonIndices: Ints;
32
+ triangles: Ints;
33
+ }
34
+ export interface Tile {
35
+ points: Points;
36
+ lines: Lines;
37
+ polygons: Polygons;
38
+ }
39
+ export declare class TileReader {
40
+ static read(pbf: any, end?: number): Tile;
41
+ static _readField(this: void, tag: number, obj: Tile, pbf: any): void;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=carto-tile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carto-tile.d.ts","sourceRoot":"","sources":["../../../src/layers/schema/carto-tile.ts"],"names":[],"mappings":"AACA,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAcD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB;AAaD,UAAU,OAAO;IACf,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAiBD,UAAU,IAAI;IACZ,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAeD,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AA6BD,UAAU,MAAM;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,IAAI,CAAC;IACvB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAC3C;AAsBD,UAAU,KAAM,SAAQ,MAAM;IAC5B,WAAW,EAAE,IAAI,CAAC;CACnB;AAgCD,UAAU,QAAS,SAAQ,MAAM;IAC/B,cAAc,EAAE,IAAI,CAAC;IACrB,uBAAuB,EAAE,IAAI,CAAC;IAC9B,SAAS,EAAE,IAAI,CAAC;CACjB;AAqCD,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,qBAAa,UAAU;IACrB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAA,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAGpC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAA;CAK1D"}
@@ -0,0 +1,161 @@
1
+ class KeyValueObjectReader {
2
+ static read(pbf, end) {
3
+ return pbf.readFields(KeyValueObjectReader._readField, { key: '', value: '' }, end);
4
+ }
5
+ static _readField(tag, obj, pbf) {
6
+ if (tag === 1)
7
+ obj.key = pbf.readString();
8
+ else if (tag === 2)
9
+ obj.value = pbf.readString();
10
+ }
11
+ }
12
+ class PropertiesReader {
13
+ static read(pbf, end) {
14
+ return pbf.readFields(PropertiesReader._readField, { data: [] }, end);
15
+ }
16
+ static _readField(tag, obj, pbf) {
17
+ if (tag === 1)
18
+ obj.data.push(KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos));
19
+ }
20
+ }
21
+ class DoublesReader {
22
+ static read(pbf, end) {
23
+ // TODO perhaps we can do better and directly map from the source
24
+ // ArrayBuffer using ArrayBuffer.slice()
25
+ const { value, size } = pbf.readFields(DoublesReader._readField, { value: [], size: 0 }, end);
26
+ return { value: new Float32Array(value), size };
27
+ }
28
+ static _readField(tag, obj, pbf) {
29
+ if (tag === 1)
30
+ pbf.readPackedDouble(obj.value);
31
+ else if (tag === 2)
32
+ obj.size = pbf.readVarint(true);
33
+ }
34
+ }
35
+ class IntsReader {
36
+ static read(pbf, end) {
37
+ const { value, size } = pbf.readFields(IntsReader._readField, { value: [], size: 0 }, end);
38
+ return { value: new Uint32Array(value), size };
39
+ }
40
+ static _readField(tag, obj, pbf) {
41
+ if (tag === 1)
42
+ pbf.readPackedVarint(obj.value);
43
+ else if (tag === 2)
44
+ obj.size = pbf.readVarint(true);
45
+ }
46
+ }
47
+ class NumericPropReader {
48
+ static read(pbf, end) {
49
+ return pbf.readFields(NumericPropReader._readField, { value: [] }, end);
50
+ }
51
+ static _readField(tag, obj, pbf) {
52
+ if (tag === 1)
53
+ pbf.readPackedDouble(obj.value);
54
+ }
55
+ }
56
+ class NumericPropKeyValueReader {
57
+ static read(pbf, end) {
58
+ return pbf.readFields(NumericPropKeyValueReader._readField, { key: '', value: null }, end);
59
+ }
60
+ static _readField(tag, obj, pbf) {
61
+ if (tag === 1)
62
+ obj.key = pbf.readString();
63
+ else if (tag === 2)
64
+ obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
65
+ }
66
+ }
67
+ class PointsReader {
68
+ static read(pbf, end) {
69
+ return pbf.readFields(PointsReader._readField, { positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {} }, end);
70
+ }
71
+ static _readField(tag, obj, pbf) {
72
+ if (tag === 1)
73
+ obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
74
+ else if (tag === 2)
75
+ obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
76
+ else if (tag === 3)
77
+ obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
78
+ else if (tag === 4)
79
+ obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
80
+ else if (tag === 5) {
81
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
82
+ obj.numericProps[entry.key] = entry.value;
83
+ }
84
+ }
85
+ }
86
+ // Lines ========================================
87
+ class LinesReader {
88
+ static read(pbf, end) {
89
+ return pbf.readFields(LinesReader._readField, {
90
+ positions: null,
91
+ pathIndices: null,
92
+ globalFeatureIds: null,
93
+ featureIds: null,
94
+ properties: [],
95
+ numericProps: {}
96
+ }, end);
97
+ }
98
+ static _readField(tag, obj, pbf) {
99
+ if (tag === 1)
100
+ obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
101
+ else if (tag === 2)
102
+ obj.pathIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
103
+ else if (tag === 3)
104
+ obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
105
+ else if (tag === 4)
106
+ obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
107
+ else if (tag === 5)
108
+ obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
109
+ else if (tag === 6) {
110
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
111
+ obj.numericProps[entry.key] = entry.value;
112
+ }
113
+ }
114
+ }
115
+ class PolygonsReader {
116
+ static read(pbf, end) {
117
+ return pbf.readFields(PolygonsReader._readField, {
118
+ positions: null,
119
+ polygonIndices: null,
120
+ globalFeatureIds: null,
121
+ featureIds: null,
122
+ primitivePolygonIndices: null,
123
+ triangles: null,
124
+ properties: [],
125
+ numericProps: {}
126
+ }, end);
127
+ }
128
+ static _readField(tag, obj, pbf) {
129
+ if (tag === 1)
130
+ obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
131
+ else if (tag === 2)
132
+ obj.polygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
133
+ else if (tag === 3)
134
+ obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
135
+ else if (tag === 4)
136
+ obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
137
+ else if (tag === 5)
138
+ obj.primitivePolygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
139
+ else if (tag === 6)
140
+ obj.triangles = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
141
+ else if (tag === 7)
142
+ obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
143
+ else if (tag === 8) {
144
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
145
+ obj.numericProps[entry.key] = entry.value;
146
+ }
147
+ }
148
+ }
149
+ export class TileReader {
150
+ static read(pbf, end) {
151
+ return pbf.readFields(TileReader._readField, { points: null, lines: null, polygons: null }, end);
152
+ }
153
+ static _readField(tag, obj, pbf) {
154
+ if (tag === 1)
155
+ obj.points = PointsReader.read(pbf, pbf.readVarint() + pbf.pos);
156
+ else if (tag === 2)
157
+ obj.lines = LinesReader.read(pbf, pbf.readVarint() + pbf.pos);
158
+ else if (tag === 3)
159
+ obj.polygons = PolygonsReader.read(pbf, pbf.readVarint() + pbf.pos);
160
+ }
161
+ }
@@ -0,0 +1,12 @@
1
+ import { PickingInfo } from '@deck.gl/core/typed';
2
+ import { TileLayer, _Tile2DHeader as Tile2DHeader } from '@deck.gl/geo-layers/typed';
3
+ export default class SpatialIndexTileLayer<ExtraProps = {}> extends TileLayer<any, ExtraProps> {
4
+ static layerName: string;
5
+ protected _updateAutoHighlight(info: PickingInfo): void;
6
+ getSubLayerPropsByTile(tile: Tile2DHeader): {
7
+ highlightedObjectIndex: number;
8
+ highlightColor: any;
9
+ };
10
+ getHighlightedObjectIndex(tile: Tile2DHeader): number;
11
+ }
12
+ //# sourceMappingURL=spatial-index-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spatial-index-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/spatial-index-tile-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,SAAS,EAAE,aAAa,IAAI,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAM7E,MAAM,CAAC,OAAO,OAAO,qBAAqB,CAAC,UAAU,GAAG,EAAE,CAAE,SAAQ,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC;IAC5F,MAAM,CAAC,SAAS,SAA2B;IAE3C,SAAS,CAAC,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAsBvD,sBAAsB,CAAC,IAAI,EAAE,YAAY;;;;IAOzC,yBAAyB,CAAC,IAAI,EAAE,YAAY;CAW7C"}
@@ -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,6 @@
1
+ {
2
+ "internal": true,
3
+ "main": "../dist/es5/index.js",
4
+ "module": "../dist/esm/index.js",
5
+ "types": "index.d.ts"
6
+ }
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function assert(condition: unknown, message?: string): asserts condition;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -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
@@ -0,0 +1,4 @@
1
+ import { log } from '@deck.gl/core';
2
+ export function assert(condition, message) {
3
+ log.assert(condition, message);
4
+ }
@@ -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-${this.props.id}`,
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-${this.props.id}`,
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;