@deck.gl/carto 9.1.12 → 9.2.0-alpha.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 (41) hide show
  1. package/dist/api/fetch-map.d.ts +13 -45
  2. package/dist/api/fetch-map.d.ts.map +1 -1
  3. package/dist/api/fetch-map.js +45 -202
  4. package/dist/api/fetch-map.js.map +1 -1
  5. package/dist/api/index.d.ts +1 -1
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +1 -1
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/cartoPropertiesTile-worker.js +1 -1
  10. package/dist/cartoRasterTile-worker.js +1 -1
  11. package/dist/cartoSpatialTile-worker.js +1 -1
  12. package/dist/cartoVectorTile-worker.js +1 -1
  13. package/dist/dist.dev.js +14497 -12442
  14. package/dist/index.cjs +24 -848
  15. package/dist/index.cjs.map +4 -4
  16. package/dist/index.d.ts +1 -17
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -18
  19. package/dist/index.js.map +1 -1
  20. package/dist/layers/schema/carto-properties-tile-loader.js +1 -1
  21. package/dist/layers/schema/carto-properties-tile-loader.js.map +1 -1
  22. package/dist/layers/schema/carto-raster-tile-loader.js +1 -1
  23. package/dist/layers/schema/carto-raster-tile-loader.js.map +1 -1
  24. package/dist/layers/schema/carto-spatial-tile-loader.js +1 -1
  25. package/dist/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  26. package/dist/layers/schema/carto-vector-tile-loader.js +1 -1
  27. package/dist/layers/schema/carto-vector-tile-loader.js.map +1 -1
  28. package/dist/layers/schema/spatialjson-utils.d.ts.map +1 -1
  29. package/dist/layers/schema/spatialjson-utils.js.map +1 -1
  30. package/dist/layers/vector-tile-layer.d.ts.map +1 -1
  31. package/dist/layers/vector-tile-layer.js.map +1 -1
  32. package/dist/utils.d.ts.map +1 -1
  33. package/dist/utils.js.map +1 -1
  34. package/dist.min.js +10 -27
  35. package/package.json +6 -6
  36. package/src/api/fetch-map.ts +54 -341
  37. package/src/api/index.ts +1 -1
  38. package/src/index.ts +1 -74
  39. package/src/layers/schema/spatialjson-utils.ts +0 -1
  40. package/src/layers/vector-tile-layer.ts +1 -2
  41. package/src/utils.ts +1 -6
