@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.
Files changed (117) hide show
  1. package/dist/dist.dev.js +14087 -14019
  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 +17 -12
  6. package/dist/es5/layers/carto-tile-layer.js.map +1 -1
  7. package/dist/es5/layers/h3-tile-layer.js +21 -11
  8. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  9. package/dist/es5/layers/h3-tileset-2d.js +4 -8
  10. package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
  11. package/dist/es5/layers/quadkey-tile-layer.js +24 -13
  12. package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
  13. package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -1
  14. package/dist/es5/layers/schema/carto-tile.js +261 -188
  15. package/dist/es5/layers/schema/carto-tile.js.map +1 -1
  16. package/dist/es5/layers/spatial-index-tile-layer.js +3 -0
  17. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  18. package/dist/esm/api/layer-map.js +8 -6
  19. package/dist/esm/api/layer-map.js.map +1 -1
  20. package/dist/esm/layers/carto-layer.js.map +1 -1
  21. package/dist/esm/layers/carto-tile-layer.js +20 -16
  22. package/dist/esm/layers/carto-tile-layer.js.map +1 -1
  23. package/dist/esm/layers/h3-tile-layer.js +13 -7
  24. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  25. package/dist/esm/layers/h3-tileset-2d.js +5 -9
  26. package/dist/esm/layers/h3-tileset-2d.js.map +1 -1
  27. package/dist/esm/layers/quadkey-tile-layer.js +16 -9
  28. package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
  29. package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -1
  30. package/dist/esm/layers/schema/carto-tile.js +174 -189
  31. package/dist/esm/layers/schema/carto-tile.js.map +1 -1
  32. package/dist/esm/layers/spatial-index-tile-layer.js +3 -0
  33. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  34. package/dist.min.js +4 -4
  35. package/package.json +11 -8
  36. package/src/api/layer-map.ts +16 -7
  37. package/src/layers/carto-layer.ts +11 -4
  38. package/src/layers/{carto-tile-layer.js → carto-tile-layer.ts} +63 -26
  39. package/src/layers/h3-tile-layer.ts +78 -0
  40. package/src/layers/{h3-tileset-2d.js → h3-tileset-2d.ts} +29 -26
  41. package/src/layers/quadkey-tile-layer.ts +68 -0
  42. package/src/layers/{quadkey-tileset-2d.js → quadkey-tileset-2d.ts} +10 -5
  43. package/src/layers/schema/carto-tile.ts +221 -0
  44. package/src/layers/{spatial-index-tile-layer.js → spatial-index-tile-layer.ts} +9 -6
  45. package/typed/api/index.d.ts +4 -0
  46. package/typed/api/index.d.ts.map +1 -0
  47. package/typed/api/index.js +3 -0
  48. package/typed/api/layer-map.d.ts +54 -0
  49. package/typed/api/layer-map.d.ts.map +1 -0
  50. package/typed/api/layer-map.js +264 -0
  51. package/typed/api/maps-api-common.d.ts +65 -0
  52. package/typed/api/maps-api-common.d.ts.map +1 -0
  53. package/typed/api/maps-api-common.js +50 -0
  54. package/typed/api/maps-client.d.ts +18 -0
  55. package/typed/api/maps-client.d.ts.map +1 -0
  56. package/typed/api/maps-client.js +125 -0
  57. package/typed/api/maps-v3-client.d.ts +45 -0
  58. package/typed/api/maps-v3-client.d.ts.map +1 -0
  59. package/typed/api/maps-v3-client.js +304 -0
  60. package/typed/api/parseMap.d.ts +11 -0
  61. package/typed/api/parseMap.d.ts.map +1 -0
  62. package/typed/api/parseMap.js +178 -0
  63. package/typed/basemap.d.ts +10 -0
  64. package/typed/basemap.d.ts.map +1 -0
  65. package/typed/basemap.js +9 -0
  66. package/typed/config.d.ts +26 -0
  67. package/typed/config.d.ts.map +1 -0
  68. package/typed/config.js +35 -0
  69. package/typed/index.d.ts +12 -0
  70. package/typed/index.d.ts.map +1 -0
  71. package/typed/index.js +10 -0
  72. package/typed/layers/carto-layer.d.ts +98 -0
  73. package/typed/layers/carto-layer.d.ts.map +1 -0
  74. package/typed/layers/carto-layer.js +173 -0
  75. package/typed/layers/carto-tile-layer.d.ts +63 -0
  76. package/typed/layers/carto-tile-layer.d.ts.map +1 -0
  77. package/typed/layers/carto-tile-layer.js +105 -0
  78. package/typed/layers/h3-tile-layer.d.ts +23 -0
  79. package/typed/layers/h3-tile-layer.d.ts.map +1 -0
  80. package/typed/layers/h3-tile-layer.js +47 -0
  81. package/typed/layers/h3-tileset-2d.d.ts +18 -0
  82. package/typed/layers/h3-tileset-2d.d.ts.map +1 -0
  83. package/typed/layers/h3-tileset-2d.js +85 -0
  84. package/typed/layers/quadkey-tile-layer.d.ts +23 -0
  85. package/typed/layers/quadkey-tile-layer.d.ts.map +1 -0
  86. package/typed/layers/quadkey-tile-layer.js +42 -0
  87. package/typed/layers/quadkey-tileset-2d.d.ts +15 -0
  88. package/typed/layers/quadkey-tileset-2d.d.ts.map +1 -0
  89. package/typed/layers/quadkey-tileset-2d.js +36 -0
  90. package/typed/layers/schema/carto-tile.d.ts +44 -0
  91. package/typed/layers/schema/carto-tile.d.ts.map +1 -0
  92. package/typed/layers/schema/carto-tile.js +161 -0
  93. package/typed/layers/spatial-index-tile-layer.d.ts +12 -0
  94. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -0
  95. package/typed/layers/spatial-index-tile-layer.js +40 -0
  96. package/typed/package.json +6 -0
  97. package/typed/style/color-bins-style.d.ts +9 -0
  98. package/typed/style/color-bins-style.d.ts.map +1 -0
  99. package/typed/style/color-bins-style.js +12 -0
  100. package/typed/style/color-categories-style.d.ts +10 -0
  101. package/typed/style/color-categories-style.d.ts.map +1 -0
  102. package/typed/style/color-categories-style.js +16 -0
  103. package/typed/style/color-continuous-style.d.ts +9 -0
  104. package/typed/style/color-continuous-style.d.ts.map +1 -0
  105. package/typed/style/color-continuous-style.js +12 -0
  106. package/typed/style/palette.d.ts +7 -0
  107. package/typed/style/palette.d.ts.map +1 -0
  108. package/typed/style/palette.js +62 -0
  109. package/typed/style/utils.d.ts +8 -0
  110. package/typed/style/utils.d.ts.map +1 -0
  111. package/typed/style/utils.js +15 -0
  112. package/typed/utils.d.ts +2 -0
  113. package/typed/utils.d.ts.map +1 -0
  114. package/typed/utils.js +4 -0
  115. package/src/layers/h3-tile-layer.js +0 -52
  116. package/src/layers/quadkey-tile-layer.js +0 -47
  117. package/src/layers/schema/carto-tile.js +0 -195
