@carto/api-client 0.5.15 → 0.5.17

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.
@@ -6152,7 +6152,8 @@ var AVAILABLE_MODELS = [
6152
6152
  "timeseries",
6153
6153
  "range",
6154
6154
  "scatterplot",
6155
- "table"
6155
+ "table",
6156
+ "aggregations"
6156
6157
  ];
6157
6158
  var { V3 } = ApiVersion;
6158
6159
  var REQUEST_GET_MAX_URL_LENGTH = 2048;
@@ -6593,6 +6594,30 @@ var WidgetRemoteSource = class extends WidgetSource {
6593
6594
  categories: res.metadata?.categories
6594
6595
  }));
6595
6596
  }
6597
+ async getAggregations(options) {
6598
+ const {
6599
+ signal,
6600
+ filters = this.props.filters,
6601
+ filterOwner,
6602
+ spatialFilter,
6603
+ spatialFiltersMode,
6604
+ aggregations
6605
+ } = options;
6606
+ return executeModel({
6607
+ model: "aggregations",
6608
+ source: {
6609
+ ...this.getModelSource(filters, filterOwner),
6610
+ spatialFiltersMode,
6611
+ spatialFilter
6612
+ },
6613
+ params: {
6614
+ aggregations
6615
+ },
6616
+ opts: { signal, headers: this.props.headers }
6617
+ }).then((res) => ({
6618
+ rows: res.rows.map((row) => normalizeObjectKeys(row))
6619
+ }));
6620
+ }
6596
6621
  /** @experimental */
6597
6622
  async getExtent(options = {}) {
6598
6623
  const { signal, filters = this.props.filters, filterOwner } = options;
@@ -7392,6 +7417,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7392
7417
  assertColumn(this._features, column);
7393
7418
  }
7394
7419
  const targetOperation = aggregationFunctions[operation2];
7420
+ assert2(targetOperation, `Unsupported aggregation operation: ${operation2}`);
7395
7421
  return {
7396
7422
  value: targetOperation(filteredFeatures, column, joinOperation)
7397
7423
  };
@@ -7590,6 +7616,39 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7590
7616
  max: aggregationFunctions.max(filteredFeatures, column)
7591
7617
  };
7592
7618
  }
7619
+ async getAggregations({
7620
+ aggregations,
7621
+ filters,
7622
+ filterOwner,
7623
+ spatialFilter
7624
+ }) {
7625
+ const filteredFeatures = this._getFilteredFeatures(
7626
+ spatialFilter,
7627
+ filters,
7628
+ filterOwner
7629
+ );
7630
+ if (!this._features.length) {
7631
+ return { rows: [] };
7632
+ }
7633
+ assert2(
7634
+ typeof aggregations !== "string",
7635
+ "Unsupported tileset SQL aggregation"
7636
+ );
7637
+ const result = {};
7638
+ const usedAliases = /* @__PURE__ */ new Set();
7639
+ for (const { column, operation: operation2, alias } of aggregations) {
7640
+ if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
7641
+ assertColumn(this._features, column);
7642
+ }
7643
+ const aliasKey = alias.toLowerCase();
7644
+ assert2(!usedAliases.has(aliasKey), `Duplicate alias: ${aliasKey}`);
7645
+ usedAliases.add(aliasKey);
7646
+ const targetOperation = aggregationFunctions[operation2];
7647
+ assert2(targetOperation, `Unsupported operation: ${operation2}`);
7648
+ result[alias] = targetOperation(filteredFeatures, column);
7649
+ }
7650
+ return { rows: [result] };
7651
+ }
7593
7652
  /** @experimental */
7594
7653
  async getExtent() {
7595
7654
  return Promise.reject(new Error("not implemented"));
@@ -7824,6 +7883,16 @@ var WidgetTilesetSource = class extends WidgetSource {
7824
7883
  }) {
7825
7884
  return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
7826
7885
  }
7886
+ async getAggregations({
7887
+ signal,
7888
+ ...options
7889
+ }) {
7890
+ return this._executeWorkerMethod(
7891
+ "getAggregations" /* GET_AGGREGATIONS */,
7892
+ [options],
7893
+ signal
7894
+ );
7895
+ }
7827
7896
  /** @experimental */