package/dist/index.cjs CHANGED
@@ -32,15 +32,13 @@ var dist_exports = {};
32
32
  __export(dist_exports, {
33
33
  BASEMAP: () => basemap_default,
34
34
  CARTO_LAYERS: () => CARTO_LAYERS,
35
- CARTO_SOURCES: () => CARTO_SOURCES,
36
- CartoAPIError: () => import_api_client4.CartoAPIError,
37
35
  ClusterTileLayer: () => cluster_tile_layer_default,
38
36
  H3TileLayer: () => h3_tile_layer_default,
39
37
  HeatmapTileLayer: () => heatmap_tile_layer_default,
38
+ LayerFactory: () => LayerFactory,
40
39
  PointLabelLayer: () => point_label_layer_default,
41
40
  QuadbinTileLayer: () => quadbin_tile_layer_default,
42
41
  RasterTileLayer: () => raster_tile_layer_default,
43
- SOURCE_DEFAULTS: () => import_api_client4.SOURCE_DEFAULTS,
44
42
  VectorTileLayer: () => vector_tile_layer_default,
45
43
  _GOOGLE_BASEMAPS: () => GOOGLE_BASEMAPS,
46
44
  _QuadbinLayer: () => quadbin_layer_default,
@@ -50,24 +48,11 @@ __export(dist_exports, {
50
48
  _applyLayerGroupFilters: () => applyLayerGroupFilters,
51
49
  _fetchStyle: () => fetchStyle,
52
50
  _getStyleUrl: () => getStyleUrl,
53
- boundaryQuerySource: () => import_api_client4.boundaryQuerySource,
54
- boundaryTableSource: () => import_api_client4.boundaryTableSource,
55
51
  colorBins: () => colorBins,
56
52
  colorCategories: () => colorCategories,
57
53
  colorContinuous: () => colorContinuous,
58
54
  fetchBasemapProps: () => fetchBasemapProps,
59
- fetchMap: () => fetchMap,
60
- h3QuerySource: () => import_api_client4.h3QuerySource,
61
- h3TableSource: () => import_api_client4.h3TableSource,
62
- h3TilesetSource: () => import_api_client4.h3TilesetSource,
63
- quadbinQuerySource: () => import_api_client4.quadbinQuerySource,
64
- quadbinTableSource: () => import_api_client4.quadbinTableSource,
65
- quadbinTilesetSource: () => import_api_client4.quadbinTilesetSource,
66
- query: () => import_api_client4.query,
67
- rasterSource: () => import_api_client4.rasterSource,
68
- vectorQuerySource: () => import_api_client4.vectorQuerySource,
69
- vectorTableSource: () => import_api_client4.vectorTableSource,
70
- vectorTilesetSource: () => import_api_client4.vectorTilesetSource
55
+ fetchMap: () => fetchMap
71
56
  });
72
57
  module.exports = __toCommonJS(dist_exports);
73
58
 
@@ -110,26 +95,6 @@ function createBinaryProxy(data, index) {
110
95
  function getWorkerUrl(id5, version) {
111
96
  return `https://unpkg.com/@deck.gl/carto@${version}/dist/${id5}-worker.js`;
112
97
  }
113
- function scaleIdentity() {
114
- let unknown;
115
- function scale(x) {
116
- return x === null ? unknown : x;
117
- }
118
- scale.invert = scale;
119
- scale.domain = scale.range = (d) => d;
120
- scale.unknown = (u) => {
121
- if (u) {
122
- unknown = u;
123
- }
124
- return unknown;
125
- };
126
- scale.copy = () => {
127
- const scaleCopy = scaleIdentity();
128
- scaleCopy.unknown(unknown);
129
- return scaleCopy;
130
- };
131
- return scale;
132
- }
133
98
  var EMPTY_UINT16ARRAY = new Uint16Array();
134
99
  var EMPTY_BINARY_PROPS = {
135
100
  positions: { value: new Float32Array(), size: 2 },
@@ -591,7 +556,7 @@ function binaryToSpatialjson(binary) {
591
556
  }
592
557
 
593
558
  // dist/layers/schema/carto-spatial-tile-loader.js
594
- var VERSION = true ? "9.1.12" : "latest";
559
+ var VERSION = true ? "9.2.0-alpha.2" : "latest";
595
560
  var id = "cartoSpatialTile";
596
561
  var DEFAULT_OPTIONS = {
597
562
  cartoSpatialTile: {
@@ -2002,7 +1967,7 @@ var TileReader3 = class {
2002
1967
  };
2003
1968
 
2004
1969
  // dist/layers/schema/carto-raster-tile-loader.js
2005
- var VERSION2 = true ? "9.1.12" : "latest";
1970
+ var VERSION2 = true ? "9.2.0-alpha.2" : "latest";
2006
1971
  var id2 = "cartoRasterTile";
2007
1972
  var DEFAULT_OPTIONS2 = {
2008
1973
  cartoRasterTile: {
@@ -2114,7 +2079,7 @@ var TileReader4 = class {
2114
2079
  };
2115
2080
 
2116
2081
  // dist/layers/schema/carto-properties-tile-loader.js
2117
- var VERSION3 = true ? "9.1.12" : "latest";
2082
+ var VERSION3 = true ? "9.2.0-alpha.2" : "latest";
2118
2083
  var id3 = "cartoPropertiesTile";
2119
2084
  var DEFAULT_OPTIONS3 = {
2120
2085
  cartoPropertiesTile: {
@@ -2143,7 +2108,7 @@ var carto_properties_tile_loader_default = CartoPropertiesTileLoader;
2143
2108
 
2144
2109
  // dist/layers/schema/carto-vector-tile-loader.js
2145
2110
  var import_earcut = __toESM(require("earcut"), 1);
2146
- var VERSION4 = true ? "9.1.12" : "latest";
2111
+ var VERSION4 = true ? "9.2.0-alpha.2" : "latest";
2147
2112
  var id4 = "cartoVectorTile";
2148
2113
  var DEFAULT_OPTIONS4 = {
2149
2114
  cartoVectorTile: {
@@ -2769,54 +2734,7 @@ function colorContinuous({ attr, domain, colors = DEFAULT_PALETTE, nullColor = N
2769
2734
 
2770
2735
  // dist/api/fetch-map.js
2771
2736
  var import_api_client2 = require("@carto/api-client");
2772
-
2773
- // dist/api/parse-map.js
2774
- var import_core17 = require("@deck.gl/core");
2775
-
2776
- // dist/api/layer-map.js
2777
- var import_d3_array = require("d3-array");
2778
- var import_d3_color = require("d3-color");
2779
- var import_d3_scale3 = require("d3-scale");
2780
- var import_d3_format = require("d3-format");
2781
- var import_moment_timezone = __toESM(require("moment-timezone"), 1);
2782
- var import_aggregation_layers = require("@deck.gl/aggregation-layers");
2783
- var import_layers6 = require("@deck.gl/layers");
2784
- var import_geo_layers9 = require("@deck.gl/geo-layers");
2785
- var SCALE_FUNCS = {
2786
- linear: import_d3_scale3.scaleLinear,
2787
- ordinal: import_d3_scale3.scaleOrdinal,
2788
- log: import_d3_scale3.scaleLog,
2789
- point: import_d3_scale3.scalePoint,
2790
- quantile: import_d3_scale3.scaleQuantile,
2791
- quantize: import_d3_scale3.scaleQuantize,
2792
- sqrt: import_d3_scale3.scaleSqrt,
2793
- custom: import_d3_scale3.scaleThreshold,
2794
- identity: scaleIdentity
2795
- };
2796
- function identity(v) {
2797
- return v;
2798
- }
2799
- var UNKNOWN_COLOR = "#868d91";
2800
- var AGGREGATION = {
2801
- average: "MEAN",
2802
- maximum: "MAX",
2803
- minimum: "MIN",
2804
- sum: "SUM"
2805
- };
2806
- var OPACITY_MAP = {
2807
- getFillColor: "opacity",
2808
- getLineColor: "strokeOpacity",
2809
- getTextColor: "opacity"
2810
- };
2811
- var AGGREGATION_FUNC = {
2812
- "count unique": (values, accessor) => (0, import_d3_array.groupSort)(values, (v) => v.length, accessor).length,
2813
- median: import_d3_array.median,
2814
- // Unfortunately mode() is only available in d3-array@3+ which is ESM only
2815
- mode: (values, accessor) => (0, import_d3_array.groupSort)(values, (v) => v.length, accessor).pop(),
2816
- stddev: import_d3_array.deviation,
2817
- variance: import_d3_array.variance
2818
- };
2819
- var TILE_LAYER_TYPE_TO_LAYER = {
2737
+ var layerClasses = {
2820
2738
  clusterTile: cluster_tile_layer_default,
2821
2739
  h3: h3_tile_layer_default,
2822
2740
  heatmapTile: heatmap_tile_layer_default,
@@ -2825,576 +2743,31 @@ var TILE_LAYER_TYPE_TO_LAYER = {
2825
2743
  raster: raster_tile_layer_default,
2826
2744
  tileset: vector_tile_layer_default
2827
2745
  };
2828
- var hexToRGBA = (c) => {
2829
- const { r, g, b, opacity } = (0, import_d3_color.rgb)(c);
2830
- return [r, g, b, 255 * opacity];
2831
- };
2832
- var sharedPropMap = {
2833
- // Apply the value of Kepler `color` prop to the deck `getFillColor` prop
2834
- color: "getFillColor",
2835
- isVisible: "visible",
2836
- label: "cartoLabel",
2837
- textLabel: {
2838
- alignment: "getTextAlignmentBaseline",
2839
- anchor: "getTextAnchor",
2840
- // Apply the value of Kepler `textLabel.color` prop to the deck `getTextColor` prop
2841
- color: "getTextColor",
2842
- size: "getTextSize"
2843
- },
2844
- visConfig: {
2845
- enable3d: "extruded",
2846
- elevationScale: "elevationScale",
2847
- filled: "filled",
2848
- strokeColor: "getLineColor",
2849
- stroked: "stroked",
2850
- thickness: "getLineWidth",
2851
- radius: "getPointRadius",
2852
- wireframe: "wireframe"
2853
- }
2854
- };
2855
- var customMarkersPropsMap = {
2856
- color: "getIconColor",
2857
- visConfig: {
2858
- radius: "getIconSize"
2859
- }
2860
- };
2861
- var heatmapTilePropsMap = {
2862
- visConfig: {
2863
- colorRange: (x) => ({ colorRange: x.colors.map(hexToRGBA) }),
2864
- radius: "radiusPixels"
2865
- }
2866
- };
2867
- var aggregationVisConfig = {
2868
- colorAggregation: (x) => ({ colorAggregation: AGGREGATION[x] || AGGREGATION.sum }),
2869
- colorRange: (x) => ({ colorRange: x.colors.map(hexToRGBA) }),
2870
- coverage: "coverage",
2871
- elevationPercentile: ["elevationLowerPercentile", "elevationUpperPercentile"],
2872
- percentile: ["lowerPercentile", "upperPercentile"]
2873
- };
2874
- var defaultProps11 = {
2875
- lineMiterLimit: 2,
2876
- lineWidthUnits: "pixels",
2877
- pointRadiusUnits: "pixels",
2878
- rounded: true,
2879
- wrapLongitude: false
2880
- };
2881
- function mergePropMaps(a = {}, b = {}) {
2882
- return { ...a, ...b, visConfig: { ...a.visConfig, ...b.visConfig } };
2883
- }
2884
- function getLayer(type, config, dataset) {
2885
- var _a, _b;
2886
- let basePropMap = sharedPropMap;
2887
- if ((_a = config.visConfig) == null ? void 0 : _a.customMarkers) {
2888
- basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
2889
- }
2890
- if (type === "heatmapTile") {
2891
- basePropMap = mergePropMaps(basePropMap, heatmapTilePropsMap);
2892
- }
2893
- if (TILE_LAYER_TYPE_TO_LAYER[type]) {
2894
- return getTileLayer(dataset, basePropMap, type);
2895
- }
2896
- const geoColumn = dataset == null ? void 0 : dataset.geoColumn;
2897
- const getPosition = (d) => d[geoColumn].coordinates;
2898
- const hexagonId = (_b = config.columns) == null ? void 0 : _b.hex_id;
2899
- const layerTypeDefs = {
2900
- point: {
2901
- Layer: import_layers6.GeoJsonLayer,
2902
- propMap: {
2903
- columns: {
2904
- altitude: (x) => ({ parameters: { depthWriteEnabled: Boolean(x) } })
2905
- },
2906
- visConfig: { outline: "stroked" }
2907
- }
2908
- },
2909
- geojson: {
2910
- Layer: import_layers6.GeoJsonLayer
2911
- },
2912
- grid: {
2913
- Layer: import_aggregation_layers.GridLayer,
2914
- propMap: { visConfig: { ...aggregationVisConfig, worldUnitSize: (x) => ({ cellSize: 1e3 * x }) } },
2915
- defaultProps: { getPosition }
2916
- },
2917
- heatmap: {
2918
- Layer: import_aggregation_layers.HeatmapLayer,
2919
- propMap: { visConfig: { ...aggregationVisConfig, radius: "radiusPixels" } },
2920
- defaultProps: { getPosition }
2921
- },
2922
- hexagon: {
2923
- Layer: import_aggregation_layers.HexagonLayer,
2924
- propMap: { visConfig: { ...aggregationVisConfig, worldUnitSize: (x) => ({ radius: 1e3 * x }) } },
2925
- defaultProps: { getPosition }
2926
- },
2927
- hexagonId: {
2928
- Layer: import_geo_layers9.H3HexagonLayer,
2929
- propMap: { visConfig: { coverage: "coverage" } },
2930
- defaultProps: { getHexagon: (d) => d[hexagonId], stroked: false }
2931
- }
2932
- };
2933
- const layer = layerTypeDefs[type];
2934
- assert(layer, `Unsupported layer type: ${type}`);
2935
- return {
2936
- ...layer,
2937
- propMap: mergePropMaps(basePropMap, layer.propMap),
2938
- defaultProps: { ...defaultProps11, ...layer.defaultProps }
2939
- };
2940
- }
2941
- function getTileLayer(dataset, basePropMap, type) {
2942
- const { aggregationExp, aggregationResLevel } = dataset;
2943
- return {
2944
- Layer: TILE_LAYER_TYPE_TO_LAYER[type] || vector_tile_layer_default,
2945
- propMap: basePropMap,
2946
- defaultProps: {
2947
- ...defaultProps11,
2948
- ...aggregationExp && { aggregationExp },
2949
- ...aggregationResLevel && { aggregationResLevel },
2950
- uniqueIdProperty: "geoid"
2951
- }
2952
- };
2953
- }
2954
- function domainFromAttribute(attribute, scaleType, scaleLength) {
2955
- if (scaleType === "ordinal" || scaleType === "point") {
2956
- return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
2957
- }
2958
- if (scaleType === "quantile" && attribute.quantiles) {
2959
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
2960
- }
2961
- let { min } = attribute;
2962
- if (scaleType === "log" && min === 0) {
2963
- min = 1e-5;
2964
- }
2965
- return [min, attribute.max];
2966
- }
2967
- function domainFromValues(values, scaleType) {
2968
- if (scaleType === "ordinal" || scaleType === "point") {
2969
- return (0, import_d3_array.groupSort)(values, (g) => -g.length, (d) => d);
2970
- } else if (scaleType === "quantile") {
2971
- return values.sort((a, b) => a - b);
2972
- } else if (scaleType === "log") {
2973
- const [d0, d1] = (0, import_d3_array.extent)(values);
2974
- return [d0 === 0 ? 1e-5 : d0, d1];
2975
- }
2976
- return (0, import_d3_array.extent)(values);
2977
- }
2978
- function calculateDomain(data, name, scaleType, scaleLength) {
2979
- if (data.tilestats) {
2980
- const { attributes } = data.tilestats.layers[0];
2981
- const attribute = attributes.find((a) => a.attribute === name);
2982
- return domainFromAttribute(attribute, scaleType, scaleLength);
2983
- } else if (data.features) {
2984
- const values = data.features.map(({ properties }) => properties[name]);
2985
- return domainFromValues(values, scaleType);
2986
- } else if (Array.isArray(data) && data[0][name] !== void 0) {
2987
- const values = data.map((properties) => properties[name]);
2988
- return domainFromValues(values, scaleType);
2989
- }
2990
- return [0, 1];
2991
- }
2992
- function normalizeAccessor(accessor, data) {
2993
- if (data.features || data.tilestats) {
2994
- return (object, info) => {
2995
- if (object) {
2996
- return accessor(object.properties || object.__source.object.properties);
2997
- }
2998
- const { data: data2, index } = info;
2999
- const proxy = createBinaryProxy(data2, index);
3000
- return accessor(proxy);
3001
- };
2746
+ function LayerFactory(descriptor) {
2747
+ const LayerClass = layerClasses[descriptor.type];
2748
+ if (!LayerClass) {
2749
+ throw new Error(`No layer class found for type: ${descriptor.type}`);
3002
2750
  }
3003
- return accessor;
2751
+ return new LayerClass(descriptor.props);
3004
2752
  }
3005
- function opacityToAlpha(opacity) {
3006
- return opacity !== void 0 ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
3007
- }
3008
- function getAccessorKeys(name, aggregation) {
3009
- let keys = [name];
3010
- if (aggregation) {
3011
- keys = keys.concat([aggregation, aggregation.toUpperCase()].map((a) => `${name}_${a}`));
3012
- }
3013
- return keys;
3014
- }
3015
- function findAccessorKey(keys, properties) {
3016
- for (const key of keys) {
3017
- if (key in properties) {
3018
- return [key];
3019
- }
3020
- }
3021
- throw new Error(`Could not find property for any accessor key: ${keys}`);
3022
- }
3023
- function getColorValueAccessor({ name }, colorAggregation, data) {
3024
- const aggregator = AGGREGATION_FUNC[colorAggregation];
3025
- const accessor = (values) => aggregator(values, (p) => p[name]);
3026
- return normalizeAccessor(accessor, data);
3027
- }
3028
- function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
3029
- const scale = calculateLayerScale(colorColumn || name, scaleType, range, data);
3030
- const alpha = opacityToAlpha(opacity);
3031
- let accessorKeys = getAccessorKeys(name, aggregation);
3032
- const accessor = (properties) => {
3033
- if (!(accessorKeys[0] in properties)) {
3034
- accessorKeys = findAccessorKey(accessorKeys, properties);
3035
- }
3036
- const propertyValue = properties[accessorKeys[0]];
3037
- const { r, g, b } = (0, import_d3_color.rgb)(scale(propertyValue));
3038
- return [r, g, b, propertyValue === null ? 0 : alpha];
3039
- };
3040
- return normalizeAccessor(accessor, data);
3041
- }
3042
- function calculateLayerScale(name, scaleType, range, data) {
3043
- const scale = SCALE_FUNCS[scaleType]();
3044
- let domain = [];
3045
- let scaleColor = [];
3046
- if (scaleType !== "identity") {
3047
- const { colorMap, colors } = range;
3048
- if (Array.isArray(colorMap)) {
3049
- colorMap.forEach(([value, color]) => {
3050
- domain.push(value);
3051
- scaleColor.push(color);
3052
- });
3053
- } else {
3054
- domain = calculateDomain(data, name, scaleType, colors.length);
3055
- scaleColor = colors;
3056
- }
3057
- if (scaleType === "ordinal") {
3058
- domain = domain.slice(0, scaleColor.length);
3059
- }
3060
- }
3061
- scale.domain(domain);
3062
- scale.range(scaleColor);
3063
- scale.unknown(UNKNOWN_COLOR);
3064
- return scale;
3065
- }
3066
- var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
3067
- function getIconUrlAccessor(field, range, { fallbackUrl, maxIconSize, useMaskedIcons }, data) {
3068
- const urlToUnpackedIcon = (url) => ({
3069
- id: `${url}@@${maxIconSize}`,
3070
- url,
3071
- width: maxIconSize,
3072
- height: maxIconSize,
3073
- mask: useMaskedIcons
3074
- });
3075
- let unknownValue = fallbackUrl || FALLBACK_ICON;
3076
- if (range == null ? void 0 : range.othersMarker) {
3077
- unknownValue = range.othersMarker;
3078
- }
3079
- const unknownIcon = urlToUnpackedIcon(unknownValue);
3080
- if (!range || !field) {
3081
- return () => unknownIcon;
3082
- }
3083
- const mapping = {};
3084
- for (const { value, markerUrl } of range.markerMap) {
3085
- if (markerUrl) {
3086
- mapping[value] = urlToUnpackedIcon(markerUrl);
3087
- }
3088
- }
3089
- const accessor = (properties) => {
3090
- const propertyValue = properties[field.name];
3091
- return mapping[propertyValue] || unknownIcon;
3092
- };
3093
- return normalizeAccessor(accessor, data);
3094
- }
3095
- function getMaxMarkerSize(visConfig, visualChannels) {
3096
- const { radiusRange, radius } = visConfig;
3097
- const { radiusField, sizeField } = visualChannels;
3098
- const field = radiusField || sizeField;
3099
- return Math.ceil(radiusRange && field ? radiusRange[1] : radius);
3100
- }
3101
- function negateAccessor(accessor) {
3102
- return typeof accessor === "function" ? (d, i) => -accessor(d, i) : -accessor;
3103
- }
3104
- function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
3105
- const scale = scaleType ? SCALE_FUNCS[scaleType]() : identity;
3106
- if (scaleType) {
3107
- if (aggregation !== "count") {
3108
- scale.domain(calculateDomain(data, name, scaleType));
3109
- }
3110
- scale.range(range);
3111
- }
3112
- let accessorKeys = getAccessorKeys(name, aggregation);
3113
- const accessor = (properties) => {
3114
- if (!(accessorKeys[0] in properties)) {
3115
- accessorKeys = findAccessorKey(accessorKeys, properties);
3116
- }
3117
- const propertyValue = properties[accessorKeys[0]];
3118
- return scale(propertyValue);
3119
- };
3120
- return normalizeAccessor(accessor, data);
3121
- }
3122
- var FORMATS = {
3123
- date: (s) => import_moment_timezone.default.utc(s).format("MM/DD/YY HH:mm:ssa"),
3124
- integer: (0, import_d3_format.format)("i"),
3125
- float: (0, import_d3_format.format)(".5f"),
3126
- timestamp: (s) => import_moment_timezone.default.utc(s).format("X"),
3127
- default: String
3128
- };
3129
- function getTextAccessor({ name, type }, data) {
3130
- const format = FORMATS[type] || FORMATS.default;
3131
- const accessor = (properties) => {
3132
- return format(properties[name]);
3133
- };
3134
- return normalizeAccessor(accessor, data);
3135
- }
3136
-
3137
- // dist/api/parse-map.js
3138
- function parseMap(json) {
3139
- const { keplerMapConfig, datasets, token } = json;
3140
- assert(keplerMapConfig.version === "v1", "Only support Kepler v1");
3141
- const { mapState, mapStyle } = keplerMapConfig.config;
3142
- const { layers, layerBlending, interactionConfig } = keplerMapConfig.config.visState;
2753
+ function createResult(result) {
3143
2754
  return {
3144
- id: json.id,
3145
- title: json.title,
3146
- description: json.description,
3147
- createdAt: json.createdAt,
3148
- updatedAt: json.updatedAt,
3149
- initialViewState: mapState,
3150
- /** @deprecated Use `basemap`. */
3151
- mapStyle,
3152
- token,
3153
- layers: layers.reverse().map(({ id: id5, type, config, visualChannels }) => {
3154
- try {
3155
- const { dataId } = config;
3156
- const dataset = datasets.find((d) => d.id === dataId);
3157
- assert(dataset, `No dataset matching dataId: ${dataId}`);
3158
- const { data } = dataset;
3159
- assert(data, `No data loaded for dataId: ${dataId}`);
3160
- const { Layer: Layer2, propMap, defaultProps: defaultProps12 } = getLayer(type, config, dataset);
3161
- const styleProps = createStyleProps(config, propMap);
3162
- return new Layer2({
3163
- id: id5,
3164
- data,
3165
- ...defaultProps12,
3166
- ...createInteractionProps(interactionConfig),
3167
- ...styleProps,
3168
- ...createChannelProps(id5, type, config, visualChannels, data),
3169
- // Must come after style
3170
- ...createParametersProp(layerBlending, styleProps.parameters || {}),
3171
- // Must come after style
3172
- ...createLoadOptions(token)
3173
- });
3174
- } catch (e) {
3175
- import_core17.log.error(e.message)();
3176
- return void 0;
3177
- }
3178
- })
2755
+ ...result,
2756
+ layers: result.layers.map((descriptor) => LayerFactory(descriptor))
3179
2757
  };
3180
2758
  }
3181
- function createParametersProp(layerBlending, parameters) {
3182
- if (layerBlending === "additive") {
3183
- parameters.blendColorSrcFactor = parameters.blendAlphaSrcFactor = "src-alpha";
3184
- parameters.blendColorDstFactor = parameters.blendAlphaDstFactor = "dst-alpha";
3185
- parameters.blendColorOperation = parameters.blendAlphaOperation = "add";
3186
- } else if (layerBlending === "subtractive") {
3187
- parameters.blendColorSrcFactor = "one";
3188
- parameters.blendColorDstFactor = "one-minus-dst-color";
3189
- parameters.blendAlphaSrcFactor = "src-alpha";
3190
- parameters.blendAlphaDstFactor = "dst-alpha";
3191
- parameters.blendColorOperation = "subtract";
3192
- parameters.blendAlphaOperation = "add";
3193
- }
3194
- return Object.keys(parameters).length ? { parameters } : {};
3195
- }
3196
- function createInteractionProps(interactionConfig) {
3197
- const pickable = interactionConfig && interactionConfig.tooltip.enabled;
3198
- return {
3199
- autoHighlight: pickable,
3200
- pickable
2759
+ async function fetchMap(options) {
2760
+ const { onNewData, ...rest } = options;
2761
+ const _options = {
2762
+ ...rest,
2763
+ onNewData: typeof onNewData === "function" ? (result2) => {
2764
+ onNewData(createResult(result2));
2765
+ } : void 0
3201
2766
  };
3202
- }
3203
- function mapProps(source, target, mapping) {
3204
- for (const sourceKey in mapping) {
3205
- const sourceValue = source[sourceKey];
3206
- const targetKey = mapping[sourceKey];
3207
- if (sourceValue === void 0) {
3208
- continue;
3209
- }
3210
- if (typeof targetKey === "string") {
3211
- target[targetKey] = sourceValue;
3212
- } else if (typeof targetKey === "function") {
3213
- const [key, value] = Object.entries(targetKey(sourceValue))[0];
3214
- target[key] = value;
3215
- } else if (typeof targetKey === "object") {
3216
- mapProps(sourceValue, target, targetKey);
3217
- }
3218
- }
3219
- }
3220
- function createStyleProps(config, mapping) {
3221
- const result = {};
3222
- mapProps(config, result, mapping);
3223
- if (result.stroked && !result.getLineColor) {
3224
- result.getLineColor = result.getFillColor;
3225
- }
3226
- for (const colorAccessor in OPACITY_MAP) {
3227
- if (Array.isArray(result[colorAccessor])) {
3228
- const color = [...result[colorAccessor]];
3229
- const opacityKey = OPACITY_MAP[colorAccessor];
3230
- const opacity = config.visConfig[opacityKey];
3231
- color[3] = opacityToAlpha(opacity);
3232
- result[colorAccessor] = color;
3233
- }
3234
- }
3235
- result.highlightColor = config.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
3236
- return result;
3237
- }
3238
- function createChannelProps(id5, type, config, visualChannels, data) {
3239
- var _a;
3240
- const { colorField, colorScale, radiusField, radiusScale, sizeField, sizeScale, strokeColorField, strokeColorScale, weightField } = visualChannels;
3241
- let { heightField, heightScale } = visualChannels;
3242
- if (type === "hexagonId") {
3243
- heightField = sizeField;
3244
- heightScale = sizeScale;
3245
- }
3246
- const { textLabel, visConfig } = config;
3247
- const result = {};
3248
- if (type === "grid" || type === "hexagon") {
3249
- result.colorScaleType = colorScale;
3250
- if (colorField) {
3251
- const { colorAggregation } = config.visConfig;
3252
- if (!AGGREGATION[colorAggregation]) {
3253
- result.getColorValue = getColorValueAccessor(colorField, colorAggregation, data);
3254
- } else {
3255
- result.getColorWeight = (d) => d[colorField.name];
3256
- }
3257
- }
3258
- } else if (colorField) {
3259
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
3260
- result.getFillColor = getColorAccessor(
3261
- colorField,
3262
- // @ts-ignore
3263
- colorScale,
3264
- { aggregation, range },
3265
- visConfig.opacity,
3266
- data
3267
- );
3268
- }
3269
- if (type === "point") {
3270
- const altitude = (_a = config.columns) == null ? void 0 : _a.altitude;
3271
- if (altitude) {
3272
- result.dataTransform = (data2) => {
3273
- data2.features.forEach(({ geometry, properties }) => {
3274
- const { type: type2, coordinates } = geometry;
3275
- if (type2 === "Point") {
3276
- coordinates[2] = properties[altitude];
3277
- }
3278
- });
3279
- return data2;
3280
- };
3281
- }
3282
- }
3283
- if (radiusField || sizeField) {
3284
- result.getPointRadius = getSizeAccessor(
3285
- // @ts-ignore
3286
- radiusField || sizeField,
3287
- // @ts-ignore
3288
- radiusScale || sizeScale,
3289
- visConfig.sizeAggregation,
3290
- visConfig.radiusRange || visConfig.sizeRange,
3291
- data
3292
- );
3293
- }
3294
- if (strokeColorField) {
3295
- const fallbackOpacity = type === "point" ? visConfig.opacity : 1;
3296
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : fallbackOpacity;
3297
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
3298
- result.getLineColor = getColorAccessor(
3299
- strokeColorField,
3300
- // @ts-ignore
3301
- strokeColorScale,
3302
- // @ts-ignore
3303
- { aggregation, range },
3304
- opacity,
3305
- data
3306
- );
3307
- }
3308
- if (heightField && visConfig.enable3d) {
3309
- result.getElevation = getSizeAccessor(
3310
- heightField,
3311
- // @ts-ignore
3312
- heightScale,
3313
- visConfig.heightAggregation,
3314
- visConfig.heightRange || visConfig.sizeRange,
3315
- data
3316
- );
3317
- }
3318
- if (weightField) {
3319
- result.getWeight = getSizeAccessor(weightField, void 0, visConfig.weightAggregation, void 0, data);
3320
- }
3321
- if (visConfig.customMarkers) {
3322
- const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
3323
- const { getPointRadius, getFillColor } = result;
3324
- const { customMarkersUrl, customMarkersRange, filled: useMaskedIcons } = visConfig;
3325
- result.pointType = "icon";
3326
- result.getIcon = getIconUrlAccessor(visualChannels.customMarkersField, customMarkersRange, { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons }, data);
3327
- result._subLayerProps = {
3328
- "points-icon": {
3329
- loadOptions: {
3330
- image: {
3331
- type: "imagebitmap"
3332
- },
3333
- imagebitmap: {
3334
- resizeWidth: maxIconSize,
3335
- resizeHeight: maxIconSize,
3336
- resizeQuality: "high"
3337
- }
3338
- }
3339
- }
3340
- };
3341
- if (getFillColor && useMaskedIcons) {
3342
- result.getIconColor = getFillColor;
3343
- }
3344
- if (getPointRadius) {
3345
- result.getIconSize = getPointRadius;
3346
- }
3347
- if (visualChannels.rotationField) {
3348
- result.getIconAngle = negateAccessor(getSizeAccessor(visualChannels.rotationField, void 0, null, void 0, data));
3349
- }
3350
- } else if (type === "point" || type === "tileset") {
3351
- result.pointType = "circle";
3352
- }
3353
- if (textLabel && textLabel.length && textLabel[0].field) {
3354
- const [mainLabel, secondaryLabel] = textLabel;
3355
- const collisionGroup = id5;
3356
- ({
3357
- alignment: result.getTextAlignmentBaseline,
3358
- anchor: result.getTextAnchor,
3359
- color: result.getTextColor,
3360
- outlineColor: result.textOutlineColor,
3361
- size: result.textSizeScale
3362
- } = mainLabel);
3363
- const { color: getSecondaryColor, field: secondaryField, outlineColor: secondaryOutlineColor, size: secondarySizeScale } = secondaryLabel || {};
3364
- result.getText = mainLabel.field && getTextAccessor(mainLabel.field, data);
3365
- const getSecondaryText = secondaryField && getTextAccessor(secondaryField, data);
3366
- result.pointType = `${result.pointType}+text`;
3367
- result.textCharacterSet = "auto";
3368
- result.textFontFamily = "Inter, sans";
3369
- result.textFontSettings = { sdf: true };
3370
- result.textFontWeight = 600;
3371
- result.textOutlineWidth = 3;
3372
- result._subLayerProps = {
3373
- ...result._subLayerProps,
3374
- "points-text": {
3375
- // The following props are injected by default by VectorTileLayer:
3376
- // type: PointLabelLayer,
3377
- // extensions: [new CollisionFilterExtension()],
3378
- collisionEnabled: true,
3379
- collisionGroup,
3380
- // getPointRadius already has radiusScale baked in, so only pass one or the other
3381
- ...result.getPointRadius ? { getRadius: result.getPointRadius } : { radiusScale: visConfig.radius },
3382
- ...secondaryField && {
3383
- getSecondaryText,
3384
- getSecondaryColor,
3385
- secondarySizeScale,
3386
- secondaryOutlineColor
3387
- }
3388
- }
3389
- };
3390
- }
2767
+ const _result = await (0, import_api_client2.fetchMap)(_options);
2768
+ const result = createResult(_result);
3391
2769
  return result;
3392
2770
  }
3393
- function createLoadOptions(accessToken) {
3394
- return {
3395
- loadOptions: { fetch: { headers: { Authorization: `Bearer ${accessToken}` } } }
3396
- };
3397
- }
3398
2771
 
3399
2772
  // dist/api/basemap.js
3400
2773
  var CUSTOM_STYLE_ID_PREFIX = "custom:";
@@ -3465,190 +2838,7 @@ async function fetchBasemapProps({ config, errorContext, applyLayerFilters = tru
3465
2838
  };
3466
2839
  }
3467
2840
 
3468
- // dist/api/fetch-map.js
3469
- async function _fetchMapDataset(dataset, context) {
3470
- const { aggregationExp, aggregationResLevel, connectionName, columns, format, geoColumn, source, type, queryParameters } = dataset;
3471
- const cache = {};
3472
- const globalOptions = {
3473
- ...context,
3474
- cache,
3475
- connectionName,
3476
- format
3477
- };
3478
- if (type === "tileset") {
3479
- dataset.data = await (0, import_api_client2.vectorTilesetSource)({ ...globalOptions, tableName: source });
3480
- } else {
3481
- const [spatialDataType, spatialDataColumn] = geoColumn ? geoColumn.split(":") : ["geom"];
3482
- if (spatialDataType === "geom") {
3483
- const options = { ...globalOptions, spatialDataColumn };
3484
- if (type === "table") {
3485
- dataset.data = await (0, import_api_client2.vectorTableSource)({ ...options, columns, tableName: source });
3486
- } else if (type === "query") {
3487
- dataset.data = await (0, import_api_client2.vectorQuerySource)({
3488
- ...options,
3489
- columns,
3490
- sqlQuery: source,
3491
- queryParameters
3492
- });
3493
- }
3494
- } else if (spatialDataType === "h3") {
3495
- const options = { ...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn };
3496
- if (type === "table") {
3497
- dataset.data = await (0, import_api_client2.h3TableSource)({ ...options, tableName: source });
3498
- } else if (type === "query") {
3499
- dataset.data = await (0, import_api_client2.h3QuerySource)({ ...options, sqlQuery: source, queryParameters });
3500
- }
3501
- } else if (spatialDataType === "quadbin") {
3502
- const options = { ...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn };
3503
- if (type === "table") {
3504
- dataset.data = await (0, import_api_client2.quadbinTableSource)({ ...options, tableName: source });
3505
- } else if (type === "query") {
3506
- dataset.data = await (0, import_api_client2.quadbinQuerySource)({ ...options, sqlQuery: source, queryParameters });
3507
- }
3508
- }
3509
- }
3510
- let cacheChanged = true;
3511
- if (cache.value) {
3512
- cacheChanged = dataset.cache !== cache.value;
3513
- dataset.cache = cache.value;
3514
- }
3515
- return cacheChanged;
3516
- }
3517
- async function _fetchTilestats(attribute, dataset, context) {
3518
- const { connectionName, data, id: id5, source, type, queryParameters } = dataset;
3519
- const { apiBaseUrl } = context;
3520
- const errorContext = {
3521
- requestType: "Tile stats",
3522
- connection: connectionName,
3523
- type,
3524
- source
3525
- };
3526
- if (!("tilestats" in data)) {
3527
- throw new import_api_client2.CartoAPIError(new Error(`Invalid dataset for tilestats: ${id5}`), errorContext);
3528
- }
3529
- const baseUrl = (0, import_api_client2.buildStatsUrl)({ attribute, apiBaseUrl, ...dataset });
3530
- const client = new URLSearchParams(data.tiles[0]).get("client");
3531
- const headers = { Authorization: `Bearer ${context.accessToken}` };
3532
- const parameters = {};
3533
- if (client) {
3534
- parameters.client = client;
3535
- }
3536
- if (type === "query") {
3537
- parameters.q = source;
3538
- if (queryParameters) {
3539
- parameters.queryParameters = JSON.stringify(queryParameters);
3540
- }
3541
- }
3542
- const stats = await (0, import_api_client2.requestWithParameters)({
3543
- baseUrl,
3544
- headers,
3545
- parameters,
3546
- errorContext,
3547
- maxLengthURL: context.maxLengthURL
3548
- });
3549
- const { attributes } = data.tilestats.layers[0];
3550
- const index = attributes.findIndex((d) => d.attribute === attribute);
3551
- attributes[index] = stats;
3552
- return true;
3553
- }
3554
- async function fillInMapDatasets({ datasets }, context) {
3555
- const promises = datasets.map((dataset) => _fetchMapDataset(dataset, context));
3556
- return await Promise.all(promises);
3557
- }
3558
- async function fillInTileStats({ datasets, keplerMapConfig }, context) {
3559
- var _a;
3560
- const attributes = [];
3561
- const { layers } = keplerMapConfig.config.visState;
3562
- for (const layer of layers) {
3563
- for (const channel of Object.keys(layer.visualChannels)) {
3564
- const attribute = (_a = layer.visualChannels[channel]) == null ? void 0 : _a.name;
3565
- if (attribute) {
3566
- const dataset = datasets.find((d) => d.id === layer.config.dataId);
3567
- if (dataset && dataset.type !== "tileset" && dataset.data.tilestats) {
3568
- attributes.push({ attribute, dataset });
3569
- }
3570
- }
3571
- }
3572
- }
3573
- const filteredAttributes = [];
3574
- for (const a of attributes) {
3575
- if (!filteredAttributes.find(({ attribute, dataset }) => attribute === a.attribute && dataset === a.dataset)) {
3576
- filteredAttributes.push(a);
3577
- }
3578
- }
3579
- const promises = filteredAttributes.map(({ attribute, dataset }) => _fetchTilestats(attribute, dataset, context));
3580
- return await Promise.all(promises);
3581
- }
3582
- async function fetchMap({ accessToken, apiBaseUrl = import_api_client2.DEFAULT_API_BASE_URL, cartoMapId, clientId, headers, autoRefresh, onNewData, maxLengthURL }) {
3583
- assert(cartoMapId, 'Must define CARTO map id: fetchMap({cartoMapId: "XXXX-XXXX-XXXX"})');
3584
- if (accessToken) {
3585
- headers = { Authorization: `Bearer ${accessToken}`, ...headers };
3586
- }
3587
- if (autoRefresh || onNewData) {
3588
- assert(onNewData, "Must define `onNewData` when using autoRefresh");
3589
- assert(typeof onNewData === "function", "`onNewData` must be a function");
3590
- assert(typeof autoRefresh === "number" && autoRefresh > 0, "`autoRefresh` must be a positive number");
3591
- }
3592
- const baseUrl = (0, import_api_client2.buildPublicMapUrl)({ apiBaseUrl, cartoMapId });
3593
- const errorContext = { requestType: "Public map", mapId: cartoMapId };
3594
- const map = await (0, import_api_client2.requestWithParameters)({ baseUrl, headers, errorContext, maxLengthURL });
3595
- const context = {
3596
- accessToken: map.token || accessToken,
3597
- apiBaseUrl,
3598
- clientId,
3599
- headers,
3600
- maxLengthURL
3601
- };
3602
- let stopAutoRefresh;
3603
- if (autoRefresh) {
3604
- const intervalId = setInterval(async () => {
3605
- const changed = await fillInMapDatasets(map, {
3606
- ...context,
3607
- headers: {
3608
- ...headers,
3609
- "If-Modified-Since": new Date().toUTCString()
3610
- }
3611
- });
3612
- if (onNewData && changed.some((v) => v === true)) {
3613
- onNewData(parseMap(map));
3614
- }
3615
- }, autoRefresh * 1e3);
3616
- stopAutoRefresh = () => {
3617
- clearInterval(intervalId);
3618
- };
3619
- }
3620
- const geojsonLayers = map.keplerMapConfig.config.visState.layers.filter(({ type }) => type === "geojson" || type === "point");
3621
- const geojsonDatasetIds = geojsonLayers.map(({ config }) => config.dataId);
3622
- map.datasets.forEach((dataset) => {
3623
- if (geojsonDatasetIds.includes(dataset.id)) {
3624
- const { config } = geojsonLayers.find(({ config: config2 }) => config2.dataId === dataset.id);
3625
- dataset.format = "geojson";
3626
- if (!dataset.geoColumn && config.columns.geojson) {
3627
- dataset.geoColumn = config.columns.geojson;
3628
- }
3629
- }
3630
- });
3631
- const [basemap] = await Promise.all([
3632
- fetchBasemapProps({ config: map.keplerMapConfig.config, errorContext }),
3633
- // Mutates map.datasets so that dataset.data contains data
3634
- fillInMapDatasets(map, context)
3635
- ]);
3636
- await fillInTileStats(map, context);
3637
- const out = { ...parseMap(map), basemap, ...{ stopAutoRefresh } };
3638
- const textLayers = out.layers.filter((layer) => {
3639
- const pointType = layer.props.pointType || "";
3640
- return pointType.includes("text");
3641
- });
3642
- if (textLayers.length && window.FontFace && !document.fonts.check("12px Inter")) {
3643
- const font = new FontFace("Inter", "url(https://fonts.gstatic.com/s/inter/v12/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2)");
3644
- await font.load().then((f) => document.fonts.add(f));
3645
- }
3646
- return out;
3647
- }
3648
-
3649
2841
  // dist/index.js
3650
- var import_api_client3 = require("@carto/api-client");
3651
- var import_api_client4 = require("@carto/api-client");
3652
2842
  var CARTO_LAYERS = {
3653
2843
  ClusterTileLayer: cluster_tile_layer_default,
3654
2844
  H3TileLayer: h3_tile_layer_default,
@@ -3658,18 +2848,4 @@ var CARTO_LAYERS = {
3658
2848
  RasterTileLayer: raster_tile_layer_default,
3659
2849
  VectorTileLayer: vector_tile_layer_default
3660
2850
  };
3661
- var CARTO_SOURCES = {
3662
- boundaryQuerySource: import_api_client3.boundaryQuerySource,
3663
- boundaryTableSource: import_api_client3.boundaryTableSource,
3664
- h3QuerySource: import_api_client3.h3QuerySource,
3665
- h3TableSource: import_api_client3.h3TableSource,
3666
- h3TilesetSource: import_api_client3.h3TilesetSource,
3667
- rasterSource: import_api_client3.rasterSource,
3668
- quadbinQuerySource: import_api_client3.quadbinQuerySource,
3669
- quadbinTableSource: import_api_client3.quadbinTableSource,
3670
- quadbinTilesetSource: import_api_client3.quadbinTilesetSource,
3671
- vectorQuerySource: import_api_client3.vectorQuerySource,
3672
- vectorTableSource: import_api_client3.vectorTableSource,
3673
- vectorTilesetSource: import_api_client3.vectorTilesetSource
3674
- };
3675
2851
  //# sourceMappingURL=index.cjs.map