@@ -0,0 +1,221 @@
1
+ // KeyValueObject ========================================
2
+ interface KeyValueObject {
3
+ key: string;
4
+ value: string;
5
+ }
6
+
7
+ class KeyValueObjectReader {
8
+ static read(pbf, end?: number): KeyValueObject {
9
+ return pbf.readFields(KeyValueObjectReader._readField, {key: '', value: ''}, end);
10
+ }
11
+ static _readField(this: void, tag: number, obj: KeyValueObject, pbf) {
12
+ if (tag === 1) obj.key = pbf.readString();
13
+ else if (tag === 2) obj.value = pbf.readString();
14
+ }
15
+ }
16
+
17
+ // Properties ========================================
18
+
19
+ export interface Properties {
20
+ data: KeyValueObject[];
21
+ }
22
+
23
+ class PropertiesReader {
24
+ static read(pbf, end?: number) {
25
+ return pbf.readFields(PropertiesReader._readField, {data: []}, end);
26
+ }
27
+ static _readField(this: void, tag: number, obj: Properties, pbf) {
28
+ if (tag === 1) obj.data.push(KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos));
29
+ }
30
+ }
31
+
32
+ // Doubles ========================================
33
+
34
+ interface Doubles {
35
+ value: Float32Array;
36
+ size: number;
37
+ }
38
+
39
+ class DoublesReader {
40
+ static read(pbf, end?: number): Doubles {
41
+ // TODO perhaps we can do better and directly map from the source
42
+ // ArrayBuffer using ArrayBuffer.slice()
43
+ const {value, size} = pbf.readFields(DoublesReader._readField, {value: [], size: 0}, end);
44
+ return {value: new Float32Array(value), size};
45
+ }
46
+ static _readField(this: void, tag: number, obj, pbf) {
47
+ if (tag === 1) pbf.readPackedDouble(obj.value);
48
+ else if (tag === 2) obj.size = pbf.readVarint(true);
49
+ }
50
+ }
51
+
52
+ // Ints ========================================
53
+
54
+ interface Ints {
55
+ value: Uint32Array;
56
+ size: number;
57
+ }
58
+
59
+ class IntsReader {
60
+ static read(pbf, end?: number): Ints {
61
+ const {value, size} = pbf.readFields(IntsReader._readField, {value: [], size: 0}, end);
62
+ return {value: new Uint32Array(value), size};
63
+ }
64
+ static _readField(this: void, tag: number, obj, pbf) {
65
+ if (tag === 1) pbf.readPackedVarint(obj.value);
66
+ else if (tag === 2) obj.size = pbf.readVarint(true);
67
+ }
68
+ }
69
+
70
+ // NumericProp ========================================
71
+
72
+ interface NumericProp {
73
+ value: number[];
74
+ }
75
+
76
+ class NumericPropReader {
77
+ static read(pbf, end?: number): NumericProp {
78
+ return pbf.readFields(NumericPropReader._readField, {value: []}, end);
79
+ }
80
+ static _readField(this: void, tag: number, obj: NumericProp, pbf) {
81
+ if (tag === 1) pbf.readPackedDouble(obj.value);
82
+ }
83
+ }
84
+
85
+ // NumericPropKeyValue ========================================
86
+ interface NumbericPropKeyValue {
87
+ key: string;
88
+ value: NumericProp;
89
+ }
90
+
91
+ class NumericPropKeyValueReader {
92
+ static read(pbf, end?: number): NumbericPropKeyValue {
93
+ return pbf.readFields(NumericPropKeyValueReader._readField, {key: '', value: null}, end);
94
+ }
95
+ static _readField(this: void, tag: number, obj: NumbericPropKeyValue, pbf) {
96
+ if (tag === 1) obj.key = pbf.readString();
97
+ else if (tag === 2) obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
98
+ }
99
+ }
100
+
101
+ // Points ========================================
102
+
103
+ interface Points {
104
+ positions: Doubles;
105
+ globalFeatureIds: Ints;
106
+ featureIds: Ints;
107
+ properties: Properties[];
108
+ numericProps: Record<string, NumericProp>;
109
+ }
110
+
111
+ class PointsReader {
112
+ static read(pbf, end?: number): Points {
113
+ return pbf.readFields(
114
+ PointsReader._readField,
115
+ {positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {}},
116
+ end
117
+ );
118
+ }
119
+ static _readField(this: void, tag: number, obj: Points, pbf) {
120
+ if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
121
+ else if (tag === 2) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
122
+ else if (tag === 3) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
123
+ else if (tag === 4) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
124
+ else if (tag === 5) {
125
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
126
+ obj.numericProps[entry.key] = entry.value;
127
+ }
128
+ }
129
+ }
130
+
131
+ interface Lines extends Points {
132
+ pathIndices: Ints;
133
+ }
134
+ // Lines ========================================
135
+
136
+ class LinesReader {
137
+ static read(pbf, end?: number): Lines {
138
+ return pbf.readFields(
139
+ LinesReader._readField,
140
+ {
141
+ positions: null,
142
+ pathIndices: null,
143
+ globalFeatureIds: null,
144
+ featureIds: null,
145
+ properties: [],
146
+ numericProps: {}
147
+ },
148
+ end
149
+ );
150
+ }
151
+ static _readField(this: void, tag: number, obj: Lines, pbf) {
152
+ if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
153
+ else if (tag === 2) obj.pathIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
154
+ else if (tag === 3) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
155
+ else if (tag === 4) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
156
+ else if (tag === 5) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
157
+ else if (tag === 6) {
158
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
159
+ obj.numericProps[entry.key] = entry.value;
160
+ }
161
+ }
162
+ }
163
+ // Polygons ========================================
164
+
165
+ interface Polygons extends Points {
166
+ polygonIndices: Ints;
167
+ primitivePolygonIndices: Ints;
168
+ triangles: Ints;
169
+ }
170
+
171
+ class PolygonsReader {
172
+ static read(pbf, end?: number): Polygons {
173
+ return pbf.readFields(
174
+ PolygonsReader._readField,
175
+ {
176
+ positions: null,
177
+ polygonIndices: null,
178
+ globalFeatureIds: null,
179
+ featureIds: null,
180
+ primitivePolygonIndices: null,
181
+ triangles: null,
182
+ properties: [],
183
+ numericProps: {}
184
+ },
185
+ end
186
+ );
187
+ }
188
+ static _readField(this: void, tag: number, obj: Polygons, pbf) {
189
+ if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
190
+ else if (tag === 2) obj.polygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
191
+ else if (tag === 3) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
192
+ else if (tag === 4) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
193
+ else if (tag === 5)
194
+ obj.primitivePolygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
195
+ else if (tag === 6) obj.triangles = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
196
+ else if (tag === 7) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
197
+ else if (tag === 8) {
198
+ const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
199
+ obj.numericProps[entry.key] = entry.value;
200
+ }
201
+ }
202
+ }
203
+
204
+ // Tile ========================================
205
+
206
+ export interface Tile {
207
+ points: Points;
208
+ lines: Lines;
209
+ polygons: Polygons;
210
+ }
211
+
212
+ export class TileReader {
213
+ static read(pbf, end?: number): Tile {
214
+ return pbf.readFields(TileReader._readField, {points: null, lines: null, polygons: null}, end);
215
+ }
216
+ static _readField(this: void, tag: number, obj: Tile, pbf) {
217
+ if (tag === 1) obj.points = PointsReader.read(pbf, pbf.readVarint() + pbf.pos);
218
+ else if (tag === 2) obj.lines = LinesReader.read(pbf, pbf.readVarint() + pbf.pos);
219
+ else if (tag === 3) obj.polygons = PolygonsReader.read(pbf, pbf.readVarint() + pbf.pos);
220
+ }
221
+ }
@@ -1,11 +1,14 @@
1
- import {TileLayer} from '@deck.gl/geo-layers';
1
+ import {PickingInfo} from '@deck.gl/core';
2
+ import {TileLayer, _Tile2DHeader as Tile2DHeader} from '@deck.gl/geo-layers';
2
3
 
