@carto/api-client 0.5.16 → 0.5.18-alpha.colormapfix-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8500,6 +8500,250 @@ var basemap_styles_default = {
8500
8500
  DARK_MATTER_NOLABELS: getStyleUrl("dark-matter-nolabels")
8501
8501
  };
8502
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
+
8503
8747
  // node_modules/d3-array/src/ascending.js
8504
8748
  function ascending(a, b) {
8505
8749
  return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
@@ -9078,6 +9322,37 @@ function formatDate(value) {
9078
9322
  function formatTimestamp(value) {
9079
9323
  return String(Math.floor(new Date(value).getTime() / 1e3));
9080
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
+ }
9081
9356
 
9082
9357
  // src/fetch-map/layer-map.ts
9083
9358
  var SCALE_FUNCS = {
@@ -9094,7 +9369,19 @@ var SCALE_FUNCS = {
9094
9369
  function identity2(v2) {
9095
9370
  return v2;
9096
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
+ };
9097
9383
  var UNKNOWN_COLOR = "#868d91";
9384
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9098
9385
  var OPACITY_MAP = {
9099
9386
  getFillColor: "opacity",
9100
9387
  getLineColor: "strokeOpacity",
@@ -9127,6 +9414,12 @@ var sharedPropMap = {
9127
9414
  wireframe: "wireframe"
9128
9415
  }
9129
9416
  };
9417
+ var rasterPropsMap = {
9418
+ isVisible: "visible",
9419
+ visConfig: {
9420
+ opacity: "opacity"
9421
+ }
9422
+ };
9130
9423
  var customMarkersPropsMap = {
9131
9424
  color: "getIconColor",
9132
9425
  visConfig: {
@@ -9170,6 +9463,12 @@ function getLayerProps(type, config2, dataset) {
9170
9463
  `Outdated layer type: ${type}. Please open map in CARTO Builder to automatically migrate.`
9171
9464
  );
9172
9465
  }
9466
+ if (type === "raster") {
9467
+ return {
9468
+ propMap: rasterPropsMap,
9469
+ defaultProps: {}
9470
+ };
9471
+ }
9173
9472
  let basePropMap = sharedPropMap;
9174
9473
  if (config2.visConfig?.customMarkers) {
9175
9474
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -9190,16 +9489,19 @@ function getLayerProps(type, config2, dataset) {
9190
9489
  }
9191
9490
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9192
9491
  if (scaleType === "ordinal" || scaleType === "point") {
9492
+ if (!attribute.categories) {
9493
+ return [0, 1];
9494
+ }
9193
9495
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9194
9496
  }
9195
9497
  if (scaleType === "quantile" && attribute.quantiles) {
9196
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9498
+ return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9197
9499
  }
9198
9500
  let { min: min2 } = attribute;
9199
9501
  if (scaleType === "log" && min2 === 0) {
9200
9502
  min2 = 1e-5;
9201
9503
  }
9202
- return [min2, attribute.max];
9504
+ return [min2 ?? 0, attribute.max ?? 1];
9203
9505
  }
9204
9506
  function domainFromValues(values, scaleType) {
9205
9507
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9220,12 +9522,14 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9220
9522
  if (data.tilestats) {
9221
9523
  const { attributes } = data.tilestats.layers[0];
9222
9524
  const attribute = attributes.find((a) => a.attribute === name);
9223
- return domainFromAttribute(attribute, scaleType, scaleLength);
9525
+ if (attribute) {
9526
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9527
+ }
9224
9528
  }
9225
9529
  return [0, 1];
9226
9530
  }
9227
9531
  function normalizeAccessor(accessor, data) {
9228
- if (data.features || data.tilestats) {
9532
+ if (data.features || data.tilestats || data.raster_metadata) {
9229
9533
  return (object, info) => {
9230
9534
  if (object) {
9231
9535
  return accessor(object.properties || object.__source.object.properties);
@@ -9258,46 +9562,78 @@ function findAccessorKey(keys, properties) {
9258
9562
  return keys;
9259
9563
  }
9260
9564
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9261
- const scale2 = calculateLayerScale(
9565
+ const { scale: scale2, domain } = calculateLayerScale(
9262
9566
  colorColumn || name,
9263
- scaleType,
9567
+ colorColumn ? "identity" : scaleType,
9264
9568
  range,
9265
9569
  data
9266
9570
  );
9267
9571
  const alpha = opacityToAlpha(opacity);
9268
- let accessorKeys = getAccessorKeys(name, aggregation);
9572
+ let accessorKeys = getAccessorKeys(colorColumn || name, aggregation);
9269
9573
  const accessor = (properties) => {
9270
9574
  if (!(accessorKeys[0] in properties)) {
9271
9575
  accessorKeys = findAccessorKey(accessorKeys, properties);
9272
9576
  }
9273
9577
  const propertyValue = properties[accessorKeys[0]];
9274
- const { r, g, b } = rgb(scale2(propertyValue));
9275
- 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)
9276
9587
  };
9277
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9278
9588
  }
9279
9589
  function calculateLayerScale(name, scaleType, range, data) {
9280
- const scale2 = SCALE_FUNCS[scaleType]();
9281
9590
  let domain = [];
9591
+ let scaleDomain;
9282
9592
  let scaleColor = [];
9593
+ const { colors } = range;
9283
9594
  if (scaleType !== "identity") {
9284
- const { colorMap, colors } = range;
9285
- if (Array.isArray(colorMap)) {
9595
+ if (range.colorMap) {
9596
+ const { colorMap } = range;
9597
+ scaleDomain = [];
9286
9598
  colorMap.forEach(([value, color2]) => {
9287
- domain.push(value);
9599
+ scaleDomain.push(value);
9288
9600
  scaleColor.push(color2);
9289
9601
  });
9602
+ domain = scaleDomain;
9290
9603
  } else {
9291
- domain = calculateDomain(data, name, scaleType, colors.length);
9292
- scaleColor = colors;
9604
+ if (scaleType === "custom" && range.uiCustomScaleType === "logarithmic") {
9605
+ domain = calculateDomain(data, name, scaleType, colors.length);
9606
+ const [min2, max2] = domain;
9607
+ scaleDomain = getLog10ScaleSteps({
9608
+ min: min2,
9609
+ max: max2,
9610
+ steps: colors.length
9611
+ });
9612
+ scaleColor = colors;
9613
+ } else {
9614
+ domain = calculateDomain(data, name, scaleType, colors.length);
9615
+ scaleColor = colors;
9616
+ }
9293
9617
  }
9294
9618
  if (scaleType === "ordinal") {
9295
9619
  domain = domain.slice(0, scaleColor.length);
9296
9620
  }
9297
9621
  }
9622
+ return {
9623
+ scale: createColorScale(
9624
+ scaleType,
9625
+ scaleDomain || domain,
9626
+ scaleColor.map(hexToRGB),
9627
+ UNKNOWN_COLOR_RGB
9628
+ ),
9629
+ domain
9630
+ };
9631
+ }
9632
+ function createColorScale(scaleType, domain, range, unknown) {
9633
+ const scale2 = SCALE_FUNCS[scaleType]();
9298
9634
  scale2.domain(domain);
9299
- scale2.range(scaleColor);
9300
- scale2.unknown(UNKNOWN_COLOR);
9635
+ scale2.range(range);
9636
+ scale2.unknown(unknown);
9301
9637
  return scale2;
9302
9638
  }
9303
9639
  var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
@@ -9347,9 +9683,13 @@ function negateAccessor(accessor) {
9347
9683
  }
9348
9684
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9349
9685
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9350
- if (scaleType) {
9686
+ let domain = [];
9687
+ if (scaleType && range) {
9351
9688
  if (aggregation !== AggregationTypes.Count) {
9352
- scale2.domain(calculateDomain(data, name, scaleType));
9689
+ domain = calculateDomain(data, name, scaleType);
9690
+ scale2.domain(domain);
9691
+ } else {
9692
+ domain = scale2.domain();
9353
9693
  }
9354
9694
  scale2.range(range);
9355
9695
  }
@@ -9361,7 +9701,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9361
9701
  const propertyValue = properties[accessorKeys[0]];
9362
9702
  return scale2(propertyValue);
9363
9703
  };
9364
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9704
+ return {
9705
+ accessor: normalizeAccessor(accessor, data),
9706
+ domain,
9707
+ scaleDomain: domain,
9708
+ range
9709
+ };
9365
9710
  }
9366
9711
  var FORMATS = {
9367
9712
  date: formatDate,
@@ -9412,13 +9757,420 @@ function calculateClusterTextFontSize(radius) {
9412
9757
  return 11;
9413
9758
  }
9414
9759
 
9760
+ // src/fetch-map/raster-layer.ts
9761
+ var UNKNOWN_COLOR2 = [134, 141, 145];
9762
+ var RASTER_COLOR_BANDS = ["red", "green", "blue"];
9763
+ function getHasDataPredicate(noData) {
9764
+ if (noData === "nan") {
9765
+ return (v2) => !isNaN(v2);
9766
+ }
9767
+ if (typeof noData === "string") {
9768
+ noData = parseFloat(noData);
9769
+ }
9770
+ if (typeof noData === "number") {
9771
+ return (v2) => v2 !== noData && !isNaN(v2);
9772
+ }
9773
+ return () => true;
9774
+ }
9775
+ function createRasterColumnLayerDataTransform(transform) {
9776
+ return (data) => {
9777
+ if (!data || !("data" in data) || !data?.data?.cells?.numericProps) {
9778
+ return data;
9779
+ }
9780
+ return transform(data);
9781
+ };
9782
+ }
9783
+ function createEvaluationContext(numericProps, noData) {
9784
+ const hasData = getHasDataPredicate(noData);
9785
+ const bands = Object.entries(numericProps).map(([bandName, { value }]) => ({
9786
+ bandName,
9787
+ values: value,
9788
+ copied: false
9789
+ }));
9790
+ const length2 = bands[0].values.length;
9791
+ for (let i = 0; i < length2; i++) {
9792
+ let hasSomeData = false;
9793
+ for (let j = 0; j < bands.length; j++) {
9794
+ hasSomeData = hasSomeData || hasData(bands[j].values[i]);
9795
+ }
9796
+ if (!hasSomeData) {
9797
+ for (let j = 0; j < bands.length; j++) {
9798
+ if (!bands[j].copied) {
9799
+ bands[j].copied = true;
9800
+ bands[j].values = Array.from(bands[j].values);
9801
+ }
9802
+ bands[j].values[i] = NaN;
9803
+ }
9804
+ }
9805
+ }
9806
+ const context = bands.reduce(
9807
+ (agg, { bandName, values }) => {
9808
+ agg[bandName] = values;
9809
+ return agg;
9810
+ },
9811
+ {}
9812
+ );
9813
+ return context;
9814
+ }
9815
+ function createExprDataTransform({
9816
+ colorBand,
9817
+ rasterMetadata,
9818
+ usedSymbols
9819
+ }) {
9820
+ if (!colorBand || !colorBand.type || colorBand.type === "none") {
9821
+ return void 0;
9822
+ }
9823
+ const expr = colorBand?.type === "expression" ? colorBand.value : void 0;
9824
+ const vecExprEvaluator = expr ? createVecExprEvaluator(expr) : void 0;
9825
+ const dataTransform = createRasterColumnLayerDataTransform(
9826
+ (dataWrapped) => {
9827
+ const data = dataWrapped.data;
9828
+ if (expr) {
9829
+ const cachedResult = dataWrapped.customExpressionResults?.[expr];
9830
+ if (cachedResult) {
9831
+ return dataWrapped;
9832
+ }
9833
+ }
9834
+ let context = dataWrapped.expressionEvalContext;
9835
+ if (!context) {
9836
+ const usedNumericProps = usedSymbols.reduce(
9837
+ (acc, symbol) => {
9838
+ acc[symbol] = data.cells.numericProps[symbol];
9839
+ return acc;
9840
+ },
9841
+ {}
9842
+ );
9843
+ context = createEvaluationContext(
9844
+ usedNumericProps,
9845
+ rasterMetadata.nodata
9846
+ );
9847
+ dataWrapped = {
9848
+ ...dataWrapped,
9849
+ expressionEvalContext: context
9850
+ };
9851
+ }
9852
+ if (!vecExprEvaluator || !expr) return dataWrapped;
9853
+ const evalResult = vecExprEvaluator(context);
9854
+ return {
9855
+ ...dataWrapped,
9856
+ customExpressionResults: {
9857
+ ...dataWrapped.customExpressionResults,
9858
+ [expr]: evalResult
9859
+ }
9860
+ };
9861
+ }
9862
+ );
9863
+ return dataTransform;
9864
+ }
9865
+ function combineDataTransforms(dataTransforms) {
9866
+ const actualTransforms = dataTransforms.filter((v2) => v2);
9867
+ if (actualTransforms.length === 0) return void 0;
9868
+ if (actualTransforms.length === 1) return actualTransforms[0];
9869
+ return (data) => actualTransforms.reduce(
9870
+ (aggData, transformFun) => transformFun(aggData),
9871
+ data
9872
+ );
9873
+ }
9874
+ function createRgbToColorBufferDataTransform({
9875
+ bandDefs,
9876
+ attribute
9877
+ }) {
9878
+ return createRasterColumnLayerDataTransform(
9879
+ (dataWrapped) => {
9880
+ const length2 = dataWrapped.length;
9881
+ const getBandBufferOrValue = (colorBand) => {
9882
+ if (colorBand?.type === "expression") {
9883
+ return dataWrapped.customExpressionResults?.[colorBand.value];
9884
+ }
9885
+ if (colorBand?.type === "band") {
9886
+ return dataWrapped.expressionEvalContext?.[colorBand.value];
9887
+ }
9888
+ return 0;
9889
+ };
9890
+ const red = getBandBufferOrValue(bandDefs.red);
9891
+ const green = getBandBufferOrValue(bandDefs.green);
9892
+ const blue = getBandBufferOrValue(bandDefs.blue);
9893
+ const colorBuffer = new Uint8Array(length2 * 4);
9894
+ for (let inputIndex = 0, outputIndex = 0; inputIndex < length2; inputIndex++, outputIndex += 4) {
9895
+ const redRaw = typeof red === "number" ? red : red ? red[inputIndex] : NaN;
9896
+ const greenRaw = typeof green === "number" ? green : green ? green[inputIndex] : NaN;
9897
+ const blueRaw = typeof blue === "number" ? blue : blue ? blue[inputIndex] : NaN;
9898
+ if (isNaN(redRaw) && isNaN(greenRaw) && isNaN(blueRaw)) {
9899
+ bufferSetRgba(colorBuffer, outputIndex, 0, 0, 0, 0);
9900
+ } else {
9901
+ bufferSetRgba(
9902
+ colorBuffer,
9903
+ outputIndex,
9904
+ redRaw,
9905
+ greenRaw,
9906
+ blueRaw,
9907
+ 255
9908
+ );
9909
+ }
9910
+ }
9911
+ dataWrapped.customExpressionResults = void 0;
9912
+ dataWrapped.expressionEvalContext = void 0;
9913
+ return {
9914
+ ...dataWrapped,
9915
+ attributes: {
9916
+ [attribute]: colorBuffer
9917
+ }
9918
+ };
9919
+ }
9920
+ );
9921
+ }
9922
+ function getUsedSymbols(colorBands) {
9923
+ return Array.from(
9924
+ colorBands.reduce((symbols, band) => {
9925
+ if (band.type === "expression") {
9926
+ const expressionSymbols = createVecExprEvaluator(band.value)?.symbols || [];
9927
+ expressionSymbols.forEach((symbol) => symbols.add(symbol));
9928
+ }
9929
+ if (band.type === "band") {
9930
+ symbols.add(band.value);
9931
+ }
9932
+ return symbols;
9933
+ }, /* @__PURE__ */ new Set())
9934
+ );
9935
+ }
9936
+ function getRasterTileLayerStylePropsRgb({
9937
+ layerConfig,
9938
+ rasterMetadata,
9939
+ visualChannels
9940
+ }) {
9941
+ const { visConfig } = layerConfig;
9942
+ const { colorBands } = visConfig;
9943
+ const bandDefs = {
9944
+ red: colorBands?.find((band) => band.band === "red"),
9945
+ green: colorBands?.find((band) => band.band === "green"),
9946
+ blue: colorBands?.find((band) => band.band === "blue")
9947
+ };
9948
+ const rgbToInstanceFillColorsDataTransform = createRgbToColorBufferDataTransform({
9949
+ bandDefs,
9950
+ attribute: "instanceFillColors"
9951
+ });
9952
+ const usedSymbols = colorBands ? getUsedSymbols(colorBands) : [];
9953
+ const bandTransforms = RASTER_COLOR_BANDS.map(
9954
+ (band) => createExprDataTransform({
9955
+ colorBand: bandDefs[band],
9956
+ rasterMetadata,
9957
+ usedSymbols
9958
+ })
9959
+ );
9960
+ const combinedDataTransform = combineDataTransforms([
9961
+ ...bandTransforms,
9962
+ rgbToInstanceFillColorsDataTransform
9963
+ ]);
9964
+ return {
9965
+ dataTransform: combinedDataTransform,
9966
+ updateTriggers: getRasterTileLayerUpdateTriggers({
9967
+ layerConfig,
9968
+ visualChannels
9969
+ })
9970
+ };
9971
+ }
9972
+ function createBandColorScaleDataTransform({
9973
+ bandName,
9974
+ scaleFun,
9975
+ nodata,
9976
+ attribute
9977
+ }) {
9978
+ const hasData = getHasDataPredicate(nodata);
9979
+ return createRasterColumnLayerDataTransform(
9980
+ (dataWrapped) => {
9981
+ const length2 = dataWrapped.length;
9982
+ const bandBuffer = dataWrapped.data.cells.numericProps[bandName].value;
9983
+ const colorBuffer = new Uint8Array(length2 * 4);
9984
+ for (let i = 0; i < length2; i++) {
9985
+ const rawValue = bandBuffer[i];
9986
+ if (!hasData(rawValue)) {
9987
+ bufferSetRgba(colorBuffer, i * 4, 0, 0, 0, 0);
9988
+ } else {
9989
+ const colorRgb = scaleFun(rawValue);
9990
+ bufferSetRgba(
9991
+ colorBuffer,
9992
+ i * 4,
9993
+ colorRgb[0],
9994
+ colorRgb[1],
9995
+ colorRgb[2],
9996
+ 255
9997
+ );
9998
+ }
9999
+ }
10000
+ return {
10001
+ ...dataWrapped,
10002
+ attributes: {
10003
+ [attribute]: colorBuffer
10004
+ }
10005
+ };
10006
+ }
10007
+ );
10008
+ }
10009
+ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10010
+ if (scaleType === "ordinal") {
10011
+ return colorRange.colorMap?.map(([value]) => value) || [];
10012
+ }
10013
+ if (scaleType === "custom") {
10014
+ if (colorRange.uiCustomScaleType === "logarithmic") {
10015
+ return getLog10ScaleSteps({
10016
+ min: band.stats.min,
10017
+ max: band.stats.max,
10018
+ steps: colorRange.colors.length
10019
+ });
10020
+ } else {
10021
+ return colorRange.colorMap?.map(([value]) => value) || [];
10022
+ }
10023
+ }
10024
+ const scaleLength = colorRange.colors.length;
10025
+ if (scaleType === "quantile") {
10026
+ const quantiles = band.stats.quantiles?.[scaleLength];
10027
+ if (!quantiles) {
10028
+ return [0, 1];
10029
+ }
10030
+ return [band.stats.min, ...quantiles, band.stats.max];
10031
+ }
10032
+ return [band.stats.min, band.stats.max];
10033
+ }
10034
+ function getRasterTileLayerStylePropsScaledBand({
10035
+ layerConfig,
10036
+ rasterMetadata,
10037
+ visualChannels
10038
+ }) {
10039
+ const { visConfig } = layerConfig;
10040
+ const { colorField } = visualChannels;
10041
+ const { rasterStyleType } = visConfig;
10042
+ const colorRange = rasterStyleType === "ColorRange" ? visConfig.colorRange : visConfig.uniqueValuesColorRange;
10043
+ const scaleType = rasterStyleType === "ColorRange" ? visualChannels.colorScale : "ordinal";
10044
+ const bandInfo = rasterMetadata.bands.find(
10045
+ (band) => band.name === colorField?.name
10046
+ );
10047
+ if (!colorField?.name || !scaleType || !colorRange || !bandInfo) {
10048
+ return {};
10049
+ }
10050
+ const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
10051
+ const scaleFun = createColorScale(
10052
+ scaleType,
10053
+ domain,
10054
+ colorRange.colors.map(hexToRGB2),
10055
+ UNKNOWN_COLOR2
10056
+ );
10057
+ const bandColorScaleDataTransform = createBandColorScaleDataTransform({
10058
+ bandName: bandInfo.name,
10059
+ scaleFun,
10060
+ nodata: bandInfo?.nodata ?? rasterMetadata.nodata,
10061
+ attribute: "instanceFillColors"
10062
+ });
10063
+ return {
10064
+ dataTransform: bandColorScaleDataTransform,
10065
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10066
+ layerConfig,
10067
+ visualChannels
10068
+ })
10069
+ };
10070
+ }
10071
+ function getRasterTileLayerStyleProps({
10072
+ layerConfig,
10073
+ visualChannels,
10074
+ rasterMetadata
10075
+ }) {
10076
+ const { visConfig } = layerConfig;
10077
+ const { rasterStyleType } = visConfig;
10078
+ if (rasterStyleType === "Rgb") {
10079
+ return getRasterTileLayerStylePropsRgb({
10080
+ layerConfig,
10081
+ rasterMetadata,
10082
+ visualChannels
10083
+ });
10084
+ } else {
10085
+ return getRasterTileLayerStylePropsScaledBand({
10086
+ layerConfig,
10087
+ rasterMetadata,
10088
+ visualChannels
10089
+ });
10090
+ }
10091
+ }
10092
+ function getRasterTileLayerUpdateTriggers({
10093
+ layerConfig,
10094
+ visualChannels
10095
+ }) {
10096
+ const { visConfig } = layerConfig;
10097
+ const { rasterStyleType } = visConfig;
10098
+ const getFillColorUpdateTriggers = {
10099
+ rasterStyleType
10100
+ };
10101
+ if (rasterStyleType === "ColorRange") {
10102
+ getFillColorUpdateTriggers.colorRange = visConfig.colorRange?.colors;
10103
+ getFillColorUpdateTriggers.colorMap = visConfig.colorRange?.colorMap;
10104
+ getFillColorUpdateTriggers.colorScale = visualChannels.colorScale;
10105
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10106
+ } else if (rasterStyleType === "UniqueValues") {
10107
+ getFillColorUpdateTriggers.colorMap = visConfig.uniqueValuesColorRange?.colorMap;
10108
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10109
+ } else if (rasterStyleType === "Rgb") {
10110
+ getFillColorUpdateTriggers.colorBands = visConfig.colorBands;
10111
+ }
10112
+ return {
10113
+ getFillColor: getFillColorUpdateTriggers
10114
+ };
10115
+ }
10116
+ function bufferSetRgba(target, index, r, g, b, a) {
10117
+ target[index + 0] = r;
10118
+ target[index + 1] = g;
10119
+ target[index + 2] = b;
10120
+ target[index + 3] = a;
10121
+ }
10122
+ function hexToRGB2(hexColor) {
10123
+ const r = parseInt(hexColor.slice(1, 3), 16);
10124
+ const g = parseInt(hexColor.slice(3, 5), 16);
10125
+ const b = parseInt(hexColor.slice(5, 7), 16);
10126
+ return [r, g, b];
10127
+ }
10128
+
9415
10129
  // src/fetch-map/parse-map.ts
10130
+ function getLayerDescriptor({
10131
+ mapConfig,
10132
+ layer,
10133
+ dataset
10134
+ }) {
10135
+ const { filters, visState } = mapConfig;
10136
+ const { layerBlending, interactionConfig } = visState;
10137
+ const { id, type, config: config2, visualChannels } = layer;
10138
+ const { data, id: datasetId } = dataset;
10139
+ const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config2, dataset);
10140
+ const styleProps = createStyleProps(config2, propMap);
10141
+ const { channelProps, scales } = createChannelProps(
10142
+ id,
10143
+ type,
10144
+ config2,
10145
+ visualChannels,
10146
+ data,
10147
+ dataset
10148
+ );
10149
+ const layerDescriptor = {
10150
+ type,
10151
+ filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[datasetId],
10152
+ props: {
10153
+ id,
10154
+ data,
10155
+ ...defaultProps2,
10156
+ ...createInteractionProps(interactionConfig),
10157
+ ...styleProps,
10158
+ ...channelProps,
10159
+ ...createParametersProp(layerBlending, styleProps.parameters || {}),
10160
+ // Must come after style
10161
+ ...createLoadOptions(data.accessToken)
10162
+ },
10163
+ scales
10164
+ };
10165
+ return layerDescriptor;
10166
+ }
9416
10167
  function parseMap(json) {
9417
10168
  const { keplerMapConfig, datasets, token } = json;
9418
10169
  assert2(keplerMapConfig.version === "v1", "Only support Kepler v1");
9419
- const config2 = keplerMapConfig.config;
9420
- const { filters, mapState, mapStyle, popupSettings, legendSettings } = config2;
9421
- const { layers, layerBlending, interactionConfig } = config2.visState;
10170
+ const mapConfig = keplerMapConfig.config;
10171
+ const { mapState, mapStyle, popupSettings, legendSettings, visState } = mapConfig;
10172
+ const { layers } = visState;
10173
+ const layersReverse = [...layers].reverse();
9422
10174
  return {
9423
10175
  id: json.id,
9424
10176
  title: json.title,
@@ -9431,45 +10183,19 @@ function parseMap(json) {
9431
10183
  popupSettings,
9432
10184
  legendSettings,
9433
10185
  token,
9434
- layers: layers.reverse().map(({ id, type, config: config3, visualChannels }) => {
10186
+ layers: layersReverse.map((layer) => {
9435
10187
  try {
9436
- const { dataId } = config3;
10188
+ const { dataId } = layer.config;
9437
10189
  const dataset = datasets.find(
9438
10190
  (d) => d.id === dataId
9439
10191
  );
9440
10192
  assert2(dataset, `No dataset matching dataId: ${dataId}`);
9441
- const { data } = dataset;
9442
- assert2(data, `No data loaded for dataId: ${dataId}`);
9443
- const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config3, dataset);
9444
- const styleProps = createStyleProps(config3, propMap);
9445
- const { channelProps, scales } = createChannelProps(
9446
- id,
9447
- type,
9448
- config3,
9449
- visualChannels,
9450
- data,
10193
+ const layerDescriptor = getLayerDescriptor({
10194
+ mapConfig,
10195
+ layer,
9451
10196
  dataset
9452
- );
9453
- const layer = {
9454
- type,
9455
- filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[dataId],
9456
- props: {
9457
- id,
9458
- data,
9459
- ...defaultProps2,
9460
- ...createInteractionProps(interactionConfig),
9461
- ...styleProps,
9462
- ...channelProps,
9463
- ...createParametersProp(
9464
- layerBlending,
9465
- styleProps.parameters || {}
9466
- ),
9467
- // Must come after style
9468
- ...createLoadOptions(token)
9469
- },
9470
- scales
9471
- };
9472
- return layer;
10197
+ });
10198
+ return layerDescriptor;
9473
10199
  } catch (e) {
9474
10200
  console.error(e.message);
9475
10201
  return void 0;
@@ -9534,43 +10260,63 @@ function createStyleProps(config2, mapping) {
9534
10260
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
9535
10261
  return result;
9536
10262
  }
9537
- function domainAndRangeFromScale(scale2) {
9538
- return {
9539
- domain: scale2.domain(),
9540
- range: scale2.range()
9541
- };
9542
- }
9543
10263
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
9544
- const {
9545
- colorField,
9546
- colorScale,
9547
- radiusField,
9548
- radiusScale,
9549
- strokeColorField,
9550
- strokeColorScale,
9551
- weightField
9552
- } = visualChannels;
9553
- const { heightField, heightScale } = visualChannels;
10264
+ if (layerType === "raster") {
10265
+ const rasterMetadata = data.raster_metadata;
10266
+ if (!rasterMetadata) {
10267
+ return {
10268
+ channelProps: {},
10269
+ scales: {}
10270
+ };
10271
+ }
10272
+ const rasterStyleType = config2.visConfig.rasterStyleType;
10273
+ if (rasterStyleType === "Rgb") {
10274
+ return {
10275
+ channelProps: getRasterTileLayerStylePropsRgb({
10276
+ layerConfig: config2,
10277
+ rasterMetadata,
10278
+ visualChannels
10279
+ }),
10280
+ scales: {}
10281
+ // TODO
10282
+ };
10283
+ } else {
10284
+ return {
10285
+ channelProps: getRasterTileLayerStylePropsScaledBand({
10286
+ layerConfig: config2,
10287
+ visualChannels,
10288
+ rasterMetadata
10289
+ }),
10290
+ scales: {
10291
+ // TODO
10292
+ }
10293
+ };
10294
+ }
10295
+ }
9554
10296
  const { textLabel, visConfig } = config2;
9555
10297
  const result = {};
10298
+ const updateTriggers = {};
9556
10299
  const scales = {};
9557
- if (colorField) {
9558
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
9559
- const { accessor, scale: scale2 } = getColorAccessor(
9560
- colorField,
9561
- colorScale,
9562
- { aggregation, range },
9563
- visConfig.opacity,
9564
- data
9565
- );
9566
- result.getFillColor = accessor;
9567
- scales.fillColor = {
9568
- field: colorField,
9569
- type: colorScale,
9570
- ...domainAndRangeFromScale(scale2)
9571
- };
9572
- } else if (visConfig.filled) {
9573
- scales.fillColor = {};
10300
+ {
10301
+ const { colorField, colorScale } = visualChannels;
10302
+ const { colorRange, colorAggregation } = visConfig;
10303
+ if (colorField && colorScale && colorRange) {
10304
+ const { accessor, ...scaleProps } = getColorAccessor(
10305
+ colorField,
10306
+ colorScale,
10307
+ { aggregation: colorAggregation, range: colorRange },
10308
+ visConfig.opacity,
10309
+ data
10310
+ );
10311
+ result.getFillColor = accessor;
10312
+ scales.fillColor = updateTriggers.getFillColor = {
10313
+ field: colorField,
10314
+ type: colorScale,
10315
+ ...scaleProps
10316
+ };
10317
+ } else {
10318
+ scales.fillColor = {};
10319
+ }
9574
10320
  }
9575
10321
  if (layerType === "clusterTile") {
9576
10322
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -9583,6 +10329,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9583
10329
  result.getWeight = (d) => {
9584
10330
  return d.properties[aggregationExpAlias];
9585
10331
  };
10332
+ updateTriggers.getWeight = aggregationExpAlias;
9586
10333
  result.getPointRadius = (d, info) => {
9587
10334
  return calculateClusterRadius(
9588
10335
  d.properties,
@@ -9591,11 +10338,16 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9591
10338
  aggregationExpAlias
9592
10339
  );
9593
10340
  };
10341
+ updateTriggers.getPointRadius = {
10342
+ aggregationExpAlias,
10343
+ radiusRange: visConfig.radiusRange
10344
+ };
9594
10345
  result.textCharacterSet = "auto";
9595
10346
  result.textFontFamily = "Inter, sans";
9596
10347
  result.textFontSettings = { sdf: true };
9597
10348
  result.textFontWeight = 600;
9598
10349
  result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
10350
+ updateTriggers.getText = aggregationExpAlias;
9599
10351
  result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
9600
10352
  result.textOutlineColor = [
9601
10353
  ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
@@ -9612,68 +10364,107 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9612
10364
  );
9613
10365
  return calculateClusterTextFontSize(radius);
9614
10366
  };
9615
- }
9616
- if (radiusField) {
9617
- const { accessor, scale: scale2 } = getSizeAccessor(
9618
- radiusField,
9619
- radiusScale,
9620
- visConfig.sizeAggregation,
9621
- visConfig.radiusRange || visConfig.sizeRange,
9622
- data
9623
- );
9624
- result.getPointRadius = accessor;
9625
- scales.pointRadius = {
9626
- field: radiusField,
9627
- type: radiusScale || "identity",
9628
- ...domainAndRangeFromScale(scale2)
10367
+ updateTriggers.getTextSize = {
10368
+ aggregationExpAlias,
10369
+ radiusRange: visConfig.radiusRange
9629
10370
  };
9630
10371
  }
9631
- if (strokeColorField) {
9632
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
9633
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
9634
- const { accessor, scale: scale2 } = getColorAccessor(
9635
- strokeColorField,
9636
- strokeColorScale,
9637
- { aggregation, range },
9638
- opacity,
9639
- data
9640
- );
9641
- result.getLineColor = accessor;
9642
- scales.lineColor = {
9643
- field: strokeColorField,
9644
- type: strokeColorScale,
9645
- ...domainAndRangeFromScale(scale2)
9646
- };
10372
+ {
10373
+ const radiusRange = visConfig.radiusRange;
10374
+ const { radiusField, radiusScale } = visualChannels;
10375
+ if (radiusField && radiusRange && radiusScale) {
10376
+ const { accessor, ...scaleProps } = getSizeAccessor(
10377
+ radiusField,
10378
+ radiusScale,
10379
+ visConfig.sizeAggregation,
10380
+ radiusRange,
10381
+ data
10382
+ );
10383
+ result.getPointRadius = accessor;
10384
+ scales.pointRadius = updateTriggers.getPointRadius = {
10385
+ field: radiusField,
10386
+ type: radiusScale,
10387
+ ...scaleProps
10388
+ };
10389
+ }
9647
10390
  }
9648
- if (heightField && visConfig.enable3d) {
9649
- const { accessor, scale: scale2 } = getSizeAccessor(
9650
- heightField,
9651
- heightScale,
9652
- visConfig.heightAggregation,
9653
- visConfig.heightRange || visConfig.sizeRange,
9654
- data
9655
- );
9656
- result.getElevation = accessor;
9657
- scales.elevation = {
9658
- field: heightField,
9659
- type: heightScale || "identity",
9660
- ...domainAndRangeFromScale(scale2)
9661
- };
10391
+ {
10392
+ const strokeColorRange = visConfig.strokeColorRange;
10393
+ const { strokeColorScale, strokeColorField } = visualChannels;
10394
+ if (strokeColorField && strokeColorRange && strokeColorScale) {
10395
+ const { strokeColorAggregation: aggregation } = visConfig;
10396
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10397
+ const { accessor, ...scaleProps } = getColorAccessor(
10398
+ strokeColorField,
10399
+ strokeColorScale,
10400
+ { aggregation, range: strokeColorRange },
10401
+ opacity,
10402
+ data
10403
+ );
10404
+ result.getLineColor = accessor;
10405
+ scales.lineColor = updateTriggers.getLineColor = {
10406
+ field: strokeColorField,
10407
+ type: strokeColorScale,
10408
+ ...scaleProps
10409
+ };
10410
+ }
9662
10411
  }
9663
- if (weightField) {
9664
- const { accessor, scale: scale2 } = getSizeAccessor(
9665
- weightField,
9666
- void 0,
9667
- visConfig.weightAggregation,
9668
- void 0,
9669
- data
9670
- );
9671
- result.getWeight = accessor;
9672
- scales.weight = {
9673
- field: weightField,
9674
- type: "identity",
9675
- ...domainAndRangeFromScale(scale2)
9676
- };
10412
+ {
10413
+ const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10414
+ const { sizeRange, sizeAggregation } = visConfig;
10415
+ if (strokeWidthField && sizeRange) {
10416
+ const { accessor, ...scaleProps } = getSizeAccessor(
10417
+ strokeWidthField,
10418
+ strokeWidthScale,
10419
+ sizeAggregation,
10420
+ sizeRange,
10421
+ data
10422
+ );
10423
+ result.getLineWidth = accessor;
10424
+ scales.lineWidth = updateTriggers.getLineWidth = {
10425
+ field: strokeWidthField,
10426
+ type: strokeWidthScale || "identity",
10427
+ ...scaleProps
10428
+ };
10429
+ }
10430
+ }
10431
+ {
10432
+ const { enable3d, heightRange } = visConfig;
10433
+ const { heightField, heightScale } = visualChannels;
10434
+ if (heightField && heightRange && enable3d) {
10435
+ const { accessor, ...scaleProps } = getSizeAccessor(
10436
+ heightField,
10437
+ heightScale,
10438
+ visConfig.heightAggregation,
10439
+ heightRange,
10440
+ data
10441
+ );
10442
+ result.getElevation = accessor;
10443
+ scales.elevation = updateTriggers.getElevation = {
10444
+ field: heightField,
10445
+ type: heightScale || "identity",
10446
+ ...scaleProps
10447
+ };
10448
+ }
10449
+ }
10450
+ {
10451
+ const { weightField } = visualChannels;
10452
+ const { weightAggregation } = visConfig;
10453
+ if (weightField && weightAggregation) {
10454
+ const { accessor, ...scaleProps } = getSizeAccessor(
10455
+ weightField,
10456
+ void 0,
10457
+ weightAggregation,
10458
+ void 0,
10459
+ data
10460
+ );
10461
+ result.getWeight = accessor;
10462
+ scales.weight = updateTriggers.getWeight = {
10463
+ field: weightField,
10464
+ type: "identity",
10465
+ ...scaleProps
10466
+ };
10467
+ }
9677
10468
  }
9678
10469
  if (visConfig.customMarkers) {
9679
10470
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -9690,6 +10481,12 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9690
10481
  { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons },
9691
10482
  data
9692
10483
  );
10484
+ updateTriggers.getIcon = {
10485
+ customMarkersUrl,
10486
+ customMarkersRange,
10487
+ maxIconSize,
10488
+ useMaskedIcons
10489
+ };
9693
10490
  result._subLayerProps = {
9694
10491
  "points-icon": {
9695
10492
  loadOptions: {
@@ -9706,9 +10503,11 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9706
10503
  };
9707
10504
  if (getFillColor && useMaskedIcons) {
9708
10505
  result.getIconColor = getFillColor;
10506
+ updateTriggers.getIconColor = updateTriggers.getFillColor;
9709
10507
  }
9710
10508
  if (getPointRadius) {
9711
10509
  result.getIconSize = getPointRadius;
10510
+ updateTriggers.getIconSize = updateTriggers.getPointRadius;
9712
10511
  }
9713
10512
  if (visualChannels.rotationField) {
9714
10513
  const { accessor } = getSizeAccessor(
@@ -9719,6 +10518,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9719
10518
  data
9720
10519
  );
9721
10520
  result.getIconAngle = negateAccessor(accessor);
10521
+ updateTriggers.getIconAngle = updateTriggers.getRotationField;
9722
10522
  }
9723
10523
  } else if (layerType === "tileset") {
9724
10524
  result.pointType = "circle";
@@ -9763,7 +10563,13 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9763
10563
  }
9764
10564
  };
9765
10565
  }
9766
- return { channelProps: result, scales };
10566
+ return {
10567
+ channelProps: {
10568
+ ...result,
10569
+ updateTriggers
10570
+ },
10571
+ scales
10572
+ };
9767
10573
  }
9768
10574
  function createLoadOptions(accessToken) {
9769
10575
  return {
@@ -10410,9 +11216,16 @@ export {
10410
11216
  WidgetSource,
10411
11217
  WidgetTableSource,
10412
11218
  WidgetTilesetSource,
11219
+ ErrorCode as _ErrorCode,
11220
+ applyLayerGroupFilters as _applyLayerGroupFilters,
10413
11221
  _buildFeatureFilter,
11222
+ createVecExprEvaluator as _createVecExprEvaluator,
10414
11223
  domainFromValues as _domainFromValues,
11224
+ evaluateVecExpr as _evaluateVecExpr,
10415
11225
  _getHexagonResolution,
11226
+ getLog10ScaleSteps as _getLog10ScaleSteps,
11227
+ getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps,
11228
+ validateVecExprSyntax as _validateVecExprSyntax,
10416
11229
  addFilter,
10417
11230
  aggregate,
10418
11231
  aggregationFunctions,
@@ -10425,9 +11238,11 @@ export {
10425
11238
  buildStatsUrl,
10426
11239
  calculateClusterRadius,
10427
11240
  calculateClusterTextFontSize,
11241
+ calculateLayerScale,
10428
11242
  clearDefaultRequestCache,
10429
11243
  clearFilters,
10430
11244
  configureSource,
11245
+ createColorScale,
10431
11246
  createPolygonSpatialFilter,
10432
11247
  createViewportSpatialFilter,
10433
11248
  fetchBasemapProps,
@@ -10442,6 +11257,7 @@ export {
10442
11257
  getDefaultAggregationExpColumnAliasForLayerType,
10443
11258
  getFilter,
10444
11259
  getIconUrlAccessor,
11260
+ getLayerDescriptor,
10445
11261
  getLayerProps,
10446
11262
  getMaxMarkerSize,
10447
11263
  getSizeAccessor,