7828
7897
  async getExtent() {
7829
7898
  return Promise.resolve({
@@ -8431,6 +8500,250 @@ var basemap_styles_default = {
8431
8500
  DARK_MATTER_NOLABELS: getStyleUrl("dark-matter-nolabels")
8432
8501
  };
8433
8502
 
8503
+ // src/fetch-map/vec-expr-evaluator.ts
8504
+ import jsep from "jsep";
8505
+ function createVecExprEvaluator(expression) {
8506
+ try {
8507
+ const parsed = compile(expression);
8508
+ const evalFun = (context) => evaluate(parsed, context);
8509
+ evalFun.symbols = getSymbols(parsed);
8510
+ return evalFun;
8511
+ } catch {
8512
+ return null;
8513
+ }
8514
+ }
8515
+ function evaluateVecExpr(expression, context) {
8516
+ try {
8517
+ return createVecExprEvaluator(expression)?.(context);
8518
+ } catch {
8519
+ return null;
8520
+ }
8521
+ }
8522
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
8523
+ ErrorCode2[ErrorCode2["InvalidSyntax"] = 0] = "InvalidSyntax";
8524
+ ErrorCode2[ErrorCode2["UnknownIdentifier"] = 1] = "UnknownIdentifier";
8525
+ return ErrorCode2;
8526
+ })(ErrorCode || {});
8527
+ function validateVecExprSyntax(expression, context) {
8528
+ let parsed;
8529
+ try {
8530
+ parsed = compile(expression);
8531
+ } catch (e) {
8532
+ return {
8533
+ valid: false,
8534
+ errorCode: 0 /* InvalidSyntax */,
8535
+ errorMessage: e && "message" in e ? String(e.message) : String(e)
8536
+ };
8537
+ }
8538
+ return validate(parsed, context);
8539
+ }
8540
+ function createResultArray(typeTemplate, length2 = typeTemplate.length) {
8541
+ return new Array(length2);
8542
+ }
8543
+ function isVecLike(a) {
8544
+ return Array.isArray(a) || ArrayBuffer.isView(a);
8545
+ }
8546
+ var createBinopVec = (scalarBinOp) => (left, right) => {
8547
+ const length2 = Math.min(left.length, right.length);
8548
+ const r = createResultArray(left, length2);
8549
+ for (let i = 0; i < length2; i++) {
8550
+ r[i] = scalarBinOp(left[i], right[i]);
8551
+ }
8552
+ return r;
8553
+ };
8554
+ var createBinopVecNum = (scalarBinOp) => (left, right) => {
8555
+ const length2 = left.length;
8556
+ const r = createResultArray(left, length2);
8557
+ for (let i = 0; i < length2; i++) {
8558
+ r[i] = scalarBinOp(left[i], right);
8559
+ }
8560
+ return r;
8561
+ };
8562
+ var createBinopNumVec = (scalarBinOp) => (left, right) => {
8563
+ const length2 = right.length;
8564
+ const r = createResultArray(right, length2);
8565
+ for (let i = 0; i < length2; i++) {
8566
+ r[i] = scalarBinOp(left, right[i]);
8567
+ }
8568
+ return r;
8569
+ };
8570
+ var createUnopVec = (scalarUnop) => (a) => {
8571
+ const length2 = a.length;
8572
+ const r = createResultArray(a, length2);
8573
+ for (let i = 0; i < length2; i++) {
8574
+ r[i] = scalarUnop(a[i]);
8575
+ }
8576
+ return r;
8577
+ };
8578
+ function mapDictValues(dict, fun) {
8579
+ return Object.keys(dict).reduce(
8580
+ (acc, key) => {
8581
+ acc[key] = fun(dict[key]);
8582
+ return acc;
8583
+ },
8584
+ {}
8585
+ );
8586
+ }
8587
+ var binopsNum = {
8588
+ "||": (a, b) => a || b,
8589
+ "&&": (a, b) => a && b,
8590
+ "|": (a, b) => a | b,
8591
+ "^": (a, b) => a ^ b,
8592
+ "&": (a, b) => a & b,
8593
+ "==": (a, b) => Number(a == b),
8594
+ "!=": (a, b) => Number(a != b),
8595
+ "===": (a, b) => Number(a === b),
8596
+ "!==": (a, b) => Number(a !== b),
8597
+ "<": (a, b) => Number(a < b),
8598
+ ">": (a, b) => Number(a > b),
8599
+ "<=": (a, b) => Number(a <= b),
8600
+ ">=": (a, b) => Number(a >= b),
8601
+ "<<": (a, b) => a << b,
8602
+ ">>": (a, b) => a >> b,
8603
+ ">>>": (a, b) => a >>> b,
8604
+ "+": (a, b) => a + b,
8605
+ "-": (a, b) => a - b,
8606
+ "*": (a, b) => a * b,
8607
+ "/": (a, b) => a / b,
8608
+ "%": (a, b) => a % b
8609
+ };
8610
+ var unopsNum = {
8611
+ "-": (a) => -a,
8612
+ "+": (a) => +a,
8613
+ "~": (a) => ~a,
8614
+ "!": (a) => Number(!a)
8615
+ };
8616
+ var binopsVector = mapDictValues(binopsNum, createBinopVec);
8617
+ var binopsNumVec = mapDictValues(binopsNum, createBinopNumVec);
8618
+ var binopsVecNum = mapDictValues(binopsNum, createBinopVecNum);
8619
+ var unopsVector = mapDictValues(unopsNum, createUnopVec);
8620
+ function getBinop(operator, left, right) {
8621
+ const isLeftVec = isVecLike(left);
8622
+ const isRightVec = isVecLike(right);
8623
+ if (isLeftVec && isRightVec) {
8624
+ return binopsVector[operator];
8625
+ } else if (isLeftVec) {
8626
+ return binopsVecNum[operator];
8627
+ } else if (isRightVec) {
8628
+ return binopsNumVec[operator];
8629
+ } else {
8630
+ return binopsNum[operator];
8631
+ }
8632
+ }
8633
+ function evaluate(_node, context) {
8634
+ const node = _node;
8635
+ switch (node.type) {
8636
+ case "BinaryExpression": {
8637
+ const left = evaluate(node.left, context);
8638
+ const right = evaluate(node.right, context);
8639
+ const binopFun = getBinop(node.operator, left, right);
8640
+ return binopFun(left, right);
8641
+ }
8642
+ case "ConditionalExpression": {
8643
+ const val = evaluate(node.test, context);
8644
+ if (isVecLike(val)) {
8645
+ const length2 = val.length;
8646
+ const consequentVal = evaluate(node.consequent, context);
8647
+ const alternateVal = evaluate(node.alternate, context);
8648
+ const r = createResultArray(val);
8649
+ for (let i = 0; i < length2; i++) {
8650
+ const entryVal = val[i] ? consequentVal : alternateVal;
8651
+ r[i] = isVecLike(entryVal) ? entryVal[i] ?? NaN : entryVal;
8652
+ }
8653
+ return r;
8654
+ } else {
8655
+ return val ? evaluate(node.consequent, context) : evaluate(node.alternate, context);
8656
+ }
8657
+ }
8658
+ case "Identifier":
8659
+ return context[node.name];
8660
+ case "Literal":
8661
+ return node.value;
8662
+ case "UnaryExpression": {
8663
+ const val = evaluate(node.argument, context);
8664
+ const unopFun = isVecLike(val) ? unopsVector[node.operator] : unopsNum[node.operator];
8665
+ return unopFun(val);
8666
+ }
8667
+ default:
8668
+ return void 0;
8669
+ }
8670
+ }
8671
+ var validResult = { valid: true };
8672
+ function visit(_node, visitor) {
8673
+ const node = _node;
8674
+ visitor(node);
8675
+ switch (node.type) {
8676
+ case "BinaryExpression": {
8677
+ visit(node.left, visitor);
8678
+ visit(node.right, visitor);
8679
+ break;
8680
+ }
8681
+ case "ConditionalExpression": {
8682
+ visit(node.test, visitor);
8683
+ visit(node.consequent, visitor);
8684
+ visit(node.alternate, visitor);
8685
+ break;
8686
+ }
8687
+ case "UnaryExpression": {
8688
+ visit(node.argument, visitor);
8689
+ break;
8690
+ }
8691
+ }
8692
+ }
8693
+ var supportedExpressionTypes = [
8694
+ "BinaryExpression",
8695
+ "UnaryExpression",
8696
+ "ConditionalExpression",
8697
+ "LogicalExpression",
8698
+ "Identifier",
8699
+ "Literal"
8700
+ ];
8701
+ function validate(_node, context) {
8702
+ const node = _node;
8703
+ const errors = [];
8704
+ visit(node, (node2) => {
8705
+ if (!supportedExpressionTypes.includes(node2.type)) {
8706
+ errors.push({
8707
+ valid: false,
8708
+ errorCode: 0 /* InvalidSyntax */,
8709
+ errorMessage: `Not allowed`
8710
+ });
8711
+ return;
8712
+ }
8713
+ if (node2.type === "Identifier") {
8714
+ if (!Object.prototype.hasOwnProperty.call(context, node2.name)) {
8715
+ return errors.push({
8716
+ valid: false,
8717
+ errorCode: 1 /* UnknownIdentifier */,
8718
+ errorMessage: `"${node2.name}" not found`
8719
+ });
8720
+ }
8721
+ }
8722
+ if (node2.type === "Literal") {
8723
+ if (typeof node2.value !== "number") {
8724
+ return errors.push({
8725
+ valid: false,
8726
+ errorCode: 0 /* InvalidSyntax */,
8727
+ errorMessage: `Only number literals are supported`
8728
+ });
8729
+ }
8730
+ }
8731
+ });
8732
+ return errors.length ? errors[0] : validResult;
8733
+ }
8734
+ function getSymbols(node) {
8735
+ const symbols = /* @__PURE__ */ new Set();
8736
+ visit(node, (node2) => {
8737
+ if (node2.type === "Identifier") {
8738
+ symbols.add(node2.name);
8739
+ }
8740
+ });
8741
+ return Array.from(symbols);
8742
+ }
8743
+ function compile(expression) {
8744
+ return jsep(expression);
8745
+ }
8746
+
8434
8747
  // node_modules/d3-array/src/ascending.js
8435
8748
  function ascending(a, b) {
8436
8749
  return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
@@ -9009,6 +9322,37 @@ function formatDate(value) {
9009
9322
  function formatTimestamp(value) {
9010
9323
  return String(Math.floor(new Date(value).getTime() / 1e3));
9011
9324
  }
9325
+ function roundedPow10(exp) {
9326
+ const raw = Math.pow(10, exp);
9327
+ if (exp < 0) {
9328
+ const shift = Math.pow(10, -exp);
9329
+ return Math.round(raw * shift) / shift;
9330
+ }
9331
+ return raw;
9332
+ }
9333
+ function getLog10ScaleSteps({
9334
+ min: min2,
9335
+ max: max2,
9336
+ steps
9337
+ }) {
9338
+ if (min2 === 0) {
9339
+ if (max2 === Infinity) {
9340
+ return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9341
+ }
9342
+ const maxLog = Math.log10(max2);
9343
+ const endExponent = Math.ceil(maxLog);
9344
+ const startExponent = endExponent - steps + 1;
9345
+ return [...Array(steps - 1)].map(
9346
+ (_v, i) => roundedPow10(startExponent + i)
9347
+ );
9348
+ } else {
9349
+ const minLog = Math.log10(min2);
9350
+ const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9351
+ return [...Array(steps - 1)].map(
9352
+ (_v, i) => roundedPow10(startExponent + i)
9353
+ );
9354
+ }
9355
+ }
9012
9356
 
9013
9357
  // src/fetch-map/layer-map.ts
9014
9358
  var SCALE_FUNCS = {
@@ -9025,7 +9369,19 @@ var SCALE_FUNCS = {
9025
9369
  function identity2(v2) {
9026
9370
  return v2;
9027
9371
  }
9372
+ var hexToRGB = (c) => {
9373
+ const { r, g, b } = rgb(c);
9374
+ return [r, g, b];
9375
+ };
9376
+ var rgbToHex = (c) => {
9377
+ const [r, g, b] = c;
9378
+ const rStr = r.toString(16).padStart(2, "0");
9379
+ const gStr = g.toString(16).padStart(2, "0");
9380
+ const bStr = b.toString(16).padStart(2, "0");
9381
+ return `#${rStr}${gStr}${bStr}`.toUpperCase();
9382
+ };
9028
9383
  var UNKNOWN_COLOR = "#868d91";
9384
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9029
9385
  var OPACITY_MAP = {
9030
9386
  getFillColor: "opacity",
9031
9387
  getLineColor: "strokeOpacity",
@@ -9058,6 +9414,12 @@ var sharedPropMap = {
9058
9414
  wireframe: "wireframe"
9059
9415
  }
9060
9416
  };
9417
+ var rasterPropsMap = {
9418
+ isVisible: "visible",
9419
+ visConfig: {
9420
+ opacity: "opacity"
9421
+ }
9422
+ };
9061
9423
  var customMarkersPropsMap = {
9062
9424
  color: "getIconColor",
9063
9425
  visConfig: {
@@ -9101,6 +9463,12 @@ function getLayerProps(type, config2, dataset) {
9101
9463
  `Outdated layer type: ${type}. Please open map in CARTO Builder to automatically migrate.`
9102
9464
  );
9103
9465
  }
9466
+ if (type === "raster") {
9467
+ return {
9468
+ propMap: rasterPropsMap,
9469
+ defaultProps: {}
9470
+ };
9471
+ }
9104
9472
  let basePropMap = sharedPropMap;
9105
9473
  if (config2.visConfig?.customMarkers) {
9106
9474
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -9121,16 +9489,19 @@ function getLayerProps(type, config2, dataset) {
9121
9489
  }
9122
9490
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9123
9491
  if (scaleType === "ordinal" || scaleType === "point") {
9492
+ if (!attribute.categories) {
9493
+ return [0, 1];
9494
+ }
9124
9495
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9125
9496
  }
9126
9497
  if (scaleType === "quantile" && attribute.quantiles) {
9127
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9498
+ return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9128
9499
  }
9129
9500
  let { min: min2 } = attribute;
9130
9501
  if (scaleType === "log" && min2 === 0) {
9131
9502
  min2 = 1e-5;
9132
9503
  }
9133
- return [min2, attribute.max];
9504
+ return [min2 ?? 0, attribute.max ?? 1];
9134
9505
  }
9135
9506
  function domainFromValues(values, scaleType) {
9136
9507
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9151,12 +9522,14 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9151
9522
  if (data.tilestats) {
9152
9523
  const { attributes } = data.tilestats.layers[0];
9153
9524
  const attribute = attributes.find((a) => a.attribute === name);
9154
- return domainFromAttribute(attribute, scaleType, scaleLength);
9525
+ if (attribute) {
9526
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9527
+ }
9155
9528
  }
9156
9529
  return [0, 1];
9157
9530
  }
9158
9531
  function normalizeAccessor(accessor, data) {
9159
- if (data.features || data.tilestats) {
9532
+ if (data.features || data.tilestats || data.raster_metadata) {
9160
9533
  return (object, info) => {
9161
9534
  if (object) {
9162
9535
  return accessor(object.properties || object.__source.object.properties);
@@ -9189,46 +9562,75 @@ function findAccessorKey(keys, properties) {
9189
9562
  return keys;
9190
9563
  }
9191
9564
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9192
- const scale2 = calculateLayerScale(
9565
+ const { scale: scale2, domain } = calculateLayerScale(
9193
9566
  colorColumn || name,
9194
- scaleType,
9567
+ colorColumn ? "identity" : scaleType,
9195
9568
  range,
9196
9569
  data
9197
9570
  );
9198
9571
  const alpha = opacityToAlpha(opacity);
9199
- let accessorKeys = getAccessorKeys(name, aggregation);
9572
+ let accessorKeys = getAccessorKeys(colorColumn || name, aggregation);
9200
9573
  const accessor = (properties) => {
9201
9574
  if (!(accessorKeys[0] in properties)) {
9202
9575
  accessorKeys = findAccessorKey(accessorKeys, properties);
9203
9576
  }
9204
9577
  const propertyValue = properties[accessorKeys[0]];
9205
- const { r, g, b } = rgb(scale2(propertyValue));
9206
- return [r, g, b, propertyValue === null ? 0 : alpha];
9578
+ const scaled = scale2(propertyValue);
9579
+ const rgb2 = typeof scaled === "string" ? hexToRGB(scaled) : scaled;
9580
+ return [...rgb2, propertyValue === null ? 0 : alpha];
9581
+ };
9582
+ return {
9583
+ accessor: normalizeAccessor(accessor, data),
9584
+ scaleDomain: scale2.domain(),
9585
+ domain,
9586
+ range: (scale2.range() || []).map(rgbToHex)
9207
9587
  };
9208
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9209
9588
  }
9210
9589
  function calculateLayerScale(name, scaleType, range, data) {
9211
- const scale2 = SCALE_FUNCS[scaleType]();
9212
9590
  let domain = [];
9591
+ let scaleDomain;
9213
9592
  let scaleColor = [];
9214
- if (scaleType !== "identity") {
9215
- const { colorMap, colors } = range;
9216
- if (Array.isArray(colorMap)) {
9593
+ const { colors } = range;
9594
+ if (scaleType === "custom") {
9595
+ domain = calculateDomain(data, name, scaleType, colors.length);
9596
+ const [min2, max2] = domain;
9597
+ if (range.uiCustomScaleType === "logarithmic") {
9598
+ scaleDomain = getLog10ScaleSteps({
9599
+ min: min2,
9600
+ max: max2,
9601
+ steps: colors.length
9602
+ });
9603
+ scaleColor = colors;
9604
+ } else if (range.colorMap) {
9605
+ const { colorMap } = range;
9606
+ scaleDomain = [];
9217
9607
  colorMap.forEach(([value, color2]) => {
9218
- domain.push(value);
9608
+ scaleDomain.push(Number(value));
9219
9609
  scaleColor.push(color2);
9220
9610
  });
9221
- } else {
9222
- domain = calculateDomain(data, name, scaleType, colors.length);
9223
- scaleColor = colors;
9224
9611
  }
9612
+ } else if (scaleType !== "identity") {
9613
+ domain = calculateDomain(data, name, scaleType, colors.length);
9614
+ scaleColor = colors;
9225
9615
  if (scaleType === "ordinal") {
9226
9616
  domain = domain.slice(0, scaleColor.length);
9227
9617
  }
9228
9618
  }
9619
+ return {
9620
+ scale: createColorScale(
9621
+ scaleType,
9622
+ scaleDomain || domain,
9623
+ scaleColor.map(hexToRGB),
9624
+ UNKNOWN_COLOR_RGB
9625
+ ),
9626
+ domain
9627
+ };
9628
+ }
9629
+ function createColorScale(scaleType, domain, range, unknown) {
9630
+ const scale2 = SCALE_FUNCS[scaleType]();
9229
9631
  scale2.domain(domain);
9230
- scale2.range(scaleColor);
9231
- scale2.unknown(UNKNOWN_COLOR);
9632
+ scale2.range(range);
9633
+ scale2.unknown(unknown);
9232
9634
  return scale2;
9233
9635
  }
9234
9636
  var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
@@ -9278,9 +9680,13 @@ function negateAccessor(accessor) {
9278
9680
  }
9279
9681
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9280
9682
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9281
- if (scaleType) {
9683
+ let domain = [];
9684
+ if (scaleType && range) {
9282
9685
  if (aggregation !== AggregationTypes.Count) {
9283
- scale2.domain(calculateDomain(data, name, scaleType));
9686
+ domain = calculateDomain(data, name, scaleType);
9687
+ scale2.domain(domain);
9688
+ } else {
9689
+ domain = scale2.domain();
9284
9690
  }
9285
9691
  scale2.range(range);
9286
9692
  }
@@ -9292,7 +9698,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9292
9698
  const propertyValue = properties[accessorKeys[0]];
9293
9699
  return scale2(propertyValue);
9294
9700
  };
9295
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9701
+ return {
9702
+ accessor: normalizeAccessor(accessor, data),
9703
+ domain,
9704
+ scaleDomain: domain,
9705
+ range
9706
+ };
9296
9707
  }
9297
9708
  var FORMATS = {
9298
9709
  date: formatDate,
@@ -9343,13 +9754,420 @@ function calculateClusterTextFontSize(radius) {
9343
9754
  return 11;
9344
9755
  }
9345
9756
 
9757
+ // src/fetch-map/raster-layer.ts
9758
+ var UNKNOWN_COLOR2 = [134, 141, 145];
9759
+ var RASTER_COLOR_BANDS = ["red", "green", "blue"];
9760
+ function getHasDataPredicate(noData) {
9761
+ if (noData === "nan") {
9762
+ return (v2) => !isNaN(v2);
9763
+ }
9764
+ if (typeof noData === "string") {
9765
+ noData = parseFloat(noData);
9766
+ }
9767
+ if (typeof noData === "number") {
9768
+ return (v2) => v2 !== noData && !isNaN(v2);
9769
+ }
9770
+ return () => true;
9771
+ }
9772
+ function createRasterColumnLayerDataTransform(transform) {
9773
+ return (data) => {
9774
+ if (!data || !("data" in data) || !data?.data?.cells?.numericProps) {
9775
+ return data;
9776
+ }
9777
+ return transform(data);
9778
+ };
9779
+ }
9780
+ function createEvaluationContext(numericProps, noData) {
9781
+ const hasData = getHasDataPredicate(noData);
9782
+ const bands = Object.entries(numericProps).map(([bandName, { value }]) => ({
9783
+ bandName,
9784
+ values: value,
9785
+ copied: false
9786
+ }));
9787
+ const length2 = bands[0].values.length;
9788
+ for (let i = 0; i < length2; i++) {
9789
+ let hasSomeData = false;
9790
+ for (let j = 0; j < bands.length; j++) {
9791
+ hasSomeData = hasSomeData || hasData(bands[j].values[i]);
9792
+ }
9793
+ if (!hasSomeData) {
9794
+ for (let j = 0; j < bands.length; j++) {
9795
+ if (!bands[j].copied) {
9796
+ bands[j].copied = true;
9797
+ bands[j].values = Array.from(bands[j].values);
9798
+ }
9799
+ bands[j].values[i] = NaN;
9800
+ }
9801
+ }
9802
+ }
9803
+ const context = bands.reduce(
9804
+ (agg, { bandName, values }) => {
9805
+ agg[bandName] = values;
9806
+ return agg;
9807
+ },
9808
+ {}
9809
+ );
9810
+ return context;
9811
+ }
9812
+ function createExprDataTransform({
9813
+ colorBand,
9814
+ rasterMetadata,
9815
+ usedSymbols
9816
+ }) {
9817
+ if (!colorBand || !colorBand.type || colorBand.type === "none") {
9818
+ return void 0;
9819
+ }
9820
+ const expr = colorBand?.type === "expression" ? colorBand.value : void 0;
9821
+ const vecExprEvaluator = expr ? createVecExprEvaluator(expr) : void 0;
9822
+ const dataTransform = createRasterColumnLayerDataTransform(
9823
+ (dataWrapped) => {
9824
+ const data = dataWrapped.data;
9825
+ if (expr) {
9826
+ const cachedResult = dataWrapped.customExpressionResults?.[expr];
9827
+ if (cachedResult) {
9828
+ return dataWrapped;
9829
+ }
9830
+ }
9831
+ let context = dataWrapped.expressionEvalContext;
9832
+ if (!context) {
9833
+ const usedNumericProps = usedSymbols.reduce(
9834
+ (acc, symbol) => {
9835
+ acc[symbol] = data.cells.numericProps[symbol];
9836
+ return acc;
9837
+ },
9838
+ {}
9839
+ );
9840
+ context = createEvaluationContext(
9841
+ usedNumericProps,
9842
+ rasterMetadata.nodata
9843
+ );
9844
+ dataWrapped = {
9845
+ ...dataWrapped,
9846
+ expressionEvalContext: context
9847
+ };
9848
+ }
9849
+ if (!vecExprEvaluator || !expr) return dataWrapped;
9850
+ const evalResult = vecExprEvaluator(context);
9851
+ return {
9852
+ ...dataWrapped,
9853
+ customExpressionResults: {
9854
+ ...dataWrapped.customExpressionResults,
9855
+ [expr]: evalResult
9856
+ }
9857
+ };
9858
+ }
9859
+ );
9860
+ return dataTransform;
9861
+ }
9862
+ function combineDataTransforms(dataTransforms) {
9863
+ const actualTransforms = dataTransforms.filter((v2) => v2);
9864
+ if (actualTransforms.length === 0) return void 0;
9865
+ if (actualTransforms.length === 1) return actualTransforms[0];
9866
+ return (data) => actualTransforms.reduce(
9867
+ (aggData, transformFun) => transformFun(aggData),
9868
+ data
9869
+ );
9870
+ }
9871
+ function createRgbToColorBufferDataTransform({
9872
+ bandDefs,
9873
+ attribute
9874
+ }) {
9875
+ return createRasterColumnLayerDataTransform(
9876
+ (dataWrapped) => {
9877
+ const length2 = dataWrapped.length;
9878
+ const getBandBufferOrValue = (colorBand) => {
9879
+ if (colorBand?.type === "expression") {
9880
+ return dataWrapped.customExpressionResults?.[colorBand.value];
9881
+ }
9882
+ if (colorBand?.type === "band") {
9883
+ return dataWrapped.expressionEvalContext?.[colorBand.value];
9884
+ }
9885
+ return 0;
9886
+ };
9887
+ const red = getBandBufferOrValue(bandDefs.red);
9888
+ const green = getBandBufferOrValue(bandDefs.green);
9889
+ const blue = getBandBufferOrValue(bandDefs.blue);
9890
+ const colorBuffer = new Uint8Array(length2 * 4);
9891
+ for (let inputIndex = 0, outputIndex = 0; inputIndex < length2; inputIndex++, outputIndex += 4) {
9892
+ const redRaw = typeof red === "number" ? red : red ? red[inputIndex] : NaN;
9893
+ const greenRaw = typeof green === "number" ? green : green ? green[inputIndex] : NaN;
9894
+ const blueRaw = typeof blue === "number" ? blue : blue ? blue[inputIndex] : NaN;
9895
+ if (isNaN(redRaw) && isNaN(greenRaw) && isNaN(blueRaw)) {
9896
+ bufferSetRgba(colorBuffer, outputIndex, 0, 0, 0, 0);
9897
+ } else {
9898
+ bufferSetRgba(
9899
+ colorBuffer,
9900
+ outputIndex,
9901
+ redRaw,
9902
+ greenRaw,
9903
+ blueRaw,
9904
+ 255
9905
+ );
9906
+ }
9907
+ }
9908
+ dataWrapped.customExpressionResults = void 0;
9909
+ dataWrapped.expressionEvalContext = void 0;
9910
+ return {
9911
+ ...dataWrapped,
9912
+ attributes: {
9913
+ [attribute]: colorBuffer
9914
+ }
9915
+ };
9916
+ }
9917
+ );
9918
+ }
9919
+ function getUsedSymbols(colorBands) {
9920
+ return Array.from(
9921
+ colorBands.reduce((symbols, band) => {
9922
+ if (band.type === "expression") {
9923
+ const expressionSymbols = createVecExprEvaluator(band.value)?.symbols || [];
9924
+ expressionSymbols.forEach((symbol) => symbols.add(symbol));
9925
+ }
9926
+ if (band.type === "band") {
9927
+ symbols.add(band.value);
9928
+ }
9929
+ return symbols;
9930
+ }, /* @__PURE__ */ new Set())
9931
+ );
9932
+ }
9933
+ function getRasterTileLayerStylePropsRgb({
9934
+ layerConfig,
9935
+ rasterMetadata,
9936
+ visualChannels
9937
+ }) {
9938
+ const { visConfig } = layerConfig;
9939
+ const { colorBands } = visConfig;
9940
+ const bandDefs = {
9941
+ red: colorBands?.find((band) => band.band === "red"),
9942
+ green: colorBands?.find((band) => band.band === "green"),
9943
+ blue: colorBands?.find((band) => band.band === "blue")
9944
+ };
9945
+ const rgbToInstanceFillColorsDataTransform = createRgbToColorBufferDataTransform({
9946
+ bandDefs,
9947
+ attribute: "instanceFillColors"
9948
+ });
9949
+ const usedSymbols = colorBands ? getUsedSymbols(colorBands) : [];
9950
+ const bandTransforms = RASTER_COLOR_BANDS.map(
9951
+ (band) => createExprDataTransform({
9952
+ colorBand: bandDefs[band],
9953
+ rasterMetadata,
9954
+ usedSymbols
9955
+ })
9956
+ );
9957
+ const combinedDataTransform = combineDataTransforms([
9958
+ ...bandTransforms,
9959
+ rgbToInstanceFillColorsDataTransform
9960
+ ]);
9961
+ return {
9962
+ dataTransform: combinedDataTransform,
9963
+ updateTriggers: getRasterTileLayerUpdateTriggers({
9964
+ layerConfig,
9965
+ visualChannels
9966
+ })
9967
+ };
9968
+ }
9969
+ function createBandColorScaleDataTransform({
9970
+ bandName,
9971
+ scaleFun,
9972
+ nodata,
9973
+ attribute
9974
+ }) {
9975
+ const hasData = getHasDataPredicate(nodata);
9976
+ return createRasterColumnLayerDataTransform(
9977
+ (dataWrapped) => {
9978
+ const length2 = dataWrapped.length;
9979
+ const bandBuffer = dataWrapped.data.cells.numericProps[bandName].value;
9980
+ const colorBuffer = new Uint8Array(length2 * 4);
9981
+ for (let i = 0; i < length2; i++) {
9982
+ const rawValue = bandBuffer[i];
9983
+ if (!hasData(rawValue)) {
9984
+ bufferSetRgba(colorBuffer, i * 4, 0, 0, 0, 0);
9985
+ } else {
9986
+ const colorRgb = scaleFun(rawValue);
9987
+ bufferSetRgba(
9988
+ colorBuffer,
9989
+ i * 4,
9990
+ colorRgb[0],
9991
+ colorRgb[1],
9992
+ colorRgb[2],
9993
+ 255
9994
+ );
9995
+ }
9996
+ }
9997
+ return {
9998
+ ...dataWrapped,
9999
+ attributes: {
10000
+ [attribute]: colorBuffer
10001
+ }
10002
+ };
10003
+ }
10004
+ );
10005
+ }
10006
+ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10007
+ if (scaleType === "ordinal") {
10008
+ return colorRange.colorMap?.map(([value]) => value) || [];
10009
+ }
10010
+ if (scaleType === "custom") {
10011
+ if (colorRange.uiCustomScaleType === "logarithmic") {
10012
+ return getLog10ScaleSteps({
10013
+ min: band.stats.min,
10014
+ max: band.stats.max,
10015
+ steps: colorRange.colors.length
10016
+ });
10017
+ } else {
10018
+ return colorRange.colorMap?.map(([value]) => value) || [];
10019
+ }
10020
+ }
10021
+ const scaleLength = colorRange.colors.length;
10022
+ if (scaleType === "quantile") {
10023
+ const quantiles = band.stats.quantiles?.[scaleLength];
10024
+ if (!quantiles) {
10025
+ return [0, 1];
10026
+ }
10027
+ return [band.stats.min, ...quantiles, band.stats.max];
10028
+ }
10029
+ return [band.stats.min, band.stats.max];
10030
+ }
10031
+ function getRasterTileLayerStylePropsScaledBand({
10032
+ layerConfig,
10033
+ rasterMetadata,
10034
+ visualChannels
10035
+ }) {
10036
+ const { visConfig } = layerConfig;
10037
+ const { colorField } = visualChannels;
10038
+ const { rasterStyleType } = visConfig;
10039
+ const colorRange = rasterStyleType === "ColorRange" ? visConfig.colorRange : visConfig.uniqueValuesColorRange;
10040
+ const scaleType = rasterStyleType === "ColorRange" ? visualChannels.colorScale : "ordinal";
10041
+ const bandInfo = rasterMetadata.bands.find(
10042
+ (band) => band.name === colorField?.name
10043
+ );
10044
+ if (!colorField?.name || !scaleType || !colorRange || !bandInfo) {
10045
+ return {};
10046
+ }
10047
+ const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
10048
+ const scaleFun = createColorScale(
10049
+ scaleType,
10050
+ domain,
10051
+ colorRange.colors.map(hexToRGB2),
10052
+ UNKNOWN_COLOR2
10053
+ );
10054
+ const bandColorScaleDataTransform = createBandColorScaleDataTransform({
10055
+ bandName: bandInfo.name,
10056
+ scaleFun,
10057
+ nodata: bandInfo?.nodata ?? rasterMetadata.nodata,
10058
+ attribute: "instanceFillColors"
10059
+ });
10060
+ return {
10061
+ dataTransform: bandColorScaleDataTransform,
10062
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10063
+ layerConfig,
10064
+ visualChannels
10065
+ })
10066
+ };
10067
+ }
10068
+ function getRasterTileLayerStyleProps({
10069
+ layerConfig,
10070
+ visualChannels,
10071
+ rasterMetadata
10072
+ }) {
10073
+ const { visConfig } = layerConfig;
10074
+ const { rasterStyleType } = visConfig;
10075
+ if (rasterStyleType === "Rgb") {
10076
+ return getRasterTileLayerStylePropsRgb({
10077
+ layerConfig,
10078
+ rasterMetadata,
10079
+ visualChannels
10080
+ });
10081
+ } else {
10082
+ return getRasterTileLayerStylePropsScaledBand({
10083
+ layerConfig,
10084
+ rasterMetadata,
10085
+ visualChannels
10086
+ });
10087
+ }
10088
+ }
10089
+ function getRasterTileLayerUpdateTriggers({
10090
+ layerConfig,
10091
+ visualChannels
10092
+ }) {
10093
+ const { visConfig } = layerConfig;
10094
+ const { rasterStyleType } = visConfig;
10095
+ const getFillColorUpdateTriggers = {
10096
+ rasterStyleType
10097
+ };
10098
+ if (rasterStyleType === "ColorRange") {
10099
+ getFillColorUpdateTriggers.colorRange = visConfig.colorRange?.colors;
10100
+ getFillColorUpdateTriggers.colorMap = visConfig.colorRange?.colorMap;
10101
+ getFillColorUpdateTriggers.colorScale = visualChannels.colorScale;
10102
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10103
+ } else if (rasterStyleType === "UniqueValues") {
10104
+ getFillColorUpdateTriggers.colorMap = visConfig.uniqueValuesColorRange?.colorMap;
10105
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10106
+ } else if (rasterStyleType === "Rgb") {
10107
+ getFillColorUpdateTriggers.colorBands = visConfig.colorBands;
10108
+ }
10109
+ return {
10110
+ getFillColor: getFillColorUpdateTriggers
10111
+ };
10112
+ }
10113
+ function bufferSetRgba(target, index, r, g, b, a) {
10114
+ target[index + 0] = r;
10115
+ target[index + 1] = g;
10116
+ target[index + 2] = b;
10117
+ target[index + 3] = a;
10118
+ }
10119
+ function hexToRGB2(hexColor) {
10120
+ const r = parseInt(hexColor.slice(1, 3), 16);
10121
+ const g = parseInt(hexColor.slice(3, 5), 16);
10122
+ const b = parseInt(hexColor.slice(5, 7), 16);
10123
+ return [r, g, b];
10124
+ }
10125
+
9346
10126
  // src/fetch-map/parse-map.ts
10127
+ function getLayerDescriptor({
10128
+ mapConfig,
10129
+ layer,
10130
+ dataset
10131
+ }) {
10132
+ const { filters, visState } = mapConfig;
10133
+ const { layerBlending, interactionConfig } = visState;
10134
+ const { id, type, config: config2, visualChannels } = layer;
10135
+ const { data, id: datasetId } = dataset;
10136
+ const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config2, dataset);
10137
+ const styleProps = createStyleProps(config2, propMap);
10138
+ const { channelProps, scales } = createChannelProps(
10139
+ id,
10140
+ type,
10141
+ config2,
10142
+ visualChannels,
10143
+ data,
10144
+ dataset
10145
+ );
10146
+ const layerDescriptor = {
10147
+ type,
10148
+ filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[datasetId],
10149
+ props: {
10150
+ id,
10151
+ data,
10152
+ ...defaultProps2,
10153
+ ...createInteractionProps(interactionConfig),
10154
+ ...styleProps,
10155
+ ...channelProps,
10156
+ ...createParametersProp(layerBlending, styleProps.parameters || {}),
10157
+ // Must come after style
10158
+ ...createLoadOptions(data.accessToken)
10159
+ },
10160
+ scales
10161
+ };
10162
+ return layerDescriptor;
10163
+ }
9347
10164
  function parseMap(json) {
9348
10165
  const { keplerMapConfig, datasets, token } = json;
9349
10166
  assert2(keplerMapConfig.version === "v1", "Only support Kepler v1");
9350
- const config2 = keplerMapConfig.config;
9351
- const { filters, mapState, mapStyle, popupSettings, legendSettings } = config2;
9352
- const { layers, layerBlending, interactionConfig } = config2.visState;
10167
+ const mapConfig = keplerMapConfig.config;
10168
+ const { mapState, mapStyle, popupSettings, legendSettings, visState } = mapConfig;
10169
+ const { layers } = visState;
10170
+ const layersReverse = [...layers].reverse();
9353
10171
  return {
9354
10172
  id: json.id,
9355
10173
  title: json.title,
@@ -9362,45 +10180,19 @@ function parseMap(json) {
9362
10180
  popupSettings,
9363
10181
  legendSettings,
9364
10182
  token,
9365
- layers: layers.reverse().map(({ id, type, config: config3, visualChannels }) => {
10183
+ layers: layersReverse.map((layer) => {
9366
10184
  try {
9367
- const { dataId } = config3;
10185
+ const { dataId } = layer.config;
9368
10186
  const dataset = datasets.find(
9369
10187
  (d) => d.id === dataId
9370
10188
  );
9371
10189
  assert2(dataset, `No dataset matching dataId: ${dataId}`);
9372
- const { data } = dataset;
9373
- assert2(data, `No data loaded for dataId: ${dataId}`);
9374
- const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config3, dataset);
9375
- const styleProps = createStyleProps(config3, propMap);
9376
- const { channelProps, scales } = createChannelProps(
9377
- id,
9378
- type,
9379
- config3,
9380
- visualChannels,
9381
- data,
10190
+ const layerDescriptor = getLayerDescriptor({
10191
+ mapConfig,
10192
+ layer,
9382
10193
  dataset
9383
- );
9384
- const layer = {
9385
- type,
9386
- filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[dataId],
9387
- props: {
9388
- id,
9389
- data,
9390
- ...defaultProps2,
9391
- ...createInteractionProps(interactionConfig),
9392
- ...styleProps,
9393
- ...channelProps,
9394
- ...createParametersProp(
9395
- layerBlending,
9396
- styleProps.parameters || {}
9397
- ),
9398
- // Must come after style
9399
- ...createLoadOptions(token)
9400
- },
9401
- scales
9402
- };
9403
- return layer;
10194
+ });
10195
+ return layerDescriptor;
9404
10196
  } catch (e) {
9405
10197
  console.error(e.message);
9406
10198
  return void 0;
@@ -9465,43 +10257,63 @@ function createStyleProps(config2, mapping) {
9465
10257
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
9466
10258
  return result;
9467
10259
  }
9468
- function domainAndRangeFromScale(scale2) {
9469
- return {
9470
- domain: scale2.domain(),
9471
- range: scale2.range()
9472
- };
9473
- }
9474
10260
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
9475
- const {
9476
- colorField,
9477
- colorScale,
9478
- radiusField,
9479
- radiusScale,
9480
- strokeColorField,
9481
- strokeColorScale,
9482
- weightField
9483
- } = visualChannels;
9484
- const { heightField, heightScale } = visualChannels;
10261
+ if (layerType === "raster") {
10262
+ const rasterMetadata = data.raster_metadata;
10263
+ if (!rasterMetadata) {
10264
+ return {
10265
+ channelProps: {},
10266
+ scales: {}
10267
+ };
10268
+ }
10269
+ const rasterStyleType = config2.visConfig.rasterStyleType;
10270
+ if (rasterStyleType === "Rgb") {
10271
+ return {
10272
+ channelProps: getRasterTileLayerStylePropsRgb({
10273
+ layerConfig: config2,
10274
+ rasterMetadata,
10275
+ visualChannels
10276
+ }),
10277
+ scales: {}
10278
+ // TODO
10279
+ };
10280
+ } else {
10281
+ return {
10282
+ channelProps: getRasterTileLayerStylePropsScaledBand({
10283
+ layerConfig: config2,
10284
+ visualChannels,
10285
+ rasterMetadata
10286
+ }),
10287
+ scales: {
10288
+ // TODO
10289
+ }
10290
+ };
10291
+ }
10292
+ }
9485
10293
  const { textLabel, visConfig } = config2;
9486
10294
  const result = {};
10295
+ const updateTriggers = {};
9487
10296
  const scales = {};
9488
- if (colorField) {
9489
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
9490
- const { accessor, scale: scale2 } = getColorAccessor(
9491
- colorField,
9492
- colorScale,
9493
- { aggregation, range },
9494
- visConfig.opacity,
9495
- data
9496
- );
9497
- result.getFillColor = accessor;
9498
- scales.fillColor = {
9499
- field: colorField,
9500
- type: colorScale,
9501
- ...domainAndRangeFromScale(scale2)
9502
- };
9503
- } else if (visConfig.filled) {
9504
- scales.fillColor = {};
10297
+ {
10298
+ const { colorField, colorScale } = visualChannels;
10299
+ const { colorRange, colorAggregation } = visConfig;
10300
+ if (colorField && colorScale && colorRange) {
10301
+ const { accessor, ...scaleProps } = getColorAccessor(
10302
+ colorField,
10303
+ colorScale,
10304
+ { aggregation: colorAggregation, range: colorRange },
10305
+ visConfig.opacity,
10306
+ data
10307
+ );
10308
+ result.getFillColor = accessor;
10309
+ scales.fillColor = updateTriggers.getFillColor = {
10310
+ field: colorField,
10311
+ type: colorScale,
10312
+ ...scaleProps
10313
+ };
10314
+ } else {
10315
+ scales.fillColor = {};
10316
+ }
9505
10317
  }
9506
10318
  if (layerType === "clusterTile") {
9507
10319
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -9514,6 +10326,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9514
10326
  result.getWeight = (d) => {
9515
10327
  return d.properties[aggregationExpAlias];
9516
10328
  };
10329
+ updateTriggers.getWeight = aggregationExpAlias;
9517
10330
  result.getPointRadius = (d, info) => {
9518
10331
  return calculateClusterRadius(
9519
10332
  d.properties,
@@ -9522,11 +10335,16 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9522
10335
  aggregationExpAlias
9523
10336
  );
9524
10337
  };
10338
+ updateTriggers.getPointRadius = {
10339
+ aggregationExpAlias,
10340
+ radiusRange: visConfig.radiusRange
10341
+ };
9525
10342
  result.textCharacterSet = "auto";
9526
10343
  result.textFontFamily = "Inter, sans";
9527
10344
  result.textFontSettings = { sdf: true };
9528
10345
  result.textFontWeight = 600;
9529
10346
  result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
10347
+ updateTriggers.getText = aggregationExpAlias;
9530
10348
  result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
9531
10349
  result.textOutlineColor = [
9532
10350
  ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
@@ -9543,68 +10361,107 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9543
10361
  );
9544
10362
  return calculateClusterTextFontSize(radius);
9545
10363
  };
9546
- }
9547
- if (radiusField) {
9548
- const { accessor, scale: scale2 } = getSizeAccessor(
9549
- radiusField,
9550
- radiusScale,
9551
- visConfig.sizeAggregation,
9552
- visConfig.radiusRange || visConfig.sizeRange,
9553
- data
9554
- );
9555
- result.getPointRadius = accessor;
9556
- scales.pointRadius = {
9557
- field: radiusField,
9558
- type: radiusScale || "identity",
9559
- ...domainAndRangeFromScale(scale2)
10364
+ updateTriggers.getTextSize = {
10365
+ aggregationExpAlias,
10366
+ radiusRange: visConfig.radiusRange
9560
10367
  };
9561
10368
  }
9562
- if (strokeColorField) {
9563
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
9564
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
9565
- const { accessor, scale: scale2 } = getColorAccessor(
9566
- strokeColorField,
9567
- strokeColorScale,
9568
- { aggregation, range },
9569
- opacity,
9570
- data
9571
- );
9572
- result.getLineColor = accessor;
9573
- scales.lineColor = {
9574
- field: strokeColorField,
9575
- type: strokeColorScale,
9576
- ...domainAndRangeFromScale(scale2)
9577
- };
10369
+ {
10370
+ const radiusRange = visConfig.radiusRange;
10371
+ const { radiusField, radiusScale } = visualChannels;
10372
+ if (radiusField && radiusRange && radiusScale) {
10373
+ const { accessor, ...scaleProps } = getSizeAccessor(
10374
+ radiusField,
10375
+ radiusScale,
10376
+ visConfig.sizeAggregation,
10377
+ radiusRange,
10378
+ data
10379
+ );
10380
+ result.getPointRadius = accessor;
10381
+ scales.pointRadius = updateTriggers.getPointRadius = {
10382
+ field: radiusField,
10383
+ type: radiusScale,
10384
+ ...scaleProps
10385
+ };
10386
+ }
9578
10387
  }
9579
- if (heightField && visConfig.enable3d) {
9580
- const { accessor, scale: scale2 } = getSizeAccessor(
9581
- heightField,
9582
- heightScale,
9583
- visConfig.heightAggregation,
9584
- visConfig.heightRange || visConfig.sizeRange,
9585
- data
9586
- );
9587
- result.getElevation = accessor;
9588
- scales.elevation = {
9589
- field: heightField,
9590
- type: heightScale || "identity",
9591
- ...domainAndRangeFromScale(scale2)
9592
- };
10388
+ {
10389
+ const strokeColorRange = visConfig.strokeColorRange;
10390
+ const { strokeColorScale, strokeColorField } = visualChannels;
10391
+ if (strokeColorField && strokeColorRange && strokeColorScale) {
10392
+ const { strokeColorAggregation: aggregation } = visConfig;
10393
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10394
+ const { accessor, ...scaleProps } = getColorAccessor(
10395
+ strokeColorField,
10396
+ strokeColorScale,
10397
+ { aggregation, range: strokeColorRange },
10398
+ opacity,
10399
+ data
10400
+ );
10401
+ result.getLineColor = accessor;
10402
+ scales.lineColor = updateTriggers.getLineColor = {
10403
+ field: strokeColorField,
10404
+ type: strokeColorScale,
10405
+ ...scaleProps
10406
+ };
10407
+ }
9593
10408
  }
9594
- if (weightField) {
9595
- const { accessor, scale: scale2 } = getSizeAccessor(
9596
- weightField,
9597
- void 0,
9598
- visConfig.weightAggregation,
9599
- void 0,
9600
- data
9601
- );
9602
- result.getWeight = accessor;
9603
- scales.weight = {
9604
- field: weightField,
9605
- type: "identity",
9606
- ...domainAndRangeFromScale(scale2)
9607
- };
10409
+ {
10410
+ const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10411
+ const { sizeRange, sizeAggregation } = visConfig;
10412
+ if (strokeWidthField && sizeRange) {
10413
+ const { accessor, ...scaleProps } = getSizeAccessor(
10414
+ strokeWidthField,
10415
+ strokeWidthScale,
10416
+ sizeAggregation,
10417
+ sizeRange,
10418
+ data
10419
+ );
10420
+ result.getLineWidth = accessor;
10421
+ scales.lineWidth = updateTriggers.getLineWidth = {
10422
+ field: strokeWidthField,
10423
+ type: strokeWidthScale || "identity",
10424
+ ...scaleProps
10425
+ };
10426
+ }
10427
+ }
10428
+ {
10429
+ const { enable3d, heightRange } = visConfig;
10430
+ const { heightField, heightScale } = visualChannels;
10431
+ if (heightField && heightRange && enable3d) {
10432
+ const { accessor, ...scaleProps } = getSizeAccessor(
10433
+ heightField,
10434
+ heightScale,
10435
+ visConfig.heightAggregation,
10436
+ heightRange,
10437
+ data
10438
+ );
10439
+ result.getElevation = accessor;
10440
+ scales.elevation = updateTriggers.getElevation = {
10441
+ field: heightField,
10442
+ type: heightScale || "identity",
10443
+ ...scaleProps
10444
+ };
10445
+ }
10446
+ }
10447
+ {
10448
+ const { weightField } = visualChannels;
10449
+ const { weightAggregation } = visConfig;
10450
+ if (weightField && weightAggregation) {
10451
+ const { accessor, ...scaleProps } = getSizeAccessor(
10452
+ weightField,
10453
+ void 0,
10454
+ weightAggregation,
10455
+ void 0,
10456
+ data
10457
+ );
10458
+ result.getWeight = accessor;
10459
+ scales.weight = updateTriggers.getWeight = {
10460
+ field: weightField,
10461
+ type: "identity",
10462
+ ...scaleProps
10463
+ };
10464
+ }
9608
10465
  }
9609
10466
  if (visConfig.customMarkers) {
9610
10467
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -9621,6 +10478,12 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9621
10478
  { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons },
9622
10479
  data
9623
10480
  );
10481
+ updateTriggers.getIcon = {
10482
+ customMarkersUrl,
10483
+ customMarkersRange,
10484
+ maxIconSize,
10485
+ useMaskedIcons
10486
+ };
9624
10487
  result._subLayerProps = {
9625
10488
  "points-icon": {
9626
10489
  loadOptions: {
@@ -9637,9 +10500,11 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9637
10500
  };
9638
10501
  if (getFillColor && useMaskedIcons) {
9639
10502
  result.getIconColor = getFillColor;
10503
+ updateTriggers.getIconColor = updateTriggers.getFillColor;
9640
10504
  }
9641
10505
  if (getPointRadius) {
9642
10506
  result.getIconSize = getPointRadius;
10507
+ updateTriggers.getIconSize = updateTriggers.getPointRadius;
9643
10508
  }
9644
10509
  if (visualChannels.rotationField) {
9645
10510
  const { accessor } = getSizeAccessor(
@@ -9650,6 +10515,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9650
10515
  data
9651
10516
  );
9652
10517
  result.getIconAngle = negateAccessor(accessor);
10518
+ updateTriggers.getIconAngle = updateTriggers.getRotationField;
9653
10519
  }
9654
10520
  } else if (layerType === "tileset") {
9655
10521
  result.pointType = "circle";
@@ -9694,7 +10560,13 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9694
10560
  }
9695
10561
  };
9696
10562
  }
9697
- return { channelProps: result, scales };
10563
+ return {
10564
+ channelProps: {
10565
+ ...result,
10566
+ updateTriggers
10567
+ },
10568
+ scales
10569
+ };
9698
10570
  }
9699
10571
  function createLoadOptions(accessToken) {
9700
10572
  return {
@@ -10341,9 +11213,16 @@ export {
10341
11213
  WidgetSource,
10342
11214
  WidgetTableSource,
10343
11215
  WidgetTilesetSource,
11216
+ ErrorCode as _ErrorCode,
11217
+ applyLayerGroupFilters as _applyLayerGroupFilters,
10344
11218
  _buildFeatureFilter,
11219
+ createVecExprEvaluator as _createVecExprEvaluator,
10345
11220
  domainFromValues as _domainFromValues,
11221
+ evaluateVecExpr as _evaluateVecExpr,
10346
11222
  _getHexagonResolution,
11223
+ getLog10ScaleSteps as _getLog10ScaleSteps,
11224
+ getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps,
11225
+ validateVecExprSyntax as _validateVecExprSyntax,
10347
11226
  addFilter,
10348
11227
  aggregate,
10349
11228
  aggregationFunctions,
@@ -10356,9 +11235,11 @@ export {
10356
11235
  buildStatsUrl,
10357
11236
  calculateClusterRadius,
10358
11237
  calculateClusterTextFontSize,
11238
+ calculateLayerScale,
10359
11239
  clearDefaultRequestCache,
10360
11240
  clearFilters,
10361
11241
  configureSource,
11242
+ createColorScale,
10362
11243
  createPolygonSpatialFilter,
10363
11244
  createViewportSpatialFilter,
10364
11245
  fetchBasemapProps,
@@ -10373,6 +11254,7 @@ export {
10373
11254
  getDefaultAggregationExpColumnAliasForLayerType,
10374
11255
  getFilter,
10375
11256
  getIconUrlAccessor,
11257
+ getLayerDescriptor,
10376
11258
  getLayerProps,
10377
11259
  getMaxMarkerSize,
10378
11260
  getSizeAccessor,