3
- function isFeatureIdDefined(value) {
4
+ function isFeatureIdDefined(value: unknown): boolean {
4
5
  return value !== undefined && value !== null && value !== '';
5
6
  }
6
7
 
7
- export default class SpatialIndexTileLayer extends TileLayer {
8
- _updateAutoHighlight(info) {
8
+ export default class SpatialIndexTileLayer<ExtraProps = {}> extends TileLayer<any, ExtraProps> {
9
+ static layerName = 'SpatialIndexTileLayer';
10
+
11
+ protected _updateAutoHighlight(info: PickingInfo): void {
9
12
  const {hoveredFeatureId} = this.state;
10
13
  const hoveredFeature = info.object;
11
14
  let newHoveredFeatureId;
@@ -27,14 +30,14 @@ export default class SpatialIndexTileLayer extends TileLayer {
27
30
  }
28
31
  }
29
32
 
30
- getSubLayerPropsByTile(tile) {
33
+ getSubLayerPropsByTile(tile: Tile2DHeader) {
31
34
  return {
32
35
  highlightedObjectIndex: this.getHighlightedObjectIndex(tile),
33
36
  highlightColor: this.state.highlightColor
34
37
  };
35
38
  }
36
39
 
37
- getHighlightedObjectIndex(tile) {
40
+ getHighlightedObjectIndex(tile: Tile2DHeader) {
38
41
  const {hoveredFeatureId} = this.state;
39
42
  const data = tile.content;
40
43
 
@@ -0,0 +1,4 @@
1
+ export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS } from './maps-api-common';
2
+ export { getDataV2, CONNECTIONS } from './maps-client';
3
+ export { fetchLayerData, fetchMap, getData, mapInstantiation } from './maps-v3-client';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS } from './maps-api-common';
2
+ export { getDataV2, CONNECTIONS } from './maps-client';
3
+ export { fetchLayerData, fetchMap, getData, mapInstantiation } from './maps-v3-client';
@@ -0,0 +1,54 @@
1
+ import { scaleLinear, scaleOrdinal, scaleLog, scalePoint, scaleQuantile, scaleQuantize, scaleSqrt, scaleThreshold } from 'd3-scale';
2
+ import { Layer, _ConstructorOf as ConstructorOf } from '@deck.gl/core/typed';
3
+ declare const SCALE_FUNCS: {
4
+ linear: typeof scaleLinear;
5
+ ordinal: typeof scaleOrdinal;
6
+ log: typeof scaleLog;
7
+ point: typeof scalePoint;
8
+ quantile: typeof scaleQuantile;
9
+ quantize: typeof scaleQuantize;
10
+ sqrt: typeof scaleSqrt;
11
+ custom: typeof scaleThreshold;
12
+ };
13
+ export declare type SCALE_TYPE = keyof typeof SCALE_FUNCS;
14
+ export declare const AGGREGATION: {
15
+ average: string;
16
+ maximum: string;
17
+ minimum: string;
18
+ sum: string;
19
+ };
20
+ export declare const OPACITY_MAP: {
21
+ getFillColor: string;
22
+ getLineColor: string;
23
+ getTextColor: string;
24
+ };
25
+ export declare function getLayer(type: string, config: any, dataset: any): {
26
+ Layer: ConstructorOf<Layer>;
27
+ propMap: any;
28
+ defaultProps: any;
29
+ };
30
+ declare function domainFromValues(values: any, scaleType: SCALE_TYPE): any;
31
+ export declare function opacityToAlpha(opacity: any): number;
32
+ export declare function getColorValueAccessor({ name }: {
33
+ name: any;
34
+ }, colorAggregation: any, data: any): any;
35
+ export declare function getColorAccessor({ name }: {
36
+ name: any;
37
+ }, scaleType: SCALE_TYPE, { colors, colorMap }: {
38
+ colors: any;
39
+ colorMap: any;
40
+ }, opacity: number | undefined, data: any): any;
41
+ export declare function getSizeAccessor({ name }: {
42
+ name: any;
43
+ }, scaleType: SCALE_TYPE, range: Iterable<Range>, data: any): any;
44
+ export declare function getTextAccessor({ name, type }: {
45
+ name: any;
46
+ type: any;
47
+ }, data: any): any;
48
+ export declare function getTextPixelOffsetAccessor({ alignment, anchor, size }: {
49
+ alignment: any;
50
+ anchor: any;
51
+ size: any;
52
+ }, radius: any): number[] | ((d: any) => number[]);
53
+ export { domainFromValues as _domainFromValues };
54
+ //# sourceMappingURL=layer-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer-map.d.ts","sourceRoot":"","sources":["../../src/api/layer-map.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,cAAc,EACf,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAC,KAAK,EAAE,cAAc,IAAI,aAAa,EAAC,MAAM,eAAe,CAAC;AASrE,QAAA,MAAM,WAAW;;;;;;;;;CAShB,CAAC;AACF,oBAAY,UAAU,GAAG,MAAM,OAAO,WAAW,CAAC;AAIlD,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;CAIvB,CAAC;AA2DF,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,MAAM,KAAA,EACN,OAAO,KAAA,GACN;IAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC;IAAC,YAAY,EAAE,GAAG,CAAA;CAAC,CAmDhE;AAkCD,iBAAS,gBAAgB,CAAC,MAAM,KAAA,EAAE,SAAS,EAAE,UAAU,OActD;AA8BD,wBAAgB,cAAc,CAAC,OAAO,KAAA,UAErC;AAED,wBAAgB,qBAAqB,CAAC,EAAC,IAAI,EAAC;;CAAA,EAAE,gBAAgB,KAAA,EAAE,IAAI,EAAE,GAAG,OAIxE;AAED,wBAAgB,gBAAgB,CAC9B,EAAC,IAAI,EAAC;;CAAA,EACN,SAAS,EAAE,UAAU,EACrB,EAAC,MAAM,EAAE,QAAQ,EAAC;;;CAAA,EAClB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,IAAI,EAAE,GAAG,OA+BV;AAED,wBAAgB,eAAe,CAAC,EAAC,IAAI,EAAC;;CAAA,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAS/F;AAUD,wBAAgB,eAAe,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC;;;CAAA,EAAE,IAAI,KAAA,OAMjD;AAED,wBAAgB,0BAA0B,CAAC,EAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAC;;;;CAAA,EAAE,MAAM,KAAA,qCAa3E;AAED,OAAO,EAAC,gBAAgB,IAAI,iBAAiB,EAAC,CAAC"}
@@ -0,0 +1,264 @@
1
+ import { deviation, extent, groupSort, median, variance } from 'd3-array';
2
+ import { rgb } from 'd3-color';
3
+ import { scaleLinear, scaleOrdinal, scaleLog, scalePoint, scaleQuantile, scaleQuantize, scaleSqrt, scaleThreshold } from 'd3-scale';
4
+ import { format as d3Format } from 'd3-format';
5
+ import moment from 'moment-timezone';
6
+ import { CPUGridLayer, HeatmapLayer, HexagonLayer } from '@deck.gl/aggregation-layers';
7
+ import { GeoJsonLayer } from '@deck.gl/layers';
8
+ import { H3HexagonLayer, MVTLayer } from '@deck.gl/geo-layers';
9
+ import CartoTileLayer from '../layers/carto-tile-layer';
10
+ import { TILE_FORMATS } from './maps-api-common';
11
+ import { assert } from '../utils';
12
+ const SCALE_FUNCS = {
13
+ linear: scaleLinear,
14
+ ordinal: scaleOrdinal,
15
+ log: scaleLog,
16
+ point: scalePoint,
17
+ quantile: scaleQuantile,
18
+ quantize: scaleQuantize,
19
+ sqrt: scaleSqrt,
20
+ custom: scaleThreshold
21
+ };
22
+ const UNKNOWN_COLOR = '#868d91';
23
+ export const AGGREGATION = {
24
+ average: 'MEAN',
25
+ maximum: 'MAX',
26
+ minimum: 'MIN',
27
+ sum: 'SUM'
28
+ };
29
+ export const OPACITY_MAP = {
30
+ getFillColor: 'opacity',
31
+ getLineColor: 'strokeOpacity',
32
+ getTextColor: 'opacity'
33
+ };
34
+ const AGGREGATION_FUNC = {
35
+ 'count unique': (values, accessor) => groupSort(values, v => v.length, accessor).length,
36
+ median,
37
+ // Unfortunately mode() is only available in d3-array@3+ which is ESM only
38
+ mode: (values, accessor) => groupSort(values, v => v.length, accessor).pop(),
39
+ stddev: deviation,
40
+ variance
41
+ };
42
+ const hexToRGBA = c => {
43
+ const { r, g, b, opacity } = rgb(c);
44
+ return [r, g, b, 255 * opacity];
45
+ };
46
+ // Kepler -> Deck.gl
47
+ const sharedPropMap = {
48
+ color: 'getFillColor',
49
+ isVisible: 'visible',
50
+ label: 'cartoLabel',
51
+ textLabel: {
52
+ alignment: 'getTextAlignmentBaseline',
53
+ anchor: 'getTextAnchor',
54
+ color: 'getTextColor',
55
+ size: 'getTextSize'
56
+ },
57
+ visConfig: {
58
+ enable3d: 'extruded',
59
+ elevationScale: 'elevationScale',
60
+ filled: 'filled',
61
+ strokeColor: 'getLineColor',
62
+ stroked: 'stroked',
63
+ thickness: 'getLineWidth',
64
+ radius: 'getPointRadius',
65
+ wireframe: 'wireframe'
66
+ }
67
+ };
68
+ const aggregationVisConfig = {
69
+ colorAggregation: x => ({ colorAggregation: AGGREGATION[x] || AGGREGATION.sum }),
70
+ colorRange: x => ({ colorRange: x.colors.map(hexToRGBA) }),
71
+ coverage: 'coverage',
72
+ elevationPercentile: ['elevationLowerPercentile', 'elevationUpperPercentile'],
73
+ percentile: ['lowerPercentile', 'upperPercentile']
74
+ };
75
+ const defaultProps = {
76
+ lineMiterLimit: 2,
77
+ lineWidthUnits: 'pixels',
78
+ pointRadiusUnits: 'pixels',
79
+ rounded: true,
80
+ wrapLongitude: false
81
+ };
82
+ function mergePropMaps(a = {}, b = {}) {
83
+ return { ...a, ...b, visConfig: { ...a.visConfig, ...b.visConfig } };
84
+ }
85
+ export function getLayer(type, config, dataset) {
86
+ if (type === 'mvt' || type === 'tileset') {
87
+ return getTileLayer(dataset);
88
+ }
89
+ const geoColumn = dataset?.geoColumn;
90
+ const getPosition = d => d[geoColumn].coordinates;
91
+ const hexagonId = config.columns?.hex_id;
92
+ const layerTypeDefs = {
93
+ point: {
94
+ Layer: GeoJsonLayer,
95
+ propMap: { visConfig: { outline: 'stroked' } }
96
+ },
97
+ geojson: {
98
+ Layer: GeoJsonLayer
99
+ },
100
+ grid: {
101
+ Layer: CPUGridLayer,
102
+ propMap: { visConfig: { ...aggregationVisConfig, worldUnitSize: x => ({ cellSize: 1000 * x }) } },
103
+ defaultProps: { getPosition }
104
+ },
105
+ heatmap: {
106
+ Layer: HeatmapLayer,
107
+ propMap: { visConfig: { ...aggregationVisConfig, radius: 'radiusPixels' } },
108
+ defaultProps: { getPosition }
109
+ },
110
+ hexagon: {
111
+ Layer: HexagonLayer,
112
+ propMap: { visConfig: { ...aggregationVisConfig, worldUnitSize: x => ({ radius: 1000 * x }) } },
113
+ defaultProps: { getPosition }
114
+ },
115
+ hexagonId: {
116
+ Layer: H3HexagonLayer,
117
+ propMap: { visConfig: { coverage: 'coverage' } },
118
+ defaultProps: { getHexagon: d => d[hexagonId], stroked: false }
119
+ }
120
+ };
121
+ const layer = layerTypeDefs[type];
122
+ assert(layer, `Unsupported layer type: ${type}`);
123
+ return {
124
+ ...layer,
125
+ propMap: mergePropMaps(sharedPropMap, layer.propMap),
126
+ defaultProps: { ...defaultProps, ...layer.defaultProps }
127
+ };
128
+ }
129
+ function getTileLayer(dataset) {
130
+ const { data: { tiles: [tileUrl] } } = dataset;
131
+ /* global URL */
132
+ const formatTiles = new URL(tileUrl).searchParams.get('formatTiles') || TILE_FORMATS.MVT;
133
+ return {
134
+ Layer: formatTiles === TILE_FORMATS.MVT ? MVTLayer : CartoTileLayer,
135
+ propMap: sharedPropMap,
136
+ defaultProps: {
137
+ ...defaultProps,
138
+ uniqueIdProperty: 'geoid',
139
+ formatTiles
140
+ }
141
+ };
142
+ }
143
+ function domainFromAttribute(attribute, scaleType) {
144
+ if (scaleType === 'ordinal' || scaleType === 'point') {
145
+ return attribute.categories.map(c => c.category).filter(c => c !== undefined && c !== null);
146
+ }
147
+ let { min } = attribute;
148
+ if (scaleType === 'log' && min === 0) {
149
+ min = 1e-5;
150
+ }
151
+ return [min, attribute.max];
152
+ }
153
+ function domainFromValues(values, scaleType) {
154
+ if (scaleType === 'ordinal') {
155
+ return groupSort(values, g => -g.length, d => d);
156
+ }
157
+ else if (scaleType === 'quantile') {
158
+ return values.sort((a, b) => a - b);
159
+ }
160
+ else if (scaleType === 'log') {
161
+ const [d0, d1] = extent(values);
162
+ return [d0 === 0 ? 1e-5 : d0, d1];
163
+ }
164
+ return extent(values);
165
+ }
166
+ function calculateDomain(data, name, scaleType) {
167
+ if (data.tilestats) {
168
+ // Tileset data type
169
+ const { attributes } = data.tilestats.layers[0];
170
+ const attribute = attributes.find(a => a.attribute === name);
171
+ return domainFromAttribute(attribute, scaleType);
172
+ }
173
+ else if (data.features) {
174
+ // GeoJSON data type
175
+ const values = data.features.map(({ properties }) => properties[name]);
176
+ return domainFromValues(values, scaleType);
177
+ }
178
+ else if (Array.isArray(data) && data[0][name] !== undefined) {
179
+ // JSON data type
180
+ const values = data.map(properties => properties[name]);
181
+ return domainFromValues(values, scaleType);
182
+ }
183
+ return [0, 1];
184
+ }
185
+ function normalizeAccessor(accessor, data) {
186
+ if (data.features || data.tilestats) {
187
+ return ({ properties }) => {
188
+ return accessor(properties);
189
+ };
190
+ }
191
+ return accessor;
192
+ }
193
+ export function opacityToAlpha(opacity) {
194
+ return opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
195
+ }
196
+ export function getColorValueAccessor({ name }, colorAggregation, data) {
197
+ const aggregator = AGGREGATION_FUNC[colorAggregation];
198
+ const accessor = values => aggregator(values, p => p[name]);
199
+ return normalizeAccessor(accessor, data);
200
+ }
201
+ export function getColorAccessor({ name }, scaleType, { colors, colorMap }, opacity, data) {
202
+ const scale = SCALE_FUNCS[scaleType]();
203
+ let domain = [];
204
+ let scaleColor = [];
205
+ if (Array.isArray(colorMap)) {
206
+ colorMap.forEach(([value, color]) => {
207
+ domain.push(value);
208
+ scaleColor.push(color);
209
+ });
210
+ }
211
+ else {
212
+ domain = calculateDomain(data, name, scaleType);
213
+ scaleColor = colors;
214
+ }
215
+ if (scaleType === 'ordinal') {
216
+ domain = domain.slice(0, scaleColor.length);
217
+ }
218
+ scale.domain(domain);
219
+ scale.range(scaleColor);
220
+ scale.unknown(UNKNOWN_COLOR);
221
+ const alpha = opacityToAlpha(opacity);
222
+ const accessor = properties => {
223
+ const propertyValue = properties[name];
224
+ const { r, g, b } = rgb(scale(propertyValue));
225
+ return [r, g, b, propertyValue === null ? 0 : alpha];
226
+ };
227
+ return normalizeAccessor(accessor, data);
228
+ }
229
+ export function getSizeAccessor({ name }, scaleType, range, data) {
230
+ const scale = SCALE_FUNCS[scaleType]();
231
+ scale.domain(calculateDomain(data, name, scaleType));
232
+ scale.range(range);
233
+ const accessor = properties => {
234
+ return scale(properties[name]);
235
+ };
236
+ return normalizeAccessor(accessor, data);
237
+ }
238
+ const FORMATS = {
239
+ date: s => moment.utc(s).format('MM/DD/YY HH:mm:ssa'),
240
+ integer: d3Format('i'),
241
+ float: d3Format('.5f'),
242
+ timestamp: s => moment.utc(s).format('X'),
243
+ default: String
244
+ };
245
+ export function getTextAccessor({ name, type }, data) {
246
+ const format = FORMATS[type] || FORMATS.default;
247
+ const accessor = properties => {
248
+ return format(properties[name]);
249
+ };
250
+ return normalizeAccessor(accessor, data);
251
+ }
252
+ export function getTextPixelOffsetAccessor({ alignment, anchor, size }, radius) {
253
+ const padding = 20;
254
+ const signX = anchor === 'middle' ? 0 : anchor === 'start' ? 1 : -1;
255
+ const signY = alignment === 'center' ? 0 : alignment === 'bottom' ? 1 : -1;
256
+ const sizeOffset = alignment === 'center' ? 0 : size;
257
+ const calculateOffset = r => [signX * (r + padding), signY * (r + padding + sizeOffset)];
258
+ return typeof radius === 'function'
259
+ ? d => {
260
+ return calculateOffset(radius(d));
261
+ }
262
+ : calculateOffset(radius);
263
+ }
264
+ export { domainFromValues as _domainFromValues };
@@ -0,0 +1,65 @@
1
+ export declare const DEFAULT_USER_COMPONENT_IN_URL = "{user}";
2
+ export declare const DEFAULT_REGION_COMPONENT_IN_URL = "{region}";
3
+ export declare type ValuesOf<T extends {}> = T[keyof T];
4
+ export declare const API_VERSIONS: {
5
+ readonly V1: "v1";
6
+ readonly V2: "v2";
7
+ readonly V3: "v3";
8
+ };
9
+ export declare type ApiVersion = ValuesOf<typeof API_VERSIONS>;
10
+ export declare const DEFAULT_MAPS_URL_FORMAT: {
11
+ readonly v1: "https://{user}.carto.com/api/v1/map";
12
+ readonly v2: "https://maps-api-v2.{region}.carto.com/user/{user}";
13
+ };
14
+ export declare const MAP_TYPES: {
15
+ readonly QUERY: "query";
16
+ readonly TABLE: "table";
17
+ readonly TILESET: "tileset";
18
+ };
19
+ export declare type MapType = ValuesOf<typeof MAP_TYPES>;
20
+ export declare const COLUMNS_SUPPORT: MapType[];
21
+ export declare const GEO_COLUMN_SUPPORT: MapType[];
22
+ export declare const FORMATS: {
23
+ readonly GEOJSON: "geojson";
24
+ readonly NDJSON: "ndjson";
25
+ readonly TILEJSON: "tilejson";
26
+ readonly JSON: "json";
27
+ };
28
+ export declare type Format = ValuesOf<typeof FORMATS>;
29
+ export declare const TILE_FORMATS: {
30
+ readonly MVT: "mvt";
31
+ readonly JSON: "json";
32
+ readonly GEOJSON: "geojson";
33
+ readonly BINARY: "binary";
34
+ };
35
+ export declare type TileFormat = ValuesOf<typeof TILE_FORMATS>;
36
+ export declare enum SchemaFieldType {
37
+ Number = "number",
38
+ Bigint = "bigint",
39
+ String = "string",
40
+ Geometry = "geometry",
41
+ Timestamp = "timestamp",
42
+ Object = "object",
43
+ Boolean = "boolean",
44
+ Variant = "variant",
45
+ Unknown = "unknown"
46
+ }
47
+ export interface SchemaField {
48
+ name: string;
49
+ type: SchemaFieldType;
50
+ }
51
+ export interface MapInstantiation extends MapInstantiationFormats {
52
+ nrows: number;
53
+ size?: number;
54
+ schema: SchemaField[];
55
+ }
56
+ declare type MapInstantiationFormats = Record<Format, {
57
+ url: string[];
58
+ error?: any;
59
+ }>;
60
+ /**
61
+ * Simple encode parameter
62
+ */
63
+ export declare function encodeParameter(name: string, value: string | boolean | number): string;
64
+ export {};
65
+ //# sourceMappingURL=maps-api-common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maps-api-common.d.ts","sourceRoot":"","sources":["../../src/api/maps-api-common.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,WAAW,CAAC;AACtD,eAAO,MAAM,+BAA+B,aAAa,CAAC;AAE1D,oBAAY,QAAQ,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAChD,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AACX,oBAAY,UAAU,GAAG,QAAQ,CAAC,OAAO,YAAY,CAAC,CAAC;AAEvD,eAAO,MAAM,uBAAuB;;;CAG1B,CAAC;AAEX,eAAO,MAAM,SAAS;;;;CAIZ,CAAC;AACX,oBAAY,OAAO,GAAG,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAC;AACjD,eAAO,MAAM,eAAe,EAAE,OAAO,EAAsB,CAAC;AAC5D,eAAO,MAAM,kBAAkB,EAAE,OAAO,EAAuC,CAAC;AAGhF,eAAO,MAAM,OAAO;;;;;CAKV,CAAC;AACX,oBAAY,MAAM,GAAG,QAAQ,CAAC,OAAO,OAAO,CAAC,CAAC;AAG9C,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AACX,oBAAY,UAAU,GAAG,QAAQ,CAAC,OAAO,YAAY,CAAC,CAAC;AAEvD,oBAAY,eAAe;IACzB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AACD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,uBAAuB;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,aAAK,uBAAuB,GAAG,MAAM,CACnC,MAAM,EACN;IACE,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CACF,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAEtF"}