@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,178 @@
1
+ import GL from '@luma.gl/constants';
2
+ import { AGGREGATION, getLayer, getColorAccessor, getColorValueAccessor, getSizeAccessor, getTextAccessor, getTextPixelOffsetAccessor, OPACITY_MAP, opacityToAlpha } from './layer-map';
3
+ import { _flatten as flatten, log } from '@deck.gl/core';
4
+ import { assert } from '../utils';
5
+ export function parseMap(json) {
6
+ const { keplerMapConfig, datasets } = json;
7
+ assert(keplerMapConfig.version === 'v1', 'Only support Kepler v1');
8
+ const { mapState, mapStyle } = keplerMapConfig.config;
9
+ const { layers, layerBlending, interactionConfig } = keplerMapConfig.config.visState;
10
+ return {
11
+ id: json.id,
12
+ title: json.title,
13
+ description: json.description,
14
+ createdAt: json.createdAt,
15
+ updatedAt: json.updatedAt,
16
+ initialViewState: mapState,
17
+ mapStyle,
18
+ layers: extractTextLayers(layers.reverse()).map(({ id, type, config, visualChannels }) => {
19
+ try {
20
+ const { dataId } = config;
21
+ const dataset = datasets.find(d => d.id === dataId);
22
+ assert(dataset, `No dataset matching dataId: ${dataId}`);
23
+ const { data } = dataset;
24
+ assert(data, `No data loaded for dataId: ${dataId}`);
25
+ const { Layer, propMap, defaultProps } = getLayer(type, config, dataset);
26
+ return new Layer({
27
+ id,
28
+ data,
29
+ ...defaultProps,
30
+ ...createBlendingProps(layerBlending),
31
+ ...(!config.textLabel && createInteractionProps(interactionConfig)),
32
+ ...createStyleProps(config, propMap),
33
+ ...createChannelProps(visualChannels, type, config, data) // Must come after style
34
+ });
35
+ }
36
+ catch (e) {
37
+ log.error(e.message)();
38
+ return undefined;
39
+ }
40
+ })
41
+ };
42
+ }
43
+ function extractTextLayers(layers) {
44
+ return flatten(layers.map(({ id, config, ...rest }) => {
45
+ const { textLabel, ...configRest } = config;
46
+ return [
47
+ // Original layer without textLabel
48
+ { id, config: configRest, ...rest },
49
+ // One layer per valid text label, with full opacity
50
+ ...textLabel
51
+ .filter(t => t.field)
52
+ .map(t => {
53
+ return {
54
+ id: `${id}-label-${t.field.name}`,
55
+ config: {
56
+ textLabel: t,
57
+ ...configRest,
58
+ label: `${config.label}-label-${t.field.name}`,
59
+ visConfig: { ...configRest.visConfig, opacity: 1 }
60
+ },
61
+ ...rest
62
+ };
63
+ })
64
+ ];
65
+ }));
66
+ }
67
+ function createBlendingProps(layerBlending) {
68
+ if (layerBlending === 'additive') {
69
+ return {
70
+ parameters: {
71
+ blendFunc: [GL.SRC_ALPHA, GL.DST_ALPHA],
72
+ blendEquation: GL.FUNC_ADD
73
+ }
74
+ };
75
+ }
76
+ else if (layerBlending === 'subtractive') {
77
+ return {
78
+ parameters: {
79
+ blendFunc: [GL.ONE, GL.ONE_MINUS_DST_COLOR, GL.SRC_ALPHA, GL.DST_ALPHA],
80
+ blendEquation: [GL.FUNC_SUBTRACT, GL.FUNC_ADD]
81
+ }
82
+ };
83
+ }
84
+ return {};
85
+ }
86
+ function createInteractionProps(interactionConfig) {
87
+ const pickable = interactionConfig && interactionConfig.tooltip.enabled;
88
+ return {
89
+ autoHighlight: pickable,
90
+ pickable
91
+ };
92
+ }
93
+ function mapProps(source, target, mapping) {
94
+ for (const sourceKey in mapping) {
95
+ const sourceValue = source[sourceKey];
96
+ const targetKey = mapping[sourceKey];
97
+ if (sourceValue === undefined) {
98
+ // eslint-disable-next-line no-continue
99
+ continue;
100
+ }
101
+ if (typeof targetKey === 'string') {
102
+ target[targetKey] = sourceValue;
103
+ }
104
+ else if (typeof targetKey === 'function') {
105
+ const [key, value] = Object.entries(targetKey(sourceValue))[0];
106
+ target[key] = value;
107
+ }
108
+ else if (typeof targetKey === 'object') {
109
+ // Nested definition, recurse down one level (also handles arrays)
110
+ mapProps(sourceValue, target, targetKey);
111
+ }
112
+ }
113
+ }
114
+ function createStyleProps(config, mapping) {
115
+ const result = {};
116
+ mapProps(config, result, mapping);
117
+ // Kepler format sometimes omits strokeColor. TODO: remove once we can rely on
118
+ // `strokeColor` always being set when `stroke: true`.
119
+ if (result.stroked && !result.getLineColor) {
120
+ result.getLineColor = result.getFillColor;
121
+ }
122
+ for (const colorAccessor in OPACITY_MAP) {
123
+ if (Array.isArray(result[colorAccessor])) {
124
+ const color = [...result[colorAccessor]];
125
+ const opacityKey = OPACITY_MAP[colorAccessor];
126
+ const opacity = config.visConfig[opacityKey];
127
+ color[3] = opacityToAlpha(opacity);
128
+ result[colorAccessor] = color;
129
+ }
130
+ }
131
+ result.highlightColor = config.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
132
+ return result;
133
+ }
134
+ /* eslint-disable complexity, max-statements */
135
+ function createChannelProps(visualChannels, type, config, data) {
136
+ const { colorField, colorScale, sizeField, sizeScale, strokeColorField, strokeColorScale } = visualChannels;
137
+ let { heightField, heightScale } = visualChannels;
138
+ if (type === 'hexagonId') {
139
+ heightField = sizeField;
140
+ heightScale = sizeScale;
141
+ }
142
+ const { textLabel, visConfig } = config;
143
+ const result = {};
144
+ const textLabelField = textLabel && textLabel.field;
145
+ if (type === 'grid' || type === 'hexagon') {
146
+ result.colorScaleType = colorScale;
147
+ if (colorField) {
148
+ const { colorAggregation } = config.visConfig;
149
+ if (!AGGREGATION[colorAggregation]) {
150
+ result.getColorValue = getColorValueAccessor(colorField, colorAggregation, data);
151
+ }
152
+ else {
153
+ result.getColorWeight = d => d[colorField.name];
154
+ }
155
+ }
156
+ }
157
+ else if (colorField) {
158
+ result.getFillColor = getColorAccessor(colorField, colorScale, visConfig.colorRange, visConfig.opacity, data);
159
+ }
160
+ if (strokeColorField) {
161
+ const fallbackOpacity = type === 'point' ? visConfig.opacity : 1;
162
+ const opacity = visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : fallbackOpacity;
163
+ result.getLineColor = getColorAccessor(strokeColorField, strokeColorScale, visConfig.strokeColorRange, opacity, data);
164
+ }
165
+ if (heightField) {
166
+ result.getElevation = getSizeAccessor(heightField, heightScale, visConfig.heightRange || visConfig.sizeRange, data);
167
+ }
168
+ if (sizeField) {
169
+ result.getPointRadius = getSizeAccessor(sizeField, sizeScale, visConfig.radiusRange || visConfig.sizeRange, data);
170
+ }
171
+ if (textLabelField) {
172
+ result.getText = getTextAccessor(textLabelField, data);
173
+ result.pointType = 'text';
174
+ const radius = result.getPointRadius || visConfig.radius;
175
+ result.getTextPixelOffset = getTextPixelOffsetAccessor(textLabel, radius);
176
+ }
177
+ return result;
178
+ }
@@ -0,0 +1,10 @@
1
+ declare const _default: {
2
+ readonly VOYAGER: string;
3
+ readonly POSITRON: string;
4
+ readonly DARK_MATTER: string;
5
+ readonly VOYAGER_NOLABELS: string;
6
+ readonly POSITRON_NOLABELS: string;
7
+ readonly DARK_MATTER_NOLABELS: string;
8
+ };
9
+ export default _default;
10
+ //# sourceMappingURL=basemap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basemap.d.ts","sourceRoot":"","sources":["../src/basemap.ts"],"names":[],"mappings":";;;;;;;;AAEA,wBAOW"}
@@ -0,0 +1,9 @@
1
+ const baseUrl = 'https://basemaps.cartocdn.com/gl/{basemap}-gl-style/style.json';
2
+ export default {
3
+ VOYAGER: baseUrl.replace('{basemap}', 'voyager'),
4
+ POSITRON: baseUrl.replace('{basemap}', 'positron'),
5
+ DARK_MATTER: baseUrl.replace('{basemap}', 'dark-matter'),
6
+ VOYAGER_NOLABELS: baseUrl.replace('{basemap}', 'voyager-nolabels'),
7
+ POSITRON_NOLABELS: baseUrl.replace('{basemap}', 'positron-nolabels'),
8
+ DARK_MATTER_NOLABELS: baseUrl.replace('{basemap}', 'dark-matter-nolabels')
9
+ };
@@ -0,0 +1,26 @@
1
+ export declare const defaultClassicCredentials: {
2
+ readonly apiKey: "default_public";
3
+ readonly region: "us";
4
+ readonly username: "public";
5
+ };
6
+ export declare const defaultCloudNativeCredentials: {
7
+ readonly apiBaseUrl: "https://gcp-us-east1.api.carto.com";
8
+ };
9
+ export interface ClassicCredentials {
10
+ apiVersion: 'v1' | 'v2';
11
+ apiKey: string;
12
+ region: string;
13
+ username: string;
14
+ mapsUrl?: string;
15
+ }
16
+ export interface CloudNativeCredentials {
17
+ apiVersion: 'v3';
18
+ apiBaseUrl: string;
19
+ accessToken?: string;
20
+ mapsUrl?: string;
21
+ }
22
+ export declare type Credentials = ClassicCredentials | CloudNativeCredentials;
23
+ export declare function setDefaultCredentials({ apiVersion, ...rest }: Partial<Credentials>): void;
24
+ export declare function getDefaultCredentials(): Credentials;
25
+ export declare function buildMapsUrlFromBase(apiBaseUrl: string): string;
26
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB;;;;CAI5B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;CAEhC,CAAC;AAEX,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,oBAAY,WAAW,GAAG,kBAAkB,GAAG,sBAAsB,CAAC;AAKtE,wBAAgB,qBAAqB,CAAC,EAAC,UAAU,EAAE,GAAG,IAAI,EAAC,EAAE,OAAO,CAAC,WAAW,CAAC,QAchF;AAED,wBAAgB,qBAAqB,IAAI,WAAW,CAEnD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAO/D"}
@@ -0,0 +1,35 @@
1
+ import { API_VERSIONS } from './api/maps-api-common';
2
+ export const defaultClassicCredentials = {
3
+ apiKey: 'default_public',
4
+ region: 'us',
5
+ username: 'public'
6
+ };
7
+ export const defaultCloudNativeCredentials = {
8
+ apiBaseUrl: 'https://gcp-us-east1.api.carto.com'
9
+ };
10
+ let credentials = {};
11
+ setDefaultCredentials({});
12
+ export function setDefaultCredentials({ apiVersion, ...rest }) {
13
+ apiVersion = apiVersion || API_VERSIONS.V3;
14
+ switch (apiVersion) {
15
+ case API_VERSIONS.V1:
16
+ case API_VERSIONS.V2:
17
+ credentials = { apiVersion, ...defaultClassicCredentials, ...rest };
18
+ break;
19
+ case API_VERSIONS.V3:
20
+ credentials = { apiVersion, ...defaultCloudNativeCredentials, ...rest };
21
+ break;
22
+ default:
23
+ throw new Error(`Invalid API version ${apiVersion}. Use API_VERSIONS enum.`);
24
+ }
25
+ }
26
+ export function getDefaultCredentials() {
27
+ return credentials;
28
+ }
29
+ export function buildMapsUrlFromBase(apiBaseUrl) {
30
+ let suffix = '/v3/maps';
31
+ if (apiBaseUrl.endsWith('/')) {
32
+ suffix = suffix.substring(1);
33
+ }
34
+ return `${apiBaseUrl}${suffix}`;
35
+ }
@@ -0,0 +1,12 @@
1
+ export { getDefaultCredentials, setDefaultCredentials } from './config';
2
+ export { default as CartoLayer } from './layers/carto-layer';
3
+ export { default as _CartoTileLayer } from './layers/carto-tile-layer';
4
+ export { default as _H3TileLayer } from './layers/h3-tile-layer';
5
+ export { default as _QuadkeyTileLayer } from './layers/quadkey-tile-layer';
6
+ export { default as BASEMAP } from './basemap';
7
+ export { default as colorBins } from './style/color-bins-style';
8
+ export { default as colorCategories } from './style/color-categories-style';
9
+ export { default as colorContinuous } from './style/color-continuous-style';
10
+ export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS, fetchLayerData, fetchMap, getDataV2 as _getDataV2, getData, mapInstantiation as _mapInstantiation } from './api';
11
+ export type { CartoLayerProps } from './layers/carto-layer';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAE,qBAAqB,EAAC,MAAM,UAAU,CAAC;AACtE,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,SAAS,IAAI,UAAU,EACvB,OAAO,EACP,gBAAgB,IAAI,iBAAiB,EACtC,MAAM,OAAO,CAAC;AAEf,YAAY,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC"}
package/typed/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { getDefaultCredentials, setDefaultCredentials } from './config';
2
+ export { default as CartoLayer } from './layers/carto-layer';
3
+ export { default as _CartoTileLayer } from './layers/carto-tile-layer';
4
+ export { default as _H3TileLayer } from './layers/h3-tile-layer';
5
+ export { default as _QuadkeyTileLayer } from './layers/quadkey-tile-layer';
6
+ export { default as BASEMAP } from './basemap';
7
+ export { default as colorBins } from './style/color-bins-style';
8
+ export { default as colorCategories } from './style/color-categories-style';
9
+ export { default as colorContinuous } from './style/color-continuous-style';
10
+ export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS, fetchLayerData, fetchMap, getDataV2 as _getDataV2, getData, mapInstantiation as _mapInstantiation } from './api';
@@ -0,0 +1,98 @@
1
+ import { CompositeLayer, Layer } from '@deck.gl/core/typed';
2
+ import { Format, MapType, TileFormat } from '../api/maps-api-common';
3
+ import { Credentials } from '../config';
4
+ import { CompositeLayerProps, LayerProps } from 'modules/core/src/types/layer-props';
5
+ import { ChangeFlags } from 'modules/core/src/lib/layer-state';
6
+ /** All properties supported by CartoLayer. */
7
+ export declare type CartoLayerProps<DataT = any> = _CartoLayerProps & CompositeLayerProps<DataT>;
8
+ /** Properties added by CartoLayer. */
9
+ declare type _CartoLayerProps = {
10
+ /**
11
+ * Either a SQL query or a name of dataset/tileset.
12
+ */
13
+ data: string;
14
+ /**
15
+ * Data type.
16
+ *
17
+ * Possible values are:
18
+ * * `MAP_TYPES.QUERY`, if data is a SQL query.
19
+ * * `MAP_TYPES.TILESET`, if data is a tileset name.
20
+ * * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.
21
+ */
22
+ type: MapType;
23
+ /**
24
+ * Name of the connection registered in the CARTO workspace.
25
+ *
26
+ * Required when apiVersion is `API_VERSIONS.V3`.
27
+ */
28
+ connection?: string;
29
+ /**
30
+ * Use to override the default data format.
31
+ *
32
+ * Only supported when apiVersion is `API_VERSIONS.V3`.
33
+ *
34
+ * Possible values are: `FORMATS.GEOJSON`, `FORMATS.JSON` and `FORMATS.TILEJSON`.
35
+ */
36
+ format?: Format;
37
+ /**
38
+ * Use to override the default tile data format.
39
+ *
40
+ * Only supported when apiVersion is `API_VERSIONS.V3` and format is `FORMATS.TILEJSON`.
41
+ *
42
+ * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
43
+ */
44
+ formatTiles?: TileFormat;
45
+ /**
46
+ * Name of the geo_column in the CARTO platform.
47
+ *
48
+ * Use this override the default column (`'geom'`), from which the geometry information should be fetched.
49
+ *
50
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
51
+ */
52
+ geoColumn?: string;
53
+ /**
54
+ * Names of columns to fetch.
55
+ *
56
+ * By default, all columns are fetched
57
+ *
58
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
59
+ */
60
+ columns?: string[];
61
+ /**
62
+ * A string pointing to a unique attribute at the result of the query.
63
+ *
64
+ * A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.
65
+ */
66
+ uniqueIdProperty?: string;
67
+ /**
68
+ * Optional. Overrides the configuration to connect with CARTO.
69
+ *
70
+ * @see Credentials
71
+ */
72
+ credentials?: Credentials;
73
+ /**
74
+ * Called when the request to the CARTO Maps API failed.
75
+ *
76
+ * By default the Error is thrown.
77
+ */
78
+ onDataError?: (err: unknown) => void;
79
+ clientId?: string;
80
+ };
81
+ export default class CartoLayer<ExtraProps = {}> extends CompositeLayer<Required<_CartoLayerProps> & ExtraProps> {
82
+ static layerName: string;
83
+ static defaultProps: any;
84
+ initializeState(): void;
85
+ get isLoaded(): boolean;
86
+ _checkProps(props: CartoLayerProps): void;
87
+ updateState({ props, oldProps, changeFlags }: {
88
+ props: CartoLayerProps;
89
+ oldProps: CartoLayerProps;
90
+ context: any;
91
+ changeFlags: ChangeFlags;
92
+ }): void;
93
+ _updateData(): Promise<void>;
94
+ _getSubLayerAndProps(): [any, LayerProps];
95
+ renderLayers(): Layer | null;
96
+ }
97
+ export {};
98
+ //# sourceMappingURL=carto-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carto-layer.d.ts","sourceRoot":"","sources":["../../src/layers/carto-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,KAAK,EAAM,MAAM,eAAe,CAAC;AAOzD,OAAO,EAEL,MAAM,EAGN,OAAO,EAEP,UAAU,EAEX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,WAAW,EAEZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAC,mBAAmB,EAAE,UAAU,EAAC,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AA4C7D,8CAA8C;AAC9C,oBAAY,eAAe,CAAC,KAAK,GAAG,GAAG,IAAI,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAEzF,sCAAsC;AACtC,aAAK,gBAAgB,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAErC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,UAAU,GAAG,EAAE,CAAE,SAAQ,cAAc,CACrE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,UAAU,CACxC;IACC,MAAM,CAAC,SAAS,SAAgB;IAChC,MAAM,CAAC,YAAY,MAAuB;IAE1C,eAAe,IAAI,IAAI;IAOvB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAuCzC,WAAW,CAAC,EACV,KAAK,EACL,QAAQ,EACR,WAAW,EACZ,EAAE;QACD,KAAK,EAAE,eAAe,CAAC;QACvB,QAAQ,EAAE,eAAe,CAAC;QAC1B,OAAO,EAAE,GAAG,CAAC;QACb,WAAW,EAAE,WAAW,CAAC;KAC1B,GAAG,IAAI;IAmBF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAqClC,oBAAoB,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC;IAqCzC,YAAY,IAAI,KAAK,GAAG,IAAI;CAqB7B"}
@@ -0,0 +1,173 @@
1
+ import { CompositeLayer, log } from '@deck.gl/core';
2
+ import CartoTileLayer from './carto-tile-layer';
3
+ import H3TileLayer from './h3-tile-layer';
4
+ import QuadkeyTileLayer from './quadkey-tile-layer';
5
+ import { MVTLayer } from '@deck.gl/geo-layers';
6
+ import { GeoJsonLayer } from '@deck.gl/layers';
7
+ import { fetchLayerData, getDataV2, API_VERSIONS } from '../api';
8
+ import { COLUMNS_SUPPORT, FORMATS, GEO_COLUMN_SUPPORT, MAP_TYPES, TILE_FORMATS } from '../api/maps-api-common';
9
+ import { getDefaultCredentials } from '../config';
10
+ import { assert } from '../utils';
11
+ const defaultProps = {
12
+ // (String, required): data resource to load. table name, sql query or tileset name.
13
+ data: null,
14
+ // (Enum (MAP_TYPES), required)
15
+ type: null,
16
+ onDataLoad: { type: 'function', value: data => { }, compare: false },
17
+ onDataError: { type: 'function', value: null, compare: false, optional: true },
18
+ uniqueIdProperty: 'cartodb_id',
19
+ // override carto credentials for the layer, set to null to read from default
20
+ credentials: null,
21
+ /*********************/
22
+ /* API v3 PARAMETERS */
23
+ /**********************/
24
+ // (String, required): connection name at CARTO platform
25
+ connection: null,
26
+ // (String, optional): format of data
27
+ format: null,
28
+ // (String, optional): force format of data for tiles
29
+ formatTiles: null,
30
+ // (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.
31
+ clientId: null,
32
+ // (String, optional): name of the `geo_column` in the CARTO platform. Use this override the default column ('geom'), from which the geometry information should be fetched.
33
+ geoColumn: null,
34
+ // (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
35
+ columns: { type: 'array', value: null },
36
+ // (String, optional): aggregration SQL expression. Only used for spatial index datasets
37
+ aggregationExp: null,
38
+ // (Number, optional): aggregration resolution level. Only used for spatial index datasets, defaults to 6 for quadkeys, 4 for h3
39
+ aggregationResLevel: null
40
+ };
41
+ export default class CartoLayer extends CompositeLayer {
42
+ initializeState() {
43
+ this.state = {
44
+ data: null,
45
+ apiVersion: null
46
+ };
47
+ }
48
+ get isLoaded() {
49
+ return this.getSubLayers().length > 0 && super.isLoaded;
50
+ }
51
+ _checkProps(props) {
52
+ const { type, credentials, connection, geoColumn, columns } = props;
53
+ const localCreds = { ...getDefaultCredentials(), ...credentials };
54
+ const { apiVersion } = localCreds;
55
+ log.assert(Object.values(API_VERSIONS).includes(apiVersion), `Invalid apiVersion ${apiVersion}. Use API_VERSIONS enum.`);
56
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
57
+ log.assert(type === MAP_TYPES.QUERY || type === MAP_TYPES.TILESET, `Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`);
58
+ log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);
59
+ log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);
60
+ log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);
61
+ }
62
+ else if (apiVersion === API_VERSIONS.V3) {
63
+ log.assert(connection, 'Missing mandatory connection parameter');
64
+ log.assert(Object.values(MAP_TYPES).includes(type), `Invalid type ${type}. Use MAP_TYPES enum.`);
65
+ if (!COLUMNS_SUPPORT.includes(type)) {
66
+ log.assert(!columns, `columns prop is only supported for types: ${COLUMNS_SUPPORT.join()}`);
67
+ }
68
+ if (!GEO_COLUMN_SUPPORT.includes(type)) {
69
+ log.assert(!geoColumn, `geoColumn prop is only supported for types: ${GEO_COLUMN_SUPPORT.join()}`);
70
+ }
71
+ if (columns) {
72
+ log.assert(Array.isArray(columns), 'columns prop must be an Array');
73
+ }
74
+ }
75
+ }
76
+ updateState({ props, oldProps, changeFlags }) {
77
+ this._checkProps(props);
78
+ const shouldUpdateData = changeFlags.dataChanged ||
79
+ props.connection !== oldProps.connection ||
80
+ props.geoColumn !== oldProps.geoColumn ||
81
+ props.format !== oldProps.format ||
82
+ props.formatTiles !== oldProps.formatTiles ||
83
+ props.type !== oldProps.type ||
84
+ JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||
85
+ JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials);
86
+ if (shouldUpdateData) {
87
+ this.setState({ data: null, apiVersion: null });
88
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
89
+ this._updateData();
90
+ }
91
+ }
92
+ async _updateData() {
93
+ try {
94
+ const { type, data: source, clientId, credentials, connection, ...rest } = this.props;
95
+ const localConfig = { ...getDefaultCredentials(), ...credentials };
96
+ const { apiVersion } = localConfig;
97
+ let result;
98
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
99
+ result = {
100
+ data: await getDataV2({ type, source, credentials: credentials })
101
+ };
102
+ }
103
+ else {
104
+ result = await fetchLayerData({
105
+ type,
106
+ source,
107
+ clientId,
108
+ credentials: credentials,
109
+ connection,
110
+ ...rest
111
+ });
112
+ }
113
+ this.setState({ ...result, apiVersion });
114
+ this.props.onDataLoad?.(result.data, {
115
+ propName: 'data',
116
+ layer: this
117
+ });
118
+ }
119
+ catch (err) {
120
+ if (this.props.onDataError) {
121
+ this.props.onDataError(err);
122
+ }
123
+ else {
124
+ throw err;
125
+ }
126
+ }
127
+ }
128
+ _getSubLayerAndProps() {
129
+ assert(this.state);
130
+ const { data, format, apiVersion } = this.state;
131
+ const { uniqueIdProperty } = defaultProps;
132
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
+ const { data: _notUsed, ...propsNoData } = this.props;
134
+ // @ts-expect-error 'uniqueIdProperty' is specified more than once, so this usage will be overwritten.
135
+ const props = { uniqueIdProperty, ...propsNoData };
136
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
137
+ return [MVTLayer, props];
138
+ }
139
+ if (format === FORMATS.TILEJSON) {
140
+ /* global URL */
141
+ const tileUrl = new URL(data.tiles[0]);
142
+ props.formatTiles =
143
+ props.formatTiles ||
144
+ tileUrl.searchParams.get('formatTiles') ||
145
+ TILE_FORMATS.MVT;
146
+ if (data.scheme === 'h3') {
147
+ return [H3TileLayer, props];
148
+ }
149
+ if (data.scheme === 'quadkey') {
150
+ return [QuadkeyTileLayer, props];
151
+ }
152
+ return props.formatTiles === TILE_FORMATS.MVT ? [MVTLayer, props] : [CartoTileLayer, props];
153
+ }
154
+ // It's a geojson layer
155
+ return [GeoJsonLayer, props];
156
+ }
157
+ renderLayers() {
158
+ assert(this.state);
159
+ const { data } = this.state;
160
+ if (!data)
161
+ return null;
162
+ const { updateTriggers } = this.props;
163
+ const [layer, props] = this._getSubLayerAndProps();
164
+ // eslint-disable-next-line new-cap
165
+ return new layer(props, this.getSubLayerProps({
166
+ id: `carto-${layer.layerName}`,
167
+ data,
168
+ updateTriggers
169
+ }));
170
+ }
171
+ }
172
+ CartoLayer.layerName = 'CartoLayer';
173
+ CartoLayer.defaultProps = defaultProps;
@@ -0,0 +1,63 @@
1
+ import { MVTLayer, MVTLayerProps, TileLayer, _Tile2DHeader, _TileLoadProps as TileLoadProps } from '@deck.gl/geo-layers/typed';
2
+ import { GeoJsonLayer } from '@deck.gl/layers/typed';
3
+ import { TileFormat } from '../api/maps-api-common';
4
+ import { LoaderWithParser } from '@loaders.gl/loader-utils';
5
+ import type { Feature } from 'geojson';
6
+ /** All properties supported by CartoTileLayer. */
7
+ export declare type CartoTileLayerProps<DataT extends Feature = Feature> = _CartoTileLayerProps & MVTLayerProps<DataT>;
8
+ /** Properties added by CartoTileLayer. */
9
+ declare type _CartoTileLayerProps = {
10
+ /** Use to override the default tile data format.
11
+ *
12
+ * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
13
+ *
14
+ * Only supported when `apiVersion` is `API_VERSIONS.V3` and `format` is `FORMATS.TILEJSON`.
15
+ */
16
+ formatTiles?: TileFormat;
17
+ };
18
+ export default class CartoTileLayer<DataT extends Feature = Feature, ExtraProps = {}> extends MVTLayer<DataT, Required<_CartoTileLayerProps> & ExtraProps> {
19
+ static layerName: string;
20
+ static defaultProps: {
21
+ formatTiles: "binary";
22
+ loaders: LoaderWithParser[];
23
+ uniqueIdProperty: {
24
+ type: string;
25
+ value: string;
26
+ };
27
+ highlightedFeatureId: null;
28
+ binary: boolean;
29
+ stroked: boolean;
30
+ filled: boolean;
31
+ extruded: boolean;
32
+ wireframe: boolean;
33
+ iconAtlas: {
34
+ type: string;
35
+ value: null;
36
+ };
37
+ iconMapping: {
38
+ type: string;
39
+ value: {};
40
+ };
41
+ getIcon: {
42
+ type: string;
43
+ value: (f: any) => any;
44
+ };
45
+ getText: {
46
+ type: string;
47
+ value: (f: any) => any;
48
+ };
49
+ pointType: string;
50
+ getRadius: {
51
+ deprecatedFor: string;
52
+ };
53
+ };
54
+ getTileData(tile: TileLoadProps): any;
55
+ renderSubLayers(props: TileLayer['props'] & {
56
+ id: string;
57
+ data: any;
58
+ _offset: number;
59
+ tile: _Tile2DHeader;
60
+ }): GeoJsonLayer | null;
61
+ }
62
+ export {};
63
+ //# sourceMappingURL=carto-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carto-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/carto-tile-layer.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,QAAQ,EACR,aAAa,EACb,SAAS,EAET,aAAa,EACb,cAAc,IAAI,aAAa,EAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAC,UAAU,EAAe,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAgB,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAqErC,kDAAkD;AAClD,oBAAY,mBAAmB,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,IAAI,oBAAoB,GACrF,aAAa,CAAC,KAAK,CAAC,CAAC;AAEvB,0CAA0C;AAC1C,aAAK,oBAAoB,GAAG;IAC1B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,cAAc,CACjC,KAAK,SAAS,OAAO,GAAG,OAAO,EAC/B,UAAU,GAAG,EAAE,CACf,SAAQ,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,UAAU,CAAC;IACpE,MAAM,CAAC,SAAS,SAAoB;IACpC,MAAM,CAAC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAgB;IAEnC,WAAW,CAAC,IAAI,EAAE,aAAa;IA0B/B,eAAe,CACb,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG;QAC1B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,aAAa,CAAC;KACrB,GACA,YAAY,GAAG,IAAI;CAkBvB"}