@carto/api-client 0.5.15-alpha.raster-5 → 0.5.16

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.
@@ -125,16 +125,9 @@ __export(src_exports, {
125
125
  WidgetSource: () => WidgetSource,
126
126
  WidgetTableSource: () => WidgetTableSource,
127
127
  WidgetTilesetSource: () => WidgetTilesetSource,
128
- _ErrorCode: () => ErrorCode,
129
- _applyLayerGroupFilters: () => applyLayerGroupFilters,
130
128
  _buildFeatureFilter: () => _buildFeatureFilter,
131
- _createVecExprEvaluator: () => createVecExprEvaluator,
132
129
  _domainFromValues: () => domainFromValues,
133
- _evaluateVecExpr: () => evaluateVecExpr,
134
130
  _getHexagonResolution: () => _getHexagonResolution,
135
- _getLog10ScaleSteps: () => getLog10ScaleSteps,
136
- _getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
137
- _validateVecExprSyntax: () => validateVecExprSyntax,
138
131
  addFilter: () => addFilter,
139
132
  aggregate: () => aggregate,
140
133
  aggregationFunctions: () => aggregationFunctions,
@@ -147,11 +140,9 @@ __export(src_exports, {
147
140
  buildStatsUrl: () => buildStatsUrl,
148
141
  calculateClusterRadius: () => calculateClusterRadius,
149
142
  calculateClusterTextFontSize: () => calculateClusterTextFontSize,
150
- calculateLayerScale: () => calculateLayerScale,
151
143
  clearDefaultRequestCache: () => clearDefaultRequestCache,
152
144
  clearFilters: () => clearFilters,
153
145
  configureSource: () => configureSource,
154
- createColorScale: () => createColorScale,
155
146
  createPolygonSpatialFilter: () => createPolygonSpatialFilter,
156
147
  createViewportSpatialFilter: () => createViewportSpatialFilter,
157
148
  fetchBasemapProps: () => fetchBasemapProps,
@@ -166,7 +157,6 @@ __export(src_exports, {
166
157
  getDefaultAggregationExpColumnAliasForLayerType: () => getDefaultAggregationExpColumnAliasForLayerType,
167
158
  getFilter: () => getFilter,
168
159
  getIconUrlAccessor: () => getIconUrlAccessor,
169
- getLayerDescriptor: () => getLayerDescriptor,
170
160
  getLayerProps: () => getLayerProps,
171
161
  getMaxMarkerSize: () => getMaxMarkerSize,
172
162
  getSizeAccessor: () => getSizeAccessor,
@@ -197,6 +187,8 @@ __export(src_exports, {
197
187
  tileFeatures: () => tileFeatures,
198
188
  tileFeaturesGeometries: () => tileFeaturesGeometries,
199
189
  tileFeaturesSpatialIndex: () => tileFeaturesSpatialIndex,
190
+ trajectoryQuerySource: () => trajectoryQuerySource,
191
+ trajectoryTableSource: () => trajectoryTableSource,
200
192
  transformToTileCoords: () => transformToTileCoords,
201
193
  vectorQuerySource: () => vectorQuerySource,
202
194
  vectorTableSource: () => vectorTableSource,
@@ -6428,7 +6420,8 @@ var AVAILABLE_MODELS = [
6428
6420
  "timeseries",
6429
6421
  "range",
6430
6422
  "scatterplot",
6431
- "table"
6423
+ "table",
6424
+ "aggregations"
6432
6425
  ];
6433
6426
  var { V3 } = ApiVersion;
6434
6427
  var REQUEST_GET_MAX_URL_LENGTH = 2048;
@@ -6871,6 +6864,30 @@ var WidgetRemoteSource = class extends WidgetSource {
6871
6864
  categories: res.metadata?.categories
6872
6865
  }));
6873
6866
  }
6867
+ async getAggregations(options) {
6868
+ const {
6869
+ signal,
6870
+ filters = this.props.filters,
6871
+ filterOwner,
6872
+ spatialFilter,
6873
+ spatialFiltersMode,
6874
+ aggregations
6875
+ } = options;
6876
+ return executeModel({
6877
+ model: "aggregations",
6878
+ source: {
6879
+ ...this.getModelSource(filters, filterOwner),
6880
+ spatialFiltersMode,
6881
+ spatialFilter
6882
+ },
6883
+ params: {
6884
+ aggregations
6885
+ },
6886
+ opts: { signal, headers: this.props.headers }
6887
+ }).then((res) => ({
6888
+ rows: res.rows.map((row) => normalizeObjectKeys(row))
6889
+ }));
6890
+ }
6874
6891
  /** @experimental */
6875
6892
  async getExtent(options = {}) {
6876
6893
  const { signal, filters = this.props.filters, filterOwner } = options;
@@ -7693,6 +7710,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7693
7710
  assertColumn(this._features, column);
7694
7711
  }
7695
7712
  const targetOperation = aggregationFunctions[operation2];
7713
+ assert2(targetOperation, `Unsupported aggregation operation: ${operation2}`);
7696
7714
  return {
7697
7715
  value: targetOperation(filteredFeatures, column, joinOperation)
7698
7716
  };
@@ -7891,6 +7909,39 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7891
7909
  max: aggregationFunctions.max(filteredFeatures, column)
7892
7910
  };
7893
7911
  }
7912
+ async getAggregations({
7913
+ aggregations,
7914
+ filters,
7915
+ filterOwner,
7916
+ spatialFilter
7917
+ }) {
7918
+ const filteredFeatures = this._getFilteredFeatures(
7919
+ spatialFilter,
7920
+ filters,
7921
+ filterOwner
7922
+ );
7923
+ if (!this._features.length) {
7924
+ return { rows: [] };
7925
+ }
7926
+ assert2(
7927
+ typeof aggregations !== "string",
7928
+ "Unsupported tileset SQL aggregation"
7929
+ );
7930
+ const result = {};
7931
+ const usedAliases = /* @__PURE__ */ new Set();
7932
+ for (const { column, operation: operation2, alias } of aggregations) {
7933
+ if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
7934
+ assertColumn(this._features, column);
7935
+ }
7936
+ const aliasKey = alias.toLowerCase();
7937
+ assert2(!usedAliases.has(aliasKey), `Duplicate alias: ${aliasKey}`);
7938
+ usedAliases.add(aliasKey);
7939
+ const targetOperation = aggregationFunctions[operation2];
7940
+ assert2(targetOperation, `Unsupported operation: ${operation2}`);
7941
+ result[alias] = targetOperation(filteredFeatures, column);
7942
+ }
7943
+ return { rows: [result] };
7944
+ }
7894
7945
  /** @experimental */
7895
7946
  async getExtent() {
7896
7947
  return Promise.reject(new Error("not implemented"));
@@ -8125,6 +8176,16 @@ var WidgetTilesetSource = class extends WidgetSource {
8125
8176
  }) {
8126
8177
  return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
8127
8178
  }
8179
+ async getAggregations({
8180
+ signal,
8181
+ ...options
8182
+ }) {
8183
+ return this._executeWorkerMethod(
8184
+ "getAggregations" /* GET_AGGREGATIONS */,
8185
+ [options],
8186
+ signal
8187
+ );
8188
+ }
8128
8189
  /** @experimental */
8129
8190
  async getExtent() {
8130
8191
  return Promise.resolve({
@@ -8491,6 +8552,104 @@ var vectorTilesetSource = async function(options) {
8491
8552
  );
8492
8553
  };
8493
8554
 
8555
+ // src/sources/trajectory-query-source.ts
8556
+ init_cjs_shims();
8557
+ var trajectoryQuerySource = async function(options) {
8558
+ const {
8559
+ columns,
8560
+ spatialDataColumn = DEFAULT_GEO_COLUMN,
8561
+ sqlQuery,
8562
+ tileResolution = DEFAULT_TILE_RESOLUTION,
8563
+ queryParameters,
8564
+ aggregationExp,
8565
+ trajectoryIdColumn,
8566
+ timestampColumn
8567
+ } = options;
8568
+ const spatialDataType = "trajectory";
8569
+ const urlParameters = {
8570
+ spatialDataColumn,
8571
+ spatialDataType,
8572
+ tileResolution: tileResolution.toString(),
8573
+ q: sqlQuery,
8574
+ trajectoryIdColumn,
8575
+ timestampColumn
8576
+ };
8577
+ if (columns) {
8578
+ urlParameters.columns = columns.join(",");
8579
+ }
8580
+ if (queryParameters) {
8581
+ urlParameters.queryParameters = queryParameters;
8582
+ }
8583
+ if (aggregationExp) {
8584
+ urlParameters.aggregationExp = aggregationExp;
8585
+ }
8586
+ const result = await baseSource(
8587
+ "query",
8588
+ options,
8589
+ urlParameters
8590
+ );
8591
+ const widgetSource = new WidgetQuerySource({
8592
+ ...options,
8593
+ // NOTE: Parameters with default values above must be explicitly passed here.
8594
+ spatialDataColumn,
8595
+ spatialDataType,
8596
+ tileResolution
8597
+ });
8598
+ const timestampRange = await widgetSource.getRange({ column: timestampColumn });
8599
+ return {
8600
+ ...result,
8601
+ widgetSource,
8602
+ timestampRange
8603
+ };
8604
+ };
8605
+
8606
+ // src/sources/trajectory-table-source.ts
8607
+ init_cjs_shims();
8608
+ var trajectoryTableSource = async function(options) {
8609
+ const {
8610
+ columns,
8611
+ spatialDataColumn = DEFAULT_GEO_COLUMN,
8612
+ tableName,
8613
+ tileResolution = DEFAULT_TILE_RESOLUTION,
8614
+ aggregationExp,
8615
+ trajectoryIdColumn,
8616
+ timestampColumn
8617
+ } = options;
8618
+ const spatialDataType = "trajectory";
8619
+ const urlParameters = {
8620
+ name: tableName,
8621
+ spatialDataColumn,
8622
+ spatialDataType,
8623
+ tileResolution: tileResolution.toString(),
8624
+ trajectoryIdColumn,
8625
+ timestampColumn
8626
+ };
8627
+ if (columns) {
8628
+ urlParameters.columns = columns.join(",");
8629
+ }
8630
+ if (aggregationExp) {
8631
+ urlParameters.aggregationExp = aggregationExp;
8632
+ }
8633
+ const result = await baseSource(
8634
+ "table",
8635
+ options,
8636
+ urlParameters
8637
+ );
8638
+ const widgetSource = new WidgetTableSource({
8639
+ ...options,
8640
+ // NOTE: Parameters with default values above must be explicitly passed here.
8641
+ spatialDataColumn,
8642
+ spatialDataType,
8643
+ tileResolution
8644
+ });
8645
+ const timestampRange = await widgetSource.getRange({ column: timestampColumn });
8646
+ return {
8647
+ ...result,
8648
+ widgetSource,
8649
+ timestampRange
8650
+ };
8651
+ };
8652
+
8494
8653
  // src/api/query.ts
8495
8654
  var query = async function(options) {
8496
8655
  const {
@@ -8649,253 +8808,11 @@ var basemap_styles_default = {
8649
8808
  DARK_MATTER_NOLABELS: getStyleUrl("dark-matter-nolabels")
8650
8809
  };
8651
8810
 
8652
- // src/fetch-map/raster-layer.ts
8811
+ // src/fetch-map/fetch-map.ts
8653
8812
  init_cjs_shims();
8654
8813
 
8655
- // src/fetch-map/vec-expr-evaluator.ts
8814
+ // src/fetch-map/parse-map.ts
8656
8815
  init_cjs_shims();
8657
- var import_jsep = __toESM(require("jsep"), 1);
8658
- function createVecExprEvaluator(expression) {
8659
- try {
8660
- const parsed = compile(expression);
8661
- const evalFun = (context) => evaluate(parsed, context);
8662
- evalFun.symbols = getSymbols(parsed);
8663
- return evalFun;
8664
- } catch {
8665
- return null;
8666
- }
8667
- }
8668
- function evaluateVecExpr(expression, context) {
8669
- try {
8670
- return createVecExprEvaluator(expression)?.(context);
8671
- } catch {
8672
- return null;
8673
- }
8674
- }
8675
- var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
8676
- ErrorCode2[ErrorCode2["InvalidSyntax"] = 0] = "InvalidSyntax";
8677
- ErrorCode2[ErrorCode2["UnknownIdentifier"] = 1] = "UnknownIdentifier";
8678
- return ErrorCode2;
8679
- })(ErrorCode || {});
8680
- function validateVecExprSyntax(expression, context) {
8681
- let parsed;
8682
- try {
8683
- parsed = compile(expression);
8684
- } catch (e) {
8685
- return {
8686
- valid: false,
8687
- errorCode: 0 /* InvalidSyntax */,
8688
- errorMessage: e && "message" in e ? String(e.message) : String(e)
8689
- };
8690
- }
8691
- return validate(parsed, context);
8692
- }
8693
- function createResultArray(typeTemplate, length2 = typeTemplate.length) {
8694
- return new Array(length2);
8695
- }
8696
- function isVecLike(a) {
8697
- return Array.isArray(a) || ArrayBuffer.isView(a);
8698
- }
8699
- var createBinopVec = (scalarBinOp) => (left, right) => {
8700
- const length2 = Math.min(left.length, right.length);
8701
- const r = createResultArray(left, length2);
8702
- for (let i = 0; i < length2; i++) {
8703
- r[i] = scalarBinOp(left[i], right[i]);
8704
- }
8705
- return r;
8706
- };
8707
- var createBinopVecNum = (scalarBinOp) => (left, right) => {
8708
- const length2 = left.length;
8709
- const r = createResultArray(left, length2);
8710
- for (let i = 0; i < length2; i++) {
8711
- r[i] = scalarBinOp(left[i], right);
8712
- }
8713
- return r;
8714
- };
8715
- var createBinopNumVec = (scalarBinOp) => (left, right) => {
8716
- const length2 = right.length;
8717
- const r = createResultArray(right, length2);
8718
- for (let i = 0; i < length2; i++) {
8719
- r[i] = scalarBinOp(left, right[i]);
8720
- }
8721
- return r;
8722
- };
8723
- var createUnopVec = (scalarUnop) => (a) => {
8724
- const length2 = a.length;
8725
- const r = createResultArray(a, length2);
8726
- for (let i = 0; i < length2; i++) {
8727
- r[i] = scalarUnop(a[i]);
8728
- }
8729
- return r;
8730
- };
8731
- function mapDictValues(dict, fun) {
8732
- return Object.keys(dict).reduce(
8733
- (acc, key) => {
8734
- acc[key] = fun(dict[key]);
8735
- return acc;
8736
- },
8737
- {}
8738
- );
8739
- }
8740
- var binopsNum = {
8741
- "||": (a, b) => a || b,
8742
- "&&": (a, b) => a && b,
8743
- "|": (a, b) => a | b,
8744
- "^": (a, b) => a ^ b,
8745
- "&": (a, b) => a & b,
8746
- "==": (a, b) => Number(a == b),
8747
- "!=": (a, b) => Number(a != b),
8748
- "===": (a, b) => Number(a === b),
8749
- "!==": (a, b) => Number(a !== b),
8750
- "<": (a, b) => Number(a < b),
8751
- ">": (a, b) => Number(a > b),
8752
- "<=": (a, b) => Number(a <= b),
8753
- ">=": (a, b) => Number(a >= b),
8754
- "<<": (a, b) => a << b,
8755
- ">>": (a, b) => a >> b,
8756
- ">>>": (a, b) => a >>> b,
8757
- "+": (a, b) => a + b,
8758
- "-": (a, b) => a - b,
8759
- "*": (a, b) => a * b,
8760
- "/": (a, b) => a / b,
8761
- "%": (a, b) => a % b
8762
- };
8763
- var unopsNum = {
8764
- "-": (a) => -a,
8765
- "+": (a) => +a,
8766
- "~": (a) => ~a,
8767
- "!": (a) => Number(!a)
8768
- };
8769
- var binopsVector = mapDictValues(binopsNum, createBinopVec);
8770
- var binopsNumVec = mapDictValues(binopsNum, createBinopNumVec);
8771
- var binopsVecNum = mapDictValues(binopsNum, createBinopVecNum);
8772
- var unopsVector = mapDictValues(unopsNum, createUnopVec);
8773
- function getBinop(operator, left, right) {
8774
- const isLeftVec = isVecLike(left);
8775
- const isRightVec = isVecLike(right);
8776
- if (isLeftVec && isRightVec) {
8777
- return binopsVector[operator];
8778
- } else if (isLeftVec) {
8779
- return binopsVecNum[operator];
8780
- } else if (isRightVec) {
8781
- return binopsNumVec[operator];
8782
- } else {
8783
- return binopsNum[operator];
8784
- }
8785
- }
8786
- function evaluate(_node, context) {
8787
- const node = _node;
8788
- switch (node.type) {
8789
- case "BinaryExpression": {
8790
- const left = evaluate(node.left, context);
8791
- const right = evaluate(node.right, context);
8792
- const binopFun = getBinop(node.operator, left, right);
8793
- return binopFun(left, right);
8794
- }
8795
- case "ConditionalExpression": {
8796
- const val = evaluate(node.test, context);
8797
- if (isVecLike(val)) {
8798
- const length2 = val.length;
8799
- const consequentVal = evaluate(node.consequent, context);
8800
- const alternateVal = evaluate(node.alternate, context);
8801
- const r = createResultArray(val);
8802
- for (let i = 0; i < length2; i++) {
8803
- const entryVal = val[i] ? consequentVal : alternateVal;
8804
- r[i] = isVecLike(entryVal) ? entryVal[i] ?? NaN : entryVal;
8805
- }
8806
- return r;
8807
- } else {
8808
- return val ? evaluate(node.consequent, context) : evaluate(node.alternate, context);
8809
- }
8810
- }
8811
- case "Identifier":
8812
- return context[node.name];
8813
- case "Literal":
8814
- return node.value;
8815
- case "UnaryExpression": {
8816
- const val = evaluate(node.argument, context);
8817
- const unopFun = isVecLike(val) ? unopsVector[node.operator] : unopsNum[node.operator];
8818
- return unopFun(val);
8819
- }
8820
- default:
8821
- return void 0;
8822
- }
8823
- }
8824
- var validResult = { valid: true };
8825
- function visit(_node, visitor) {
8826
- const node = _node;
8827
- visitor(node);
8828
- switch (node.type) {
8829
- case "BinaryExpression": {
8830
- visit(node.left, visitor);
8831
- visit(node.right, visitor);
8832
- break;
8833
- }
8834
- case "ConditionalExpression": {
8835
- visit(node.test, visitor);
8836
- visit(node.consequent, visitor);
8837
- visit(node.alternate, visitor);
8838
- break;
8839
- }
8840
- case "UnaryExpression": {
8841
- visit(node.argument, visitor);
8842
- break;
8843
- }
8844
- }
8845
- }
8846
- var supportedExpressionTypes = [
8847
- "BinaryExpression",
8848
- "UnaryExpression",
8849
- "ConditionalExpression",
8850
- "LogicalExpression",
8851
- "Identifier",
8852
- "Literal"
8853
- ];
8854
- function validate(_node, context) {
8855
- const node = _node;
8856
- const errors = [];
8857
- visit(node, (node2) => {
8858
- if (!supportedExpressionTypes.includes(node2.type)) {
8859
- errors.push({
8860
- valid: false,
8861
- errorCode: 0 /* InvalidSyntax */,
8862
- errorMessage: `Not allowed`
8863
- });
8864
- return;
8865
- }
8866
- if (node2.type === "Identifier") {
8867
- if (!Object.prototype.hasOwnProperty.call(context, node2.name)) {
8868
- return errors.push({
8869
- valid: false,
8870
- errorCode: 1 /* UnknownIdentifier */,
8871
- errorMessage: `"${node2.name}" not found`
8872
- });
8873
- }
8874
- }
8875
- if (node2.type === "Literal") {
8876
- if (typeof node2.value !== "number") {
8877
- return errors.push({
8878
- valid: false,
8879
- errorCode: 0 /* InvalidSyntax */,
8880
- errorMessage: `Only number literals are supported`
8881
- });
8882
- }
8883
- }
8884
- });
8885
- return errors.length ? errors[0] : validResult;
8886
- }
8887
- function getSymbols(node) {
8888
- const symbols = /* @__PURE__ */ new Set();
8889
- visit(node, (node2) => {
8890
- if (node2.type === "Identifier") {
8891
- symbols.add(node2.name);
8892
- }
8893
- });
8894
- return Array.from(symbols);
8895
- }
8896
- function compile(expression) {
8897
- return (0, import_jsep.default)(expression);
8898
- }
8899
8816
 
8900
8817
  // src/fetch-map/layer-map.ts
8901
8818
  init_cjs_shims();
@@ -9494,37 +9411,6 @@ function formatDate(value) {
9494
9411
  function formatTimestamp(value) {
9495
9412
  return String(Math.floor(new Date(value).getTime() / 1e3));
9496
9413
  }
9497
- function roundedPow10(exp) {
9498
- const raw = Math.pow(10, exp);
9499
- if (exp < 0) {
9500
- const shift = Math.pow(10, -exp);
9501
- return Math.round(raw * shift) / shift;
9502
- }
9503
- return raw;
9504
- }
9505
- function getLog10ScaleSteps({
9506
- min: min2,
9507
- max: max2,
9508
- steps
9509
- }) {
9510
- if (min2 === 0) {
9511
- if (max2 === Infinity) {
9512
- return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9513
- }
9514
- const maxLog = Math.log10(max2);
9515
- const endExponent = Math.ceil(maxLog);
9516
- const startExponent = endExponent - steps + 1;
9517
- return [...Array(steps - 1)].map(
9518
- (_v, i) => roundedPow10(startExponent + i)
9519
- );
9520
- } else {
9521
- const minLog = Math.log10(min2);
9522
- const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9523
- return [...Array(steps - 1)].map(
9524
- (_v, i) => roundedPow10(startExponent + i)
9525
- );
9526
- }
9527
- }
9528
9414
 
9529
9415
  // src/fetch-map/layer-map.ts
9530
9416
  var SCALE_FUNCS = {
@@ -9541,19 +9427,7 @@ var SCALE_FUNCS = {
9541
9427
  function identity2(v2) {
9542
9428
  return v2;
9543
9429
  }
9544
- var hexToRGB = (c) => {
9545
- const { r, g, b } = rgb(c);
9546
- return [r, g, b];
9547
- };
9548
- var rgbToHex = (c) => {
9549
- const [r, g, b] = c;
9550
- const rStr = r.toString(16).padStart(2, "0");
9551
- const gStr = g.toString(16).padStart(2, "0");
9552
- const bStr = b.toString(16).padStart(2, "0");
9553
- return `#${rStr}${gStr}${bStr}`.toUpperCase();
9554
- };
9555
9430
  var UNKNOWN_COLOR = "#868d91";
9556
- var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9557
9431
  var OPACITY_MAP = {
9558
9432
  getFillColor: "opacity",
9559
9433
  getLineColor: "strokeOpacity",
@@ -9586,12 +9460,6 @@ var sharedPropMap = {
9586
9460
  wireframe: "wireframe"
9587
9461
  }
9588
9462
  };
9589
- var rasterPropsMap = {
9590
- isVisible: "visible",
9591
- visConfig: {
9592
- opacity: "opacity"
9593
- }
9594
- };
9595
9463
  var customMarkersPropsMap = {
9596
9464
  color: "getIconColor",
9597
9465
  visConfig: {
@@ -9635,12 +9503,6 @@ function getLayerProps(type, config2, dataset) {
9635
9503
  `Outdated layer type: ${type}. Please open map in CARTO Builder to automatically migrate.`
9636
9504
  );
9637
9505
  }
9638
- if (type === "raster") {
9639
- return {
9640
- propMap: rasterPropsMap,
9641
- defaultProps: {}
9642
- };
9643
- }
9644
9506
  let basePropMap = sharedPropMap;
9645
9507
  if (config2.visConfig?.customMarkers) {
9646
9508
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -9661,19 +9523,16 @@ function getLayerProps(type, config2, dataset) {
9661
9523
  }
9662
9524
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9663
9525
  if (scaleType === "ordinal" || scaleType === "point") {
9664
- if (!attribute.categories) {
9665
- return [0, 1];
9666
- }
9667
9526
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9668
9527
  }
9669
9528
  if (scaleType === "quantile" && attribute.quantiles) {
9670
- return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9529
+ return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9671
9530
  }
9672
9531
  let { min: min2 } = attribute;
9673
9532
  if (scaleType === "log" && min2 === 0) {
9674
9533
  min2 = 1e-5;
9675
9534
  }
9676
- return [min2 ?? 0, attribute.max ?? 1];
9535
+ return [min2, attribute.max];
9677
9536
  }
9678
9537
  function domainFromValues(values, scaleType) {
9679
9538
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9694,14 +9553,12 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9694
9553
  if (data.tilestats) {
9695
9554
  const { attributes } = data.tilestats.layers[0];
9696
9555
  const attribute = attributes.find((a) => a.attribute === name);
9697
- if (attribute) {
9698
- return domainFromAttribute(attribute, scaleType, scaleLength);
9699
- }
9556
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9700
9557
  }
9701
9558
  return [0, 1];
9702
9559
  }
9703
9560
  function normalizeAccessor(accessor, data) {
9704
- if (data.features || data.tilestats || data.raster_metadata) {
9561
+ if (data.features || data.tilestats) {
9705
9562
  return (object, info) => {
9706
9563
  if (object) {
9707
9564
  return accessor(object.properties || object.__source.object.properties);
@@ -9734,75 +9591,46 @@ function findAccessorKey(keys, properties) {
9734
9591
  return keys;
9735
9592
  }
9736
9593
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9737
- const { scale: scale2, domain } = calculateLayerScale(
9594
+ const scale2 = calculateLayerScale(
9738
9595
  colorColumn || name,
9739
- colorColumn ? "identity" : scaleType,
9596
+ scaleType,
9740
9597
  range,
9741
9598
  data
9742
9599
  );
9743
9600
  const alpha = opacityToAlpha(opacity);
9744
- let accessorKeys = getAccessorKeys(colorColumn || name, aggregation);
9601
+ let accessorKeys = getAccessorKeys(name, aggregation);
9745
9602
  const accessor = (properties) => {
9746
9603
  if (!(accessorKeys[0] in properties)) {
9747
9604
  accessorKeys = findAccessorKey(accessorKeys, properties);
9748
9605
  }
9749
9606
  const propertyValue = properties[accessorKeys[0]];
9750
- const scaled = scale2(propertyValue);
9751
- const rgb2 = typeof scaled === "string" ? hexToRGB(scaled) : scaled;
9752
- return [...rgb2, propertyValue === null ? 0 : alpha];
9753
- };
9754
- return {
9755
- accessor: normalizeAccessor(accessor, data),
9756
- scaleDomain: scale2.domain(),
9757
- domain,
9758
- range: (scale2.range() || []).map(rgbToHex)
9607
+ const { r, g, b } = rgb(scale2(propertyValue));
9608
+ return [r, g, b, propertyValue === null ? 0 : alpha];
9759
9609
  };
9610
+ return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9760
9611
  }
9761
9612
  function calculateLayerScale(name, scaleType, range, data) {
9613
+ const scale2 = SCALE_FUNCS[scaleType]();
9762
9614
  let domain = [];
9763
- let scaleDomain;
9764
9615
  let scaleColor = [];
9765
- const { colors } = range;
9766
- if (scaleType === "custom") {
9767
- domain = calculateDomain(data, name, scaleType, colors.length);
9768
- const [min2, max2] = domain;
9769
- if (range.uiCustomScaleType === "logarithmic") {
9770
- scaleDomain = getLog10ScaleSteps({
9771
- min: min2,
9772
- max: max2,
9773
- steps: colors.length
9774
- });
9775
- scaleColor = colors;
9776
- } else if (range.colorMap) {
9777
- const { colorMap } = range;
9778
- scaleDomain = [];
9616
+ if (scaleType !== "identity") {
9617
+ const { colorMap, colors } = range;
9618
+ if (Array.isArray(colorMap)) {
9779
9619
  colorMap.forEach(([value, color2]) => {
9780
- scaleDomain.push(Number(value));
9620
+ domain.push(value);
9781
9621
  scaleColor.push(color2);
9782
9622
  });
9623
+ } else {
9624
+ domain = calculateDomain(data, name, scaleType, colors.length);
9625
+ scaleColor = colors;
9783
9626
  }
9784
- } else if (scaleType !== "identity") {
9785
- domain = calculateDomain(data, name, scaleType, colors.length);
9786
- scaleColor = colors;
9787
9627
  if (scaleType === "ordinal") {
9788
9628
  domain = domain.slice(0, scaleColor.length);
9789
9629
  }
9790
9630
  }
9791
- return {
9792
- scale: createColorScale(
9793
- scaleType,
9794
- scaleDomain || domain,
9795
- scaleColor.map(hexToRGB),
9796
- UNKNOWN_COLOR_RGB
9797
- ),
9798
- domain
9799
- };
9800
- }
9801
- function createColorScale(scaleType, domain, range, unknown) {
9802
- const scale2 = SCALE_FUNCS[scaleType]();
9803
9631
  scale2.domain(domain);
9804
- scale2.range(range);
9805
- scale2.unknown(unknown);
9632
+ scale2.range(scaleColor);
9633
+ scale2.unknown(UNKNOWN_COLOR);
9806
9634
  return scale2;
9807
9635
  }
9808
9636
  var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
@@ -9852,13 +9680,9 @@ function negateAccessor(accessor) {
9852
9680
  }
9853
9681
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9854
9682
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9855
- let domain = [];
9856
- if (scaleType && range) {
9683
+ if (scaleType) {
9857
9684
  if (aggregation !== AggregationTypes.Count) {
9858
- domain = calculateDomain(data, name, scaleType);
9859
- scale2.domain(domain);
9860
- } else {
9861
- domain = scale2.domain();
9685
+ scale2.domain(calculateDomain(data, name, scaleType));
9862
9686
  }
9863
9687
  scale2.range(range);
9864
9688
  }
@@ -9870,12 +9694,7 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9870
9694
  const propertyValue = properties[accessorKeys[0]];
9871
9695
  return scale2(propertyValue);
9872
9696
  };
9873
- return {
9874
- accessor: normalizeAccessor(accessor, data),
9875
- domain,
9876
- scaleDomain: domain,
9877
- range
9878
- };
9697
+ return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9879
9698
  }
9880
9699
  var FORMATS = {
9881
9700
  date: formatDate,
@@ -9926,424 +9745,13 @@ function calculateClusterTextFontSize(radius) {
9926
9745
  return 11;
9927
9746
  }
9928
9747
 
9929
- // src/fetch-map/raster-layer.ts
9930
- var UNKNOWN_COLOR2 = [134, 141, 145];
9931
- var RASTER_COLOR_BANDS = ["red", "green", "blue"];
9932
- function getHasDataPredicate(noData) {
9933
- if (noData === "nan") {
9934
- return (v2) => !isNaN(v2);
9935
- }
9936
- if (typeof noData === "string") {
9937
- noData = parseFloat(noData);
9938
- }
9939
- if (typeof noData === "number") {
9940
- return (v2) => v2 !== noData && !isNaN(v2);
9941
- }
9942
- return () => true;
9943
- }
9944
- function createRasterColumnLayerDataTransform(transform) {
9945
- return (data) => {
9946
- if (!data || !("data" in data) || !data?.data?.cells?.numericProps) {
9947
- return data;
9948
- }
9949
- return transform(data);
9950
- };
9951
- }
9952
- function createEvaluationContext(numericProps, noData) {
9953
- const hasData = getHasDataPredicate(noData);
9954
- const bands = Object.entries(numericProps).map(([bandName, { value }]) => ({
9955
- bandName,
9956
- values: value,
9957
- copied: false
9958
- }));
9959
- const length2 = bands[0].values.length;
9960
- for (let i = 0; i < length2; i++) {
9961
- let hasSomeData = false;
9962
- for (let j = 0; j < bands.length; j++) {
9963
- hasSomeData = hasSomeData || hasData(bands[j].values[i]);
9964
- }
9965
- if (!hasSomeData) {
9966
- for (let j = 0; j < bands.length; j++) {
9967
- if (!bands[j].copied) {
9968
- bands[j].copied = true;
9969
- bands[j].values = Array.from(bands[j].values);
9970
- }
9971
- bands[j].values[i] = NaN;
9972
- }
9973
- }
9974
- }
9975
- const context = bands.reduce(
9976
- (agg, { bandName, values }) => {
9977
- agg[bandName] = values;
9978
- return agg;
9979
- },
9980
- {}
9981
- );
9982
- return context;
9983
- }
9984
- function createExprDataTransform({
9985
- colorBand,
9986
- rasterMetadata,
9987
- usedSymbols
9988
- }) {
9989
- if (!colorBand || !colorBand.type || colorBand.type === "none") {
9990
- return void 0;
9991
- }
9992
- const expr = colorBand?.type === "expression" ? colorBand.value : void 0;
9993
- const vecExprEvaluator = expr ? createVecExprEvaluator(expr) : void 0;
9994
- const dataTransform = createRasterColumnLayerDataTransform(
9995
- (dataWrapped) => {
9996
- const data = dataWrapped.data;
9997
- if (expr) {
9998
- const cachedResult = dataWrapped.customExpressionResults?.[expr];
9999
- if (cachedResult) {
10000
- return dataWrapped;
10001
- }
10002
- }
10003
- let context = dataWrapped.expressionEvalContext;
10004
- if (!context) {
10005
- const usedNumericProps = usedSymbols.reduce(
10006
- (acc, symbol) => {
10007
- acc[symbol] = data.cells.numericProps[symbol];
10008
- return acc;
10009
- },
10010
- {}
10011
- );
10012
- context = createEvaluationContext(
10013
- usedNumericProps,
10014
- rasterMetadata.nodata
10015
- );
10016
- dataWrapped = {
10017
- ...dataWrapped,
10018
- expressionEvalContext: context
10019
- };
10020
- }
10021
- if (!vecExprEvaluator || !expr) return dataWrapped;
10022
- const evalResult = vecExprEvaluator(context);
10023
- return {
10024
- ...dataWrapped,
10025
- customExpressionResults: {
10026
- ...dataWrapped.customExpressionResults,
10027
- [expr]: evalResult
10028
- }
10029
- };
10030
- }
10031
- );
10032
- return dataTransform;
10033
- }
10034
- function combineDataTransforms(dataTransforms) {
10035
- const actualTransforms = dataTransforms.filter((v2) => v2);
10036
- if (actualTransforms.length === 0) return void 0;
10037
- if (actualTransforms.length === 1) return actualTransforms[0];
10038
- return (data) => actualTransforms.reduce(
10039
- (aggData, transformFun) => transformFun(aggData),
10040
- data
10041
- );
10042
- }
10043
- function createRgbToColorBufferDataTransform({
10044
- bandDefs,
10045
- attribute
10046
- }) {
10047
- return createRasterColumnLayerDataTransform(
10048
- (dataWrapped) => {
10049
- const length2 = dataWrapped.length;
10050
- const getBandBufferOrValue = (colorBand) => {
10051
- if (colorBand?.type === "expression") {
10052
- return dataWrapped.customExpressionResults?.[colorBand.value];
10053
- }
10054
- if (colorBand?.type === "band") {
10055
- return dataWrapped.expressionEvalContext?.[colorBand.value];
10056
- }
10057
- return 0;
10058
- };
10059
- const red = getBandBufferOrValue(bandDefs.red);
10060
- const green = getBandBufferOrValue(bandDefs.green);
10061
- const blue = getBandBufferOrValue(bandDefs.blue);
10062
- const colorBuffer = new Uint8Array(length2 * 4);
10063
- for (let inputIndex = 0, outputIndex = 0; inputIndex < length2; inputIndex++, outputIndex += 4) {
10064
- const redRaw = typeof red === "number" ? red : red ? red[inputIndex] : NaN;
10065
- const greenRaw = typeof green === "number" ? green : green ? green[inputIndex] : NaN;
10066
- const blueRaw = typeof blue === "number" ? blue : blue ? blue[inputIndex] : NaN;
10067
- if (isNaN(redRaw) && isNaN(greenRaw) && isNaN(blueRaw)) {
10068
- bufferSetRgba(colorBuffer, outputIndex, 0, 0, 0, 0);
10069
- } else {
10070
- bufferSetRgba(
10071
- colorBuffer,
10072
- outputIndex,
10073
- redRaw,
10074
- greenRaw,
10075
- blueRaw,
10076
- 255
10077
- );
10078
- }
10079
- }
10080
- dataWrapped.customExpressionResults = void 0;
10081
- dataWrapped.expressionEvalContext = void 0;
10082
- return {
10083
- ...dataWrapped,
10084
- attributes: {
10085
- [attribute]: colorBuffer
10086
- }
10087
- };
10088
- }
10089
- );
10090
- }
10091
- function getUsedSymbols(colorBands) {
10092
- return Array.from(
10093
- colorBands.reduce((symbols, band) => {
10094
- if (band.type === "expression") {
10095
- const expressionSymbols = createVecExprEvaluator(band.value)?.symbols || [];
10096
- expressionSymbols.forEach((symbol) => symbols.add(symbol));
10097
- }
10098
- if (band.type === "band") {
10099
- symbols.add(band.value);
10100
- }
10101
- return symbols;
10102
- }, /* @__PURE__ */ new Set())
10103
- );
10104
- }
10105
- function getRasterTileLayerStylePropsRgb({
10106
- layerConfig,
10107
- rasterMetadata,
10108
- visualChannels
10109
- }) {
10110
- const { visConfig } = layerConfig;
10111
- const { colorBands } = visConfig;
10112
- const bandDefs = {
10113
- red: colorBands?.find((band) => band.band === "red"),
10114
- green: colorBands?.find((band) => band.band === "green"),
10115
- blue: colorBands?.find((band) => band.band === "blue")
10116
- };
10117
- const rgbToInstanceFillColorsDataTransform = createRgbToColorBufferDataTransform({
10118
- bandDefs,
10119
- attribute: "instanceFillColors"
10120
- });
10121
- const usedSymbols = colorBands ? getUsedSymbols(colorBands) : [];
10122
- const bandTransforms = RASTER_COLOR_BANDS.map(
10123
- (band) => createExprDataTransform({
10124
- colorBand: bandDefs[band],
10125
- rasterMetadata,
10126
- usedSymbols
10127
- })
10128
- );
10129
- const combinedDataTransform = combineDataTransforms([
10130
- ...bandTransforms,
10131
- rgbToInstanceFillColorsDataTransform
10132
- ]);
10133
- return {
10134
- dataTransform: combinedDataTransform,
10135
- updateTriggers: getRasterTileLayerUpdateTriggers({
10136
- layerConfig,
10137
- visualChannels
10138
- })
10139
- };
10140
- }
10141
- function createBandColorScaleDataTransform({
10142
- bandName,
10143
- scaleFun,
10144
- nodata,
10145
- attribute
10146
- }) {
10147
- const hasData = getHasDataPredicate(nodata);
10148
- return createRasterColumnLayerDataTransform(
10149
- (dataWrapped) => {
10150
- const length2 = dataWrapped.length;
10151
- const bandBuffer = dataWrapped.data.cells.numericProps[bandName].value;
10152
- const colorBuffer = new Uint8Array(length2 * 4);
10153
- for (let i = 0; i < length2; i++) {
10154
- const rawValue = bandBuffer[i];
10155
- if (!hasData(rawValue)) {
10156
- bufferSetRgba(colorBuffer, i * 4, 0, 0, 0, 0);
10157
- } else {
10158
- const colorRgb = scaleFun(rawValue);
10159
- bufferSetRgba(
10160
- colorBuffer,
10161
- i * 4,
10162
- colorRgb[0],
10163
- colorRgb[1],
10164
- colorRgb[2],
10165
- 255
10166
- );
10167
- }
10168
- }
10169
- return {
10170
- ...dataWrapped,
10171
- attributes: {
10172
- [attribute]: colorBuffer
10173
- }
10174
- };
10175
- }
10176
- );
10177
- }
10178
- function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10179
- if (scaleType === "ordinal") {
10180
- return colorRange.colorMap?.map(([value]) => value) || [];
10181
- }
10182
- if (scaleType === "custom") {
10183
- if (colorRange.uiCustomScaleType === "logarithmic") {
10184
- return getLog10ScaleSteps({
10185
- min: band.stats.min,
10186
- max: band.stats.max,
10187
- steps: colorRange.colors.length
10188
- });
10189
- } else {
10190
- return colorRange.colorMap?.map(([value]) => value) || [];
10191
- }
10192
- }
10193
- const scaleLength = colorRange.colors.length;
10194
- if (scaleType === "quantile") {
10195
- const quantiles = band.stats.quantiles?.[scaleLength];
10196
- if (!quantiles) {
10197
- return [0, 1];
10198
- }
10199
- return [band.stats.min, ...quantiles, band.stats.max];
10200
- }
10201
- return [band.stats.min, band.stats.max];
10202
- }
10203
- function getRasterTileLayerStylePropsScaledBand({
10204
- layerConfig,
10205
- rasterMetadata,
10206
- visualChannels
10207
- }) {
10208
- const { visConfig } = layerConfig;
10209
- const { colorField } = visualChannels;
10210
- const { rasterStyleType } = visConfig;
10211
- const colorRange = rasterStyleType === "ColorRange" ? visConfig.colorRange : visConfig.uniqueValuesColorRange;
10212
- const scaleType = rasterStyleType === "ColorRange" ? visualChannels.colorScale : "ordinal";
10213
- const bandInfo = rasterMetadata.bands.find(
10214
- (band) => band.name === colorField?.name
10215
- );
10216
- if (!colorField?.name || !scaleType || !colorRange || !bandInfo) {
10217
- return {};
10218
- }
10219
- const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
10220
- const scaleFun = createColorScale(
10221
- scaleType,
10222
- domain,
10223
- colorRange.colors.map(hexToRGB2),
10224
- UNKNOWN_COLOR2
10225
- );
10226
- const bandColorScaleDataTransform = createBandColorScaleDataTransform({
10227
- bandName: bandInfo.name,
10228
- scaleFun,
10229
- nodata: bandInfo?.nodata ?? rasterMetadata.nodata,
10230
- attribute: "instanceFillColors"
10231
- });
10232
- return {
10233
- dataTransform: bandColorScaleDataTransform,
10234
- updateTriggers: getRasterTileLayerUpdateTriggers({
10235
- layerConfig,
10236
- visualChannels
10237
- })
10238
- };
10239
- }
10240
- function getRasterTileLayerStyleProps({
10241
- layerConfig,
10242
- visualChannels,
10243
- rasterMetadata
10244
- }) {
10245
- const { visConfig } = layerConfig;
10246
- const { rasterStyleType } = visConfig;
10247
- if (rasterStyleType === "Rgb") {
10248
- return getRasterTileLayerStylePropsRgb({
10249
- layerConfig,
10250
- rasterMetadata,
10251
- visualChannels
10252
- });
10253
- } else {
10254
- return getRasterTileLayerStylePropsScaledBand({
10255
- layerConfig,
10256
- rasterMetadata,
10257
- visualChannels
10258
- });
10259
- }
10260
- }
10261
- function getRasterTileLayerUpdateTriggers({
10262
- layerConfig,
10263
- visualChannels
10264
- }) {
10265
- const { visConfig } = layerConfig;
10266
- const { rasterStyleType } = visConfig;
10267
- const getFillColorUpdateTriggers = {
10268
- rasterStyleType
10269
- };
10270
- if (rasterStyleType === "ColorRange") {
10271
- getFillColorUpdateTriggers.colorRange = visConfig.colorRange?.colors;
10272
- getFillColorUpdateTriggers.colorMap = visConfig.colorRange?.colorMap;
10273
- getFillColorUpdateTriggers.colorScale = visualChannels.colorScale;
10274
- getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10275
- } else if (rasterStyleType === "UniqueValues") {
10276
- getFillColorUpdateTriggers.colorMap = visConfig.uniqueValuesColorRange?.colorMap;
10277
- getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10278
- } else if (rasterStyleType === "Rgb") {
10279
- getFillColorUpdateTriggers.colorBands = visConfig.colorBands;
10280
- }
10281
- return {
10282
- getFillColor: getFillColorUpdateTriggers
10283
- };
10284
- }
10285
- function bufferSetRgba(target, index, r, g, b, a) {
10286
- target[index + 0] = r;
10287
- target[index + 1] = g;
10288
- target[index + 2] = b;
10289
- target[index + 3] = a;
10290
- }
10291
- function hexToRGB2(hexColor) {
10292
- const r = parseInt(hexColor.slice(1, 3), 16);
10293
- const g = parseInt(hexColor.slice(3, 5), 16);
10294
- const b = parseInt(hexColor.slice(5, 7), 16);
10295
- return [r, g, b];
10296
- }
10297
-
10298
- // src/fetch-map/fetch-map.ts
10299
- init_cjs_shims();
10300
-
10301
9748
  // src/fetch-map/parse-map.ts
10302
- init_cjs_shims();
10303
- function getLayerDescriptor({
10304
- mapConfig,
10305
- layer,
10306
- dataset
10307
- }) {
10308
- const { filters, visState } = mapConfig;
10309
- const { layerBlending, interactionConfig } = visState;
10310
- const { id, type, config: config2, visualChannels } = layer;
10311
- const { data, id: datasetId } = dataset;
10312
- const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config2, dataset);
10313
- const styleProps = createStyleProps(config2, propMap);
10314
- const { channelProps, scales } = createChannelProps(
10315
- id,
10316
- type,
10317
- config2,
10318
- visualChannels,
10319
- data,
10320
- dataset
10321
- );
10322
- const layerDescriptor = {
10323
- type,
10324
- filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[datasetId],
10325
- props: {
10326
- id,
10327
- data,
10328
- ...defaultProps2,
10329
- ...createInteractionProps(interactionConfig),
10330
- ...styleProps,
10331
- ...channelProps,
10332
- ...createParametersProp(layerBlending, styleProps.parameters || {}),
10333
- // Must come after style
10334
- ...createLoadOptions(data.accessToken)
10335
- },
10336
- scales
10337
- };
10338
- return layerDescriptor;
10339
- }
10340
9749
  function parseMap(json) {
10341
9750
  const { keplerMapConfig, datasets, token } = json;
10342
9751
  assert2(keplerMapConfig.version === "v1", "Only support Kepler v1");
10343
- const mapConfig = keplerMapConfig.config;
10344
- const { mapState, mapStyle, popupSettings, legendSettings, visState } = mapConfig;
10345
- const { layers } = visState;
10346
- const layersReverse = [...layers].reverse();
9752
+ const config2 = keplerMapConfig.config;
9753
+ const { filters, mapState, mapStyle, popupSettings, legendSettings } = config2;
9754
+ const { layers, layerBlending, interactionConfig } = config2.visState;
10347
9755
  return {
10348
9756
  id: json.id,
10349
9757
  title: json.title,
@@ -10356,19 +9764,45 @@ function parseMap(json) {
10356
9764
  popupSettings,
10357
9765
  legendSettings,
10358
9766
  token,
10359
- layers: layersReverse.map((layer) => {
9767
+ layers: layers.reverse().map(({ id, type, config: config3, visualChannels }) => {
10360
9768
  try {
10361
- const { dataId } = layer.config;
9769
+ const { dataId } = config3;
10362
9770
  const dataset = datasets.find(
10363
9771
  (d) => d.id === dataId
10364
9772
  );
10365
9773
  assert2(dataset, `No dataset matching dataId: ${dataId}`);
10366
- const layerDescriptor = getLayerDescriptor({
10367
- mapConfig,
10368
- layer,
9774
+ const { data } = dataset;
9775
+ assert2(data, `No data loaded for dataId: ${dataId}`);
9776
+ const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config3, dataset);
9777
+ const styleProps = createStyleProps(config3, propMap);
9778
+ const { channelProps, scales } = createChannelProps(
9779
+ id,
9780
+ type,
9781
+ config3,
9782
+ visualChannels,
9783
+ data,
10369
9784
  dataset
10370
- });
10371
- return layerDescriptor;
9785
+ );
9786
+ const layer = {
9787
+ type,
9788
+ filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[dataId],
9789
+ props: {
9790
+ id,
9791
+ data,
9792
+ ...defaultProps2,
9793
+ ...createInteractionProps(interactionConfig),
9794
+ ...styleProps,
9795
+ ...channelProps,
9796
+ ...createParametersProp(
9797
+ layerBlending,
9798
+ styleProps.parameters || {}
9799
+ ),
9800
+ // Must come after style
9801
+ ...createLoadOptions(token)
9802
+ },
9803
+ scales
9804
+ };
9805
+ return layer;
10372
9806
  } catch (e) {
10373
9807
  console.error(e.message);
10374
9808
  return void 0;
@@ -10433,63 +9867,43 @@ function createStyleProps(config2, mapping) {
10433
9867
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
10434
9868
  return result;
10435
9869
  }
9870
+ function domainAndRangeFromScale(scale2) {
9871
+ return {
9872
+ domain: scale2.domain(),
9873
+ range: scale2.range()
9874
+ };
9875
+ }
10436
9876
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
10437
- if (layerType === "raster") {
10438
- const rasterMetadata = data.raster_metadata;
10439
- if (!rasterMetadata) {
10440
- return {
10441
- channelProps: {},
10442
- scales: {}
10443
- };
10444
- }
10445
- const rasterStyleType = config2.visConfig.rasterStyleType;
10446
- if (rasterStyleType === "Rgb") {
10447
- return {
10448
- channelProps: getRasterTileLayerStylePropsRgb({
10449
- layerConfig: config2,
10450
- rasterMetadata,
10451
- visualChannels
10452
- }),
10453
- scales: {}
10454
- // TODO
10455
- };
10456
- } else {
10457
- return {
10458
- channelProps: getRasterTileLayerStylePropsScaledBand({
10459
- layerConfig: config2,
10460
- visualChannels,
10461
- rasterMetadata
10462
- }),
10463
- scales: {
10464
- // TODO
10465
- }
10466
- };
10467
- }
10468
- }
9877
+ const {
9878
+ colorField,
9879
+ colorScale,
9880
+ radiusField,
9881
+ radiusScale,
9882
+ strokeColorField,
9883
+ strokeColorScale,
9884
+ weightField
9885
+ } = visualChannels;
9886
+ const { heightField, heightScale } = visualChannels;
10469
9887
  const { textLabel, visConfig } = config2;
10470
9888
  const result = {};
10471
- const updateTriggers = {};
10472
9889
  const scales = {};
10473
- {
10474
- const { colorField, colorScale } = visualChannels;
10475
- const { colorRange, colorAggregation } = visConfig;
10476
- if (colorField && colorScale && colorRange) {
10477
- const { accessor, ...scaleProps } = getColorAccessor(
10478
- colorField,
10479
- colorScale,
10480
- { aggregation: colorAggregation, range: colorRange },
10481
- visConfig.opacity,
10482
- data
10483
- );
10484
- result.getFillColor = accessor;
10485
- scales.fillColor = updateTriggers.getFillColor = {
10486
- field: colorField,
10487
- type: colorScale,
10488
- ...scaleProps
10489
- };
10490
- } else {
10491
- scales.fillColor = {};
10492
- }
9890
+ if (colorField) {
9891
+ const { colorAggregation: aggregation, colorRange: range } = visConfig;
9892
+ const { accessor, scale: scale2 } = getColorAccessor(
9893
+ colorField,
9894
+ colorScale,
9895
+ { aggregation, range },
9896
+ visConfig.opacity,
9897
+ data
9898
+ );
9899
+ result.getFillColor = accessor;
9900
+ scales.fillColor = {
9901
+ field: colorField,
9902
+ type: colorScale,
9903
+ ...domainAndRangeFromScale(scale2)
9904
+ };
9905
+ } else if (visConfig.filled) {
9906
+ scales.fillColor = {};
10493
9907
  }
10494
9908
  if (layerType === "clusterTile") {
10495
9909
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -10502,7 +9916,6 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10502
9916
  result.getWeight = (d) => {
10503
9917
  return d.properties[aggregationExpAlias];
10504
9918
  };
10505
- updateTriggers.getWeight = aggregationExpAlias;
10506
9919
  result.getPointRadius = (d, info) => {
10507
9920
  return calculateClusterRadius(
10508
9921
  d.properties,
@@ -10511,16 +9924,11 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10511
9924
  aggregationExpAlias
10512
9925
  );
10513
9926
  };
10514
- updateTriggers.getPointRadius = {
10515
- aggregationExpAlias,
10516
- radiusRange: visConfig.radiusRange
10517
- };
10518
9927
  result.textCharacterSet = "auto";
10519
9928
  result.textFontFamily = "Inter, sans";
10520
9929
  result.textFontSettings = { sdf: true };
10521
9930
  result.textFontWeight = 600;
10522
9931
  result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
10523
- updateTriggers.getText = aggregationExpAlias;
10524
9932
  result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
10525
9933
  result.textOutlineColor = [
10526
9934
  ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
@@ -10537,107 +9945,68 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10537
9945
  );
10538
9946
  return calculateClusterTextFontSize(radius);
10539
9947
  };
10540
- updateTriggers.getTextSize = {
10541
- aggregationExpAlias,
10542
- radiusRange: visConfig.radiusRange
10543
- };
10544
9948
  }
10545
- {
10546
- const radiusRange = visConfig.radiusRange;
10547
- const { radiusField, radiusScale } = visualChannels;
10548
- if (radiusField && radiusRange && radiusScale) {
10549
- const { accessor, ...scaleProps } = getSizeAccessor(
10550
- radiusField,
10551
- radiusScale,
10552
- visConfig.sizeAggregation,
10553
- radiusRange,
10554
- data
10555
- );
10556
- result.getPointRadius = accessor;
10557
- scales.pointRadius = updateTriggers.getPointRadius = {
10558
- field: radiusField,
10559
- type: radiusScale,
10560
- ...scaleProps
10561
- };
10562
- }
10563
- }
10564
- {
10565
- const strokeColorRange = visConfig.strokeColorRange;
10566
- const { strokeColorScale, strokeColorField } = visualChannels;
10567
- if (strokeColorField && strokeColorRange && strokeColorScale) {
10568
- const { strokeColorAggregation: aggregation } = visConfig;
10569
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10570
- const { accessor, ...scaleProps } = getColorAccessor(
10571
- strokeColorField,
10572
- strokeColorScale,
10573
- { aggregation, range: strokeColorRange },
10574
- opacity,
10575
- data
10576
- );
10577
- result.getLineColor = accessor;
10578
- scales.lineColor = updateTriggers.getLineColor = {
10579
- field: strokeColorField,
10580
- type: strokeColorScale,
10581
- ...scaleProps
10582
- };
10583
- }
9949
+ if (radiusField) {
9950
+ const { accessor, scale: scale2 } = getSizeAccessor(
9951
+ radiusField,
9952
+ radiusScale,
9953
+ visConfig.sizeAggregation,
9954
+ visConfig.radiusRange || visConfig.sizeRange,
9955
+ data
9956
+ );
9957
+ result.getPointRadius = accessor;
9958
+ scales.pointRadius = {
9959
+ field: radiusField,
9960
+ type: radiusScale || "identity",
9961
+ ...domainAndRangeFromScale(scale2)
9962
+ };
10584
9963
  }
10585
- {
10586
- const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10587
- const { sizeRange, sizeAggregation } = visConfig;
10588
- if (strokeWidthField && sizeRange) {
10589
- const { accessor, ...scaleProps } = getSizeAccessor(
10590
- strokeWidthField,
10591
- strokeWidthScale,
10592
- sizeAggregation,
10593
- sizeRange,
10594
- data
10595
- );
10596
- result.getLineWidth = accessor;
10597
- scales.lineWidth = updateTriggers.getLineWidth = {
10598
- field: strokeWidthField,
10599
- type: strokeWidthScale || "identity",
10600
- ...scaleProps
10601
- };
10602
- }
9964
+ if (strokeColorField) {
9965
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
9966
+ const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
9967
+ const { accessor, scale: scale2 } = getColorAccessor(
9968
+ strokeColorField,
9969
+ strokeColorScale,
9970
+ { aggregation, range },
9971
+ opacity,
9972
+ data
9973
+ );
9974
+ result.getLineColor = accessor;
9975
+ scales.lineColor = {
9976
+ field: strokeColorField,
9977
+ type: strokeColorScale,
9978
+ ...domainAndRangeFromScale(scale2)
9979
+ };
10603
9980
  }
10604
- {
10605
- const { enable3d, heightRange } = visConfig;
10606
- const { heightField, heightScale } = visualChannels;
10607
- if (heightField && heightRange && enable3d) {
10608
- const { accessor, ...scaleProps } = getSizeAccessor(
10609
- heightField,
10610
- heightScale,
10611
- visConfig.heightAggregation,
10612
- heightRange,
10613
- data
10614
- );
10615
- result.getElevation = accessor;
10616
- scales.elevation = updateTriggers.getElevation = {
10617
- field: heightField,
10618
- type: heightScale || "identity",
10619
- ...scaleProps
10620
- };
10621
- }
9981
+ if (heightField && visConfig.enable3d) {
9982
+ const { accessor, scale: scale2 } = getSizeAccessor(
9983
+ heightField,
9984
+ heightScale,
9985
+ visConfig.heightAggregation,
9986
+ visConfig.heightRange || visConfig.sizeRange,
9987
+ data
9988
+ );
9989
+ result.getElevation = accessor;
9990
+ scales.elevation = {
9991
+ field: heightField,
9992
+ type: heightScale || "identity",
9993
+ ...domainAndRangeFromScale(scale2)
9994
+ };
10622
9995
  }
10623
- {
10624
- const { weightField } = visualChannels;
10625
- const { weightAggregation } = visConfig;
10626
- if (weightField && weightAggregation) {
10627
- const { accessor, ...scaleProps } = getSizeAccessor(
10628
- weightField,
10629
- void 0,
10630
- weightAggregation,
10631
- void 0,
10632
- data
10633
- );
10634
- result.getWeight = accessor;
10635
- scales.weight = updateTriggers.getWeight = {
10636
- field: weightField,
10637
- type: "identity",
10638
- ...scaleProps
10639
- };
10640
- }
9996
+ if (weightField) {
9997
+ const { accessor, scale: scale2 } = getSizeAccessor(
9998
+ weightField,
9999
+ void 0,
10000
+ visConfig.weightAggregation,
10001
+ void 0,
10002
+ data
10003
+ );
10004
+ result.getWeight = accessor;
10005
+ scales.weight = {
10006
+ field: weightField,
10007
+ type: "identity",
10008
+ ...domainAndRangeFromScale(scale2)
10009
+ };
10641
10010
  }
10642
10011
  if (visConfig.customMarkers) {
10643
10012
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -10654,12 +10023,6 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10654
10023
  { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons },
10655
10024
  data
10656
10025
  );
10657
- updateTriggers.getIcon = {
10658
- customMarkersUrl,
10659
- customMarkersRange,
10660
- maxIconSize,
10661
- useMaskedIcons
10662
- };
10663
10026
  result._subLayerProps = {
10664
10027
  "points-icon": {
10665
10028
  loadOptions: {
@@ -10676,11 +10039,9 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10676
10039
  };
10677
10040
  if (getFillColor && useMaskedIcons) {
10678
10041
  result.getIconColor = getFillColor;
10679
- updateTriggers.getIconColor = updateTriggers.getFillColor;
10680
10042
  }
10681
10043
  if (getPointRadius) {
10682
10044
  result.getIconSize = getPointRadius;
10683
- updateTriggers.getIconSize = updateTriggers.getPointRadius;
10684
10045
  }
10685
10046
  if (visualChannels.rotationField) {
10686
10047
  const { accessor } = getSizeAccessor(
@@ -10691,7 +10052,6 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10691
10052
  data
10692
10053
  );
10693
10054
  result.getIconAngle = negateAccessor(accessor);
10694
- updateTriggers.getIconAngle = updateTriggers.getRotationField;
10695
10055
  }
10696
10056
  } else if (layerType === "tileset") {
10697
10057
  result.pointType = "circle";
@@ -10736,13 +10096,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10736
10096
  }
10737
10097
  };
10738
10098
  }
10739
- return {
10740
- channelProps: {
10741
- ...result,
10742
- updateTriggers
10743
- },
10744
- scales
10745
- };
10099
+ return { channelProps: result, scales };
10746
10100
  }
10747
10101
  function createLoadOptions(accessToken) {
10748
10102
  return {
@@ -11398,16 +10752,9 @@ function hashBuckets(initialCount) {
11398
10752
  WidgetSource,
11399
10753
  WidgetTableSource,
11400
10754
  WidgetTilesetSource,
11401
- _ErrorCode,
11402
- _applyLayerGroupFilters,
11403
10755
  _buildFeatureFilter,
11404
- _createVecExprEvaluator,
11405
10756
  _domainFromValues,
11406
- _evaluateVecExpr,
11407
10757
  _getHexagonResolution,
11408
- _getLog10ScaleSteps,
11409
- _getRasterTileLayerStyleProps,
11410
- _validateVecExprSyntax,
11411
10758
  addFilter,
11412
10759
  aggregate,
11413
10760
  aggregationFunctions,
@@ -11420,11 +10767,9 @@ function hashBuckets(initialCount) {
11420
10767
  buildStatsUrl,
11421
10768
  calculateClusterRadius,
11422
10769
  calculateClusterTextFontSize,
11423
- calculateLayerScale,
11424
10770
  clearDefaultRequestCache,
11425
10771
  clearFilters,
11426
10772
  configureSource,
11427
- createColorScale,
11428
10773
  createPolygonSpatialFilter,
11429
10774
  createViewportSpatialFilter,
11430
10775
  fetchBasemapProps,
@@ -11439,7 +10784,6 @@ function hashBuckets(initialCount) {
11439
10784
  getDefaultAggregationExpColumnAliasForLayerType,
11440
10785
  getFilter,
11441
10786
  getIconUrlAccessor,
11442
- getLayerDescriptor,
11443
10787
  getLayerProps,
11444
10788
  getMaxMarkerSize,
11445
10789
  getSizeAccessor,
@@ -11470,6 +10814,8 @@ function hashBuckets(initialCount) {
11470
10814
  tileFeatures,
11471
10815
  tileFeaturesGeometries,
11472
10816
  tileFeaturesSpatialIndex,
10817
+ trajectoryQuerySource,
10818
+ trajectoryTableSource,
11473
10819
  transformToTileCoords,
11474
10820
  vectorQuerySource,
11475
10821
  vectorTableSource,