@carto/api-client 0.5.14 → 0.5.15-alpha.raster-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.
@@ -125,9 +125,15 @@ __export(src_exports, {
125
125
  WidgetSource: () => WidgetSource,
126
126
  WidgetTableSource: () => WidgetTableSource,
127
127
  WidgetTilesetSource: () => WidgetTilesetSource,
128
+ _ErrorCode: () => ErrorCode,
129
+ _applyLayerGroupFilters: () => applyLayerGroupFilters,
128
130
  _buildFeatureFilter: () => _buildFeatureFilter,
131
+ _createVecExprEvaluator: () => createVecExprEvaluator,
129
132
  _domainFromValues: () => domainFromValues,
133
+ _evaluateVecExpr: () => evaluateVecExpr,
130
134
  _getHexagonResolution: () => _getHexagonResolution,
135
+ _getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
136
+ _validateVecExprSyntax: () => validateVecExprSyntax,
131
137
  addFilter: () => addFilter,
132
138
  aggregate: () => aggregate,
133
139
  aggregationFunctions: () => aggregationFunctions,
@@ -140,9 +146,11 @@ __export(src_exports, {
140
146
  buildStatsUrl: () => buildStatsUrl,
141
147
  calculateClusterRadius: () => calculateClusterRadius,
142
148
  calculateClusterTextFontSize: () => calculateClusterTextFontSize,
149
+ calculateLayerScale: () => calculateLayerScale,
143
150
  clearDefaultRequestCache: () => clearDefaultRequestCache,
144
151
  clearFilters: () => clearFilters,
145
152
  configureSource: () => configureSource,
153
+ createColorScale: () => createColorScale,
146
154
  createPolygonSpatialFilter: () => createPolygonSpatialFilter,
147
155
  createViewportSpatialFilter: () => createViewportSpatialFilter,
148
156
  fetchBasemapProps: () => fetchBasemapProps,
@@ -157,6 +165,7 @@ __export(src_exports, {
157
165
  getDefaultAggregationExpColumnAliasForLayerType: () => getDefaultAggregationExpColumnAliasForLayerType,
158
166
  getFilter: () => getFilter,
159
167
  getIconUrlAccessor: () => getIconUrlAccessor,
168
+ getLayerDescriptor: () => getLayerDescriptor,
160
169
  getLayerProps: () => getLayerProps,
161
170
  getMaxMarkerSize: () => getMaxMarkerSize,
162
171
  getSizeAccessor: () => getSizeAccessor,
@@ -8639,11 +8648,253 @@ var basemap_styles_default = {
8639
8648
  DARK_MATTER_NOLABELS: getStyleUrl("dark-matter-nolabels")
8640
8649
  };
8641
8650
 
8642
- // src/fetch-map/fetch-map.ts
8651
+ // src/fetch-map/raster-layer.ts
8643
8652
  init_cjs_shims();
8644
8653
 
8645
- // src/fetch-map/parse-map.ts
8654
+ // src/fetch-map/vec-expr-evaluator.ts
8646
8655
  init_cjs_shims();
8656
+ var import_jsep = __toESM(require("jsep"), 1);
8657
+ function createVecExprEvaluator(expression) {
8658
+ try {
8659
+ const parsed = compile(expression);
8660
+ const evalFun = (context) => evaluate(parsed, context);
8661
+ evalFun.symbols = getSymbols(parsed);
8662
+ return evalFun;
8663
+ } catch {
8664
+ return null;
8665
+ }
8666
+ }
8667
+ function evaluateVecExpr(expression, context) {
8668
+ try {
8669
+ return createVecExprEvaluator(expression)?.(context);
8670
+ } catch {
8671
+ return null;
8672
+ }
8673
+ }
8674
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
8675
+ ErrorCode2[ErrorCode2["InvalidSyntax"] = 0] = "InvalidSyntax";
8676
+ ErrorCode2[ErrorCode2["UnknownIdentifier"] = 1] = "UnknownIdentifier";
8677
+ return ErrorCode2;
8678
+ })(ErrorCode || {});
8679
+ function validateVecExprSyntax(expression, context) {
8680
+ let parsed;
8681
+ try {
8682
+ parsed = compile(expression);
8683
+ } catch (e) {
8684
+ return {
8685
+ valid: false,
8686
+ errorCode: 0 /* InvalidSyntax */,
8687
+ errorMessage: e && "message" in e ? String(e.message) : String(e)
8688
+ };
8689
+ }
8690
+ return validate(parsed, context);
8691
+ }
8692
+ function createResultArray(typeTemplate, length2 = typeTemplate.length) {
8693
+ return new Array(length2);
8694
+ }
8695
+ function isVecLike(a) {
8696
+ return Array.isArray(a) || ArrayBuffer.isView(a);
8697
+ }
8698
+ var createBinopVec = (scalarBinOp) => (left, right) => {
8699
+ const length2 = Math.min(left.length, right.length);
8700
+ const r = createResultArray(left, length2);
8701
+ for (let i = 0; i < length2; i++) {
8702
+ r[i] = scalarBinOp(left[i], right[i]);
8703
+ }
8704
+ return r;
8705
+ };
8706
+ var createBinopVecNum = (scalarBinOp) => (left, right) => {
8707
+ const length2 = left.length;
8708
+ const r = createResultArray(left, length2);
8709
+ for (let i = 0; i < length2; i++) {
8710
+ r[i] = scalarBinOp(left[i], right);
8711
+ }
8712
+ return r;
8713
+ };
8714
+ var createBinopNumVec = (scalarBinOp) => (left, right) => {
8715
+ const length2 = right.length;
8716
+ const r = createResultArray(right, length2);
8717
+ for (let i = 0; i < length2; i++) {
8718
+ r[i] = scalarBinOp(left, right[i]);
8719
+ }
8720
+ return r;
8721
+ };
8722
+ var createUnopVec = (scalarUnop) => (a) => {
8723
+ const length2 = a.length;
8724
+ const r = createResultArray(a, length2);
8725
+ for (let i = 0; i < length2; i++) {
8726
+ r[i] = scalarUnop(a[i]);
8727
+ }
8728
+ return r;
8729
+ };
8730
+ function mapDictValues(dict, fun) {
8731
+ return Object.keys(dict).reduce(
8732
+ (acc, key) => {
8733
+ acc[key] = fun(dict[key]);
8734
+ return acc;
8735
+ },
8736
+ {}
8737
+ );
8738
+ }
8739
+ var binopsNum = {
8740
+ "||": (a, b) => a || b,
8741
+ "&&": (a, b) => a && b,
8742
+ "|": (a, b) => a | b,
8743
+ "^": (a, b) => a ^ b,
8744
+ "&": (a, b) => a & b,
8745
+ "==": (a, b) => Number(a == b),
8746
+ "!=": (a, b) => Number(a != b),
8747
+ "===": (a, b) => Number(a === b),
8748
+ "!==": (a, b) => Number(a !== b),
8749
+ "<": (a, b) => Number(a < b),
8750
+ ">": (a, b) => Number(a > b),
8751
+ "<=": (a, b) => Number(a <= b),
8752
+ ">=": (a, b) => Number(a >= b),
8753
+ "<<": (a, b) => a << b,
8754
+ ">>": (a, b) => a >> b,
8755
+ ">>>": (a, b) => a >>> b,
8756
+ "+": (a, b) => a + b,
8757
+ "-": (a, b) => a - b,
8758
+ "*": (a, b) => a * b,
8759
+ "/": (a, b) => a / b,
8760
+ "%": (a, b) => a % b
8761
+ };
8762
+ var unopsNum = {
8763
+ "-": (a) => -a,
8764
+ "+": (a) => +a,
8765
+ "~": (a) => ~a,
8766
+ "!": (a) => Number(!a)
8767
+ };
8768
+ var binopsVector = mapDictValues(binopsNum, createBinopVec);
8769
+ var binopsNumVec = mapDictValues(binopsNum, createBinopNumVec);
8770
+ var binopsVecNum = mapDictValues(binopsNum, createBinopVecNum);
8771
+ var unopsVector = mapDictValues(unopsNum, createUnopVec);
8772
+ function getBinop(operator, left, right) {
8773
+ const isLeftVec = isVecLike(left);
8774
+ const isRightVec = isVecLike(right);
8775
+ if (isLeftVec && isRightVec) {
8776
+ return binopsVector[operator];
8777
+ } else if (isLeftVec) {
8778
+ return binopsVecNum[operator];
8779
+ } else if (isRightVec) {
8780
+ return binopsNumVec[operator];
8781
+ } else {
8782
+ return binopsNum[operator];
8783
+ }
8784
+ }
8785
+ function evaluate(_node, context) {
8786
+ const node = _node;
8787
+ switch (node.type) {
8788
+ case "BinaryExpression": {
8789
+ const left = evaluate(node.left, context);
8790
+ const right = evaluate(node.right, context);
8791
+ const binopFun = getBinop(node.operator, left, right);
8792
+ return binopFun(left, right);
8793
+ }
8794
+ case "ConditionalExpression": {
8795
+ const val = evaluate(node.test, context);
8796
+ if (isVecLike(val)) {
8797
+ const length2 = val.length;
8798
+ const consequentVal = evaluate(node.consequent, context);
8799
+ const alternateVal = evaluate(node.alternate, context);
8800
+ const r = createResultArray(val);
8801
+ for (let i = 0; i < length2; i++) {
8802
+ const entryVal = val[i] ? consequentVal : alternateVal;
8803
+ r[i] = isVecLike(entryVal) ? entryVal[i] ?? NaN : entryVal;
8804
+ }
8805
+ return r;
8806
+ } else {
8807
+ return val ? evaluate(node.consequent, context) : evaluate(node.alternate, context);
8808
+ }
8809
+ }
8810
+ case "Identifier":
8811
+ return context[node.name];
8812
+ case "Literal":
8813
+ return node.value;
8814
+ case "UnaryExpression": {
8815
+ const val = evaluate(node.argument, context);
8816
+ const unopFun = isVecLike(val) ? unopsVector[node.operator] : unopsNum[node.operator];
8817
+ return unopFun(val);
8818
+ }
8819
+ default:
8820
+ return void 0;
8821
+ }
8822
+ }
8823
+ var validResult = { valid: true };
8824
+ function visit(_node, visitor) {
8825
+ const node = _node;
8826
+ visitor(node);
8827
+ switch (node.type) {
8828
+ case "BinaryExpression": {
8829
+ visit(node.left, visitor);
8830
+ visit(node.right, visitor);
8831
+ break;
8832
+ }
8833
+ case "ConditionalExpression": {
8834
+ visit(node.test, visitor);
8835
+ visit(node.consequent, visitor);
8836
+ visit(node.alternate, visitor);
8837
+ break;
8838
+ }
8839
+ case "UnaryExpression": {
8840
+ visit(node.argument, visitor);
8841
+ break;
8842
+ }
8843
+ }
8844
+ }
8845
+ var supportedExpressionTypes = [
8846
+ "BinaryExpression",
8847
+ "UnaryExpression",
8848
+ "ConditionalExpression",
8849
+ "LogicalExpression",
8850
+ "Identifier",
8851
+ "Literal"
8852
+ ];
8853
+ function validate(_node, context) {
8854
+ const node = _node;
8855
+ const errors = [];
8856
+ visit(node, (node2) => {
8857
+ if (!supportedExpressionTypes.includes(node2.type)) {
8858
+ errors.push({
8859
+ valid: false,
8860
+ errorCode: 0 /* InvalidSyntax */,
8861
+ errorMessage: `Not allowed`
8862
+ });
8863
+ return;
8864
+ }
8865
+ if (node2.type === "Identifier") {
8866
+ if (!Object.prototype.hasOwnProperty.call(context, node2.name)) {
8867
+ return errors.push({
8868
+ valid: false,
8869
+ errorCode: 1 /* UnknownIdentifier */,
8870
+ errorMessage: `"${node2.name}" not found`
8871
+ });
8872
+ }
8873
+ }
8874
+ if (node2.type === "Literal") {
8875
+ if (typeof node2.value !== "number") {
8876
+ return errors.push({
8877
+ valid: false,
8878
+ errorCode: 0 /* InvalidSyntax */,
8879
+ errorMessage: `Only number literals are supported`
8880
+ });
8881
+ }
8882
+ }
8883
+ });
8884
+ return errors.length ? errors[0] : validResult;
8885
+ }
8886
+ function getSymbols(node) {
8887
+ const symbols = /* @__PURE__ */ new Set();
8888
+ visit(node, (node2) => {
8889
+ if (node2.type === "Identifier") {
8890
+ symbols.add(node2.name);
8891
+ }
8892
+ });
8893
+ return Array.from(symbols);
8894
+ }
8895
+ function compile(expression) {
8896
+ return (0, import_jsep.default)(expression);
8897
+ }
8647
8898
 
8648
8899
  // src/fetch-map/layer-map.ts
8649
8900
  init_cjs_shims();
@@ -9291,6 +9542,12 @@ var sharedPropMap = {
9291
9542
  wireframe: "wireframe"
9292
9543
  }
9293
9544
  };
9545
+ var rasterPropsMap = {
9546
+ isVisible: "visible",
9547
+ visConfig: {
9548
+ opacity: "opacity"
9549
+ }
9550
+ };
9294
9551
  var customMarkersPropsMap = {
9295
9552
  color: "getIconColor",
9296
9553
  visConfig: {
@@ -9334,6 +9591,12 @@ function getLayerProps(type, config2, dataset) {
9334
9591
  `Outdated layer type: ${type}. Please open map in CARTO Builder to automatically migrate.`
9335
9592
  );
9336
9593
  }
9594
+ if (type === "raster") {
9595
+ return {
9596
+ propMap: rasterPropsMap,
9597
+ defaultProps: {}
9598
+ };
9599
+ }
9337
9600
  let basePropMap = sharedPropMap;
9338
9601
  if (config2.visConfig?.customMarkers) {
9339
9602
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -9354,16 +9617,19 @@ function getLayerProps(type, config2, dataset) {
9354
9617
  }
9355
9618
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9356
9619
  if (scaleType === "ordinal" || scaleType === "point") {
9620
+ if (!attribute.categories) {
9621
+ return [0, 1];
9622
+ }
9357
9623
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9358
9624
  }
9359
9625
  if (scaleType === "quantile" && attribute.quantiles) {
9360
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9626
+ return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9361
9627
  }
9362
9628
  let { min: min2 } = attribute;
9363
9629
  if (scaleType === "log" && min2 === 0) {
9364
9630
  min2 = 1e-5;
9365
9631
  }
9366
- return [min2, attribute.max];
9632
+ return [min2 ?? 0, attribute.max ?? 1];
9367
9633
  }
9368
9634
  function domainFromValues(values, scaleType) {
9369
9635
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9384,12 +9650,14 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9384
9650
  if (data.tilestats) {
9385
9651
  const { attributes } = data.tilestats.layers[0];
9386
9652
  const attribute = attributes.find((a) => a.attribute === name);
9387
- return domainFromAttribute(attribute, scaleType, scaleLength);
9653
+ if (attribute) {
9654
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9655
+ }
9388
9656
  }
9389
9657
  return [0, 1];
9390
9658
  }
9391
9659
  function normalizeAccessor(accessor, data) {
9392
- if (data.features || data.tilestats) {
9660
+ if (data.features || data.tilestats || data.raster_metadata) {
9393
9661
  return (object, info) => {
9394
9662
  if (object) {
9395
9663
  return accessor(object.properties || object.__source.object.properties);
@@ -9441,7 +9709,6 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9441
9709
  return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9442
9710
  }
9443
9711
  function calculateLayerScale(name, scaleType, range, data) {
9444
- const scale2 = SCALE_FUNCS[scaleType]();
9445
9712
  let domain = [];
9446
9713
  let scaleColor = [];
9447
9714
  if (scaleType !== "identity") {
@@ -9459,9 +9726,13 @@ function calculateLayerScale(name, scaleType, range, data) {
9459
9726
  domain = domain.slice(0, scaleColor.length);
9460
9727
  }
9461
9728
  }
9729
+ return createColorScale(scaleType, domain, scaleColor, UNKNOWN_COLOR);
9730
+ }
9731
+ function createColorScale(scaleType, domain, range, unknown) {
9732
+ const scale2 = SCALE_FUNCS[scaleType]();
9462
9733
  scale2.domain(domain);
9463
- scale2.range(scaleColor);
9464
- scale2.unknown(UNKNOWN_COLOR);
9734
+ scale2.range(range);
9735
+ scale2.unknown(unknown);
9465
9736
  return scale2;
9466
9737
  }
9467
9738
  var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
@@ -9576,13 +9847,423 @@ function calculateClusterTextFontSize(radius) {
9576
9847
  return 11;
9577
9848
  }
9578
9849
 
9850
+ // src/fetch-map/raster-layer.ts
9851
+ var UNKNOWN_COLOR2 = [134, 141, 145];
9852
+ var RASTER_COLOR_BANDS = ["red", "green", "blue"];
9853
+ function getHasDataPredicate(noData) {
9854
+ if (noData === "nan") {
9855
+ return (v2) => !isNaN(v2);
9856
+ }
9857
+ if (typeof noData === "string") {
9858
+ noData = parseFloat(noData);
9859
+ }
9860
+ if (typeof noData === "number") {
9861
+ return (v2) => v2 !== noData && !isNaN(v2);
9862
+ }
9863
+ return () => true;
9864
+ }
9865
+ function createRasterColumnLayerDataTransform(transform) {
9866
+ return (data) => {
9867
+ if (!data || !("data" in data) || !data?.data?.cells?.numericProps) {
9868
+ return data;
9869
+ }
9870
+ return transform(data);
9871
+ };
9872
+ }
9873
+ function createEvaluationContext(numericProps, noData) {
9874
+ const hasData = getHasDataPredicate(noData);
9875
+ const bands = Object.entries(numericProps).map(([bandName, { value }]) => ({
9876
+ bandName,
9877
+ values: value,
9878
+ copied: false
9879
+ }));
9880
+ const length2 = bands[0].values.length;
9881
+ for (let i = 0; i < length2; i++) {
9882
+ let hasSomeData = false;
9883
+ for (let j = 0; j < bands.length; j++) {
9884
+ hasSomeData = hasSomeData || hasData(bands[j].values[i]);
9885
+ }
9886
+ if (!hasSomeData) {
9887
+ for (let j = 0; j < bands.length; j++) {
9888
+ if (!bands[j].copied) {
9889
+ bands[j].copied = true;
9890
+ bands[j].values = Array.from(bands[j].values);
9891
+ }
9892
+ bands[j].values[i] = NaN;
9893
+ }
9894
+ }
9895
+ }
9896
+ const context = bands.reduce(
9897
+ (agg, { bandName, values }) => {
9898
+ agg[bandName] = values;
9899
+ return agg;
9900
+ },
9901
+ {}
9902
+ );
9903
+ return context;
9904
+ }
9905
+ function createExprDataTransform({
9906
+ colorBand,
9907
+ rasterMetadata,
9908
+ usedSymbols
9909
+ }) {
9910
+ if (!colorBand || !colorBand.type || colorBand.type === "none") {
9911
+ return void 0;
9912
+ }
9913
+ const expr = colorBand?.type === "expression" ? colorBand.value : void 0;
9914
+ const vecExprEvaluator = expr ? createVecExprEvaluator(expr) : void 0;
9915
+ const dataTransform = createRasterColumnLayerDataTransform(
9916
+ (dataWrapped) => {
9917
+ const data = dataWrapped.data;
9918
+ if (expr) {
9919
+ const cachedResult = dataWrapped.customExpressionResults?.[expr];
9920
+ if (cachedResult) {
9921
+ return dataWrapped;
9922
+ }
9923
+ }
9924
+ let context = dataWrapped.expressionEvalContext;
9925
+ if (!context) {
9926
+ const usedNumericProps = usedSymbols.reduce(
9927
+ (acc, symbol) => {
9928
+ acc[symbol] = data.cells.numericProps[symbol];
9929
+ return acc;
9930
+ },
9931
+ {}
9932
+ );
9933
+ context = createEvaluationContext(
9934
+ usedNumericProps,
9935
+ rasterMetadata.nodata
9936
+ );
9937
+ dataWrapped = {
9938
+ ...dataWrapped,
9939
+ expressionEvalContext: context
9940
+ };
9941
+ }
9942
+ if (!vecExprEvaluator || !expr) return dataWrapped;
9943
+ const evalResult = vecExprEvaluator(context);
9944
+ return {
9945
+ ...dataWrapped,
9946
+ customExpressionResults: {
9947
+ ...dataWrapped.customExpressionResults,
9948
+ [expr]: evalResult
9949
+ }
9950
+ };
9951
+ }
9952
+ );
9953
+ return dataTransform;
9954
+ }
9955
+ function combineDataTransforms(dataTransforms) {
9956
+ const actualTransforms = dataTransforms.filter((v2) => v2);
9957
+ if (actualTransforms.length === 0) return void 0;
9958
+ if (actualTransforms.length === 1) return actualTransforms[0];
9959
+ return (data) => actualTransforms.reduce(
9960
+ (aggData, transformFun) => transformFun(aggData),
9961
+ data
9962
+ );
9963
+ }
9964
+ function createRgbToColorBufferDataTransform({
9965
+ bandDefs,
9966
+ attribute
9967
+ }) {
9968
+ return createRasterColumnLayerDataTransform(
9969
+ (dataWrapped) => {
9970
+ const length2 = dataWrapped.length;
9971
+ const getBandBufferOrValue = (colorBand) => {
9972
+ if (colorBand?.type === "expression") {
9973
+ return dataWrapped.customExpressionResults?.[colorBand.value];
9974
+ }
9975
+ if (colorBand?.type === "band") {
9976
+ return dataWrapped.expressionEvalContext?.[colorBand.value];
9977
+ }
9978
+ return 0;
9979
+ };
9980
+ const red = getBandBufferOrValue(bandDefs.red);
9981
+ const green = getBandBufferOrValue(bandDefs.green);
9982
+ const blue = getBandBufferOrValue(bandDefs.blue);
9983
+ const colorBuffer = new Uint8Array(length2 * 4);
9984
+ for (let inputIndex = 0, outputIndex = 0; inputIndex < length2; inputIndex++, outputIndex += 4) {
9985
+ const redRaw = typeof red === "number" ? red : red ? red[inputIndex] : NaN;
9986
+ const greenRaw = typeof green === "number" ? green : green ? green[inputIndex] : NaN;
9987
+ const blueRaw = typeof blue === "number" ? blue : blue ? blue[inputIndex] : NaN;
9988
+ if (isNaN(redRaw) && isNaN(greenRaw) && isNaN(blueRaw)) {
9989
+ bufferSetRgba(colorBuffer, outputIndex, 0, 0, 0, 0);
9990
+ } else {
9991
+ bufferSetRgba(
9992
+ colorBuffer,
9993
+ outputIndex,
9994
+ redRaw,
9995
+ greenRaw,
9996
+ blueRaw,
9997
+ 255
9998
+ );
9999
+ }
10000
+ }
10001
+ dataWrapped.customExpressionResults = void 0;
10002
+ dataWrapped.expressionEvalContext = void 0;
10003
+ return {
10004
+ ...dataWrapped,
10005
+ attributes: {
10006
+ [attribute]: colorBuffer
10007
+ }
10008
+ };
10009
+ }
10010
+ );
10011
+ }
10012
+ function getUsedSymbols(colorBands) {
10013
+ return Array.from(
10014
+ colorBands.reduce((symbols, band) => {
10015
+ if (band.type === "expression") {
10016
+ const expressionSymbols = createVecExprEvaluator(band.value)?.symbols || [];
10017
+ expressionSymbols.forEach((symbol) => symbols.add(symbol));
10018
+ }
10019
+ if (band.type === "band") {
10020
+ symbols.add(band.value);
10021
+ }
10022
+ return symbols;
10023
+ }, /* @__PURE__ */ new Set())
10024
+ );
10025
+ }
10026
+ function getRasterTileLayerStylePropsRgb({
10027
+ layerConfig,
10028
+ rasterMetadata,
10029
+ visualChannels
10030
+ }) {
10031
+ const { visConfig } = layerConfig;
10032
+ const { colorBands } = visConfig;
10033
+ const bandDefs = {
10034
+ red: colorBands?.find((band) => band.band === "red"),
10035
+ green: colorBands?.find((band) => band.band === "green"),
10036
+ blue: colorBands?.find((band) => band.band === "blue")
10037
+ };
10038
+ const rgbToInstanceFillColorsDataTransform = createRgbToColorBufferDataTransform({
10039
+ bandDefs,
10040
+ attribute: "instanceFillColors"
10041
+ });
10042
+ const usedSymbols = colorBands ? getUsedSymbols(colorBands) : [];
10043
+ const bandTransforms = RASTER_COLOR_BANDS.map(
10044
+ (band) => createExprDataTransform({
10045
+ colorBand: bandDefs[band],
10046
+ rasterMetadata,
10047
+ usedSymbols
10048
+ })
10049
+ );
10050
+ const combinedDataTransform = combineDataTransforms([
10051
+ ...bandTransforms,
10052
+ rgbToInstanceFillColorsDataTransform
10053
+ ]);
10054
+ return {
10055
+ dataTransform: combinedDataTransform,
10056
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10057
+ layerConfig,
10058
+ visualChannels
10059
+ })
10060
+ };
10061
+ }
10062
+ function createBandColorScaleDataTransform({
10063
+ bandName,
10064
+ scaleFun,
10065
+ nodata,
10066
+ attribute
10067
+ }) {
10068
+ const hasData = getHasDataPredicate(nodata);
10069
+ return createRasterColumnLayerDataTransform(
10070
+ (dataWrapped) => {
10071
+ const length2 = dataWrapped.length;
10072
+ const bandBuffer = dataWrapped.data.cells.numericProps[bandName].value;
10073
+ const colorBuffer = new Uint8Array(length2 * 4);
10074
+ for (let i = 0; i < length2; i++) {
10075
+ const rawValue = bandBuffer[i];
10076
+ if (!hasData(rawValue)) {
10077
+ bufferSetRgba(colorBuffer, i * 4, 0, 0, 0, 0);
10078
+ } else {
10079
+ const colorRgb = scaleFun(rawValue);
10080
+ bufferSetRgba(
10081
+ colorBuffer,
10082
+ i * 4,
10083
+ colorRgb[0],
10084
+ colorRgb[1],
10085
+ colorRgb[2],
10086
+ 255
10087
+ );
10088
+ }
10089
+ }
10090
+ return {
10091
+ ...dataWrapped,
10092
+ attributes: {
10093
+ [attribute]: colorBuffer
10094
+ }
10095
+ };
10096
+ }
10097
+ );
10098
+ }
10099
+ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10100
+ if (scaleType === "ordinal") {
10101
+ return colorRange.colorMap?.map(([value]) => value) || [];
10102
+ }
10103
+ if (scaleType === "custom") {
10104
+ if (colorRange.uiCustomScaleType === "logarithmic") {
10105
+ if (colorRange.colorMap) {
10106
+ return colorRange.colorMap?.map(([value]) => value) || [];
10107
+ }
10108
+ return [band.stats.min, band.stats.max];
10109
+ } else {
10110
+ return colorRange.colorMap?.map(([value]) => value) || [];
10111
+ }
10112
+ }
10113
+ const scaleLength = colorRange.colors.length;
10114
+ if (scaleType === "quantile") {
10115
+ const quantiles = band.stats.quantiles?.[scaleLength];
10116
+ if (!quantiles) {
10117
+ return [0, 1];
10118
+ }
10119
+ return [band.stats.min, ...quantiles, band.stats.max];
10120
+ }
10121
+ return [band.stats.min, band.stats.max];
10122
+ }
10123
+ function getRasterTileLayerStylePropsScaledBand({
10124
+ layerConfig,
10125
+ rasterMetadata,
10126
+ visualChannels
10127
+ }) {
10128
+ const { visConfig } = layerConfig;
10129
+ const { colorField } = visualChannels;
10130
+ const { rasterStyleType } = visConfig;
10131
+ const colorRange = rasterStyleType === "ColorRange" ? visConfig.colorRange : visConfig.uniqueValuesColorRange;
10132
+ const scaleType = rasterStyleType === "ColorRange" ? visualChannels.colorScale : "ordinal";
10133
+ const bandInfo = rasterMetadata.bands.find(
10134
+ (band) => band.name === colorField?.name
10135
+ );
10136
+ if (!colorField?.name || !scaleType || !colorRange || !bandInfo) {
10137
+ return {};
10138
+ }
10139
+ const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
10140
+ const scaleFun = createColorScale(
10141
+ scaleType,
10142
+ domain,
10143
+ colorRange.colors.map(hexToRGB),
10144
+ UNKNOWN_COLOR2
10145
+ );
10146
+ const bandColorScaleDataTransform = createBandColorScaleDataTransform({
10147
+ bandName: bandInfo.name,
10148
+ scaleFun,
10149
+ nodata: bandInfo?.nodata ?? rasterMetadata.nodata,
10150
+ attribute: "instanceFillColors"
10151
+ });
10152
+ return {
10153
+ dataTransform: bandColorScaleDataTransform,
10154
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10155
+ layerConfig,
10156
+ visualChannels
10157
+ })
10158
+ };
10159
+ }
10160
+ function getRasterTileLayerStyleProps({
10161
+ layerConfig,
10162
+ visualChannels,
10163
+ rasterMetadata
10164
+ }) {
10165
+ const { visConfig } = layerConfig;
10166
+ const { rasterStyleType } = visConfig;
10167
+ if (rasterStyleType === "Rgb") {
10168
+ return getRasterTileLayerStylePropsRgb({
10169
+ layerConfig,
10170
+ rasterMetadata,
10171
+ visualChannels
10172
+ });
10173
+ } else {
10174
+ return getRasterTileLayerStylePropsScaledBand({
10175
+ layerConfig,
10176
+ rasterMetadata,
10177
+ visualChannels
10178
+ });
10179
+ }
10180
+ }
10181
+ function getRasterTileLayerUpdateTriggers({
10182
+ layerConfig,
10183
+ visualChannels
10184
+ }) {
10185
+ const { visConfig } = layerConfig;
10186
+ const { rasterStyleType } = visConfig;
10187
+ const getFillColorUpdateTriggers = {
10188
+ rasterStyleType
10189
+ };
10190
+ if (rasterStyleType === "ColorRange") {
10191
+ getFillColorUpdateTriggers.colorRange = visConfig.colorRange?.colors;
10192
+ getFillColorUpdateTriggers.colorMap = visConfig.colorRange?.colorMap;
10193
+ getFillColorUpdateTriggers.colorScale = visualChannels.colorScale;
10194
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10195
+ } else if (rasterStyleType === "UniqueValues") {
10196
+ getFillColorUpdateTriggers.colorMap = visConfig.uniqueValuesColorRange?.colorMap;
10197
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10198
+ } else if (rasterStyleType === "Rgb") {
10199
+ getFillColorUpdateTriggers.colorBands = visConfig.colorBands;
10200
+ }
10201
+ return {
10202
+ getFillColor: getFillColorUpdateTriggers
10203
+ };
10204
+ }
10205
+ function bufferSetRgba(target, index, r, g, b, a) {
10206
+ target[index + 0] = r;
10207
+ target[index + 1] = g;
10208
+ target[index + 2] = b;
10209
+ target[index + 3] = a;
10210
+ }
10211
+ function hexToRGB(hexColor) {
10212
+ const r = parseInt(hexColor.slice(1, 3), 16);
10213
+ const g = parseInt(hexColor.slice(3, 5), 16);
10214
+ const b = parseInt(hexColor.slice(5, 7), 16);
10215
+ return [r, g, b];
10216
+ }
10217
+
10218
+ // src/fetch-map/fetch-map.ts
10219
+ init_cjs_shims();
10220
+
9579
10221
  // src/fetch-map/parse-map.ts
10222
+ init_cjs_shims();
10223
+ function getLayerDescriptor({
10224
+ mapConfig,
10225
+ layer,
10226
+ dataset
10227
+ }) {
10228
+ const { filters, visState } = mapConfig;
10229
+ const { layerBlending, interactionConfig } = visState;
10230
+ const { id, type, config: config2, visualChannels } = layer;
10231
+ const { data, id: datasetId } = dataset;
10232
+ const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config2, dataset);
10233
+ const styleProps = createStyleProps(config2, propMap);
10234
+ const { channelProps, scales } = createChannelProps(
10235
+ id,
10236
+ type,
10237
+ config2,
10238
+ visualChannels,
10239
+ data,
10240
+ dataset
10241
+ );
10242
+ const layerDescriptor = {
10243
+ type,
10244
+ filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[datasetId],
10245
+ props: {
10246
+ id,
10247
+ data,
10248
+ ...defaultProps2,
10249
+ ...createInteractionProps(interactionConfig),
10250
+ ...styleProps,
10251
+ ...channelProps,
10252
+ ...createParametersProp(layerBlending, styleProps.parameters || {}),
10253
+ // Must come after style
10254
+ ...createLoadOptions(data.accessToken)
10255
+ },
10256
+ scales
10257
+ };
10258
+ return layerDescriptor;
10259
+ }
9580
10260
  function parseMap(json) {
9581
10261
  const { keplerMapConfig, datasets, token } = json;
9582
10262
  assert2(keplerMapConfig.version === "v1", "Only support Kepler v1");
9583
- const config2 = keplerMapConfig.config;
9584
- const { filters, mapState, mapStyle, popupSettings, legendSettings } = config2;
9585
- const { layers, layerBlending, interactionConfig } = config2.visState;
10263
+ const mapConfig = keplerMapConfig.config;
10264
+ const { mapState, mapStyle, popupSettings, legendSettings, visState } = mapConfig;
10265
+ const { layers } = visState;
10266
+ const layersReverse = [...layers].reverse();
9586
10267
  return {
9587
10268
  id: json.id,
9588
10269
  title: json.title,
@@ -9595,45 +10276,19 @@ function parseMap(json) {
9595
10276
  popupSettings,
9596
10277
  legendSettings,
9597
10278
  token,
9598
- layers: layers.reverse().map(({ id, type, config: config3, visualChannels }) => {
10279
+ layers: layersReverse.map((layer) => {
9599
10280
  try {
9600
- const { dataId } = config3;
10281
+ const { dataId } = layer.config;
9601
10282
  const dataset = datasets.find(
9602
10283
  (d) => d.id === dataId
9603
10284
  );
9604
10285
  assert2(dataset, `No dataset matching dataId: ${dataId}`);
9605
- const { data } = dataset;
9606
- assert2(data, `No data loaded for dataId: ${dataId}`);
9607
- const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config3, dataset);
9608
- const styleProps = createStyleProps(config3, propMap);
9609
- const { channelProps, scales } = createChannelProps(
9610
- id,
9611
- type,
9612
- config3,
9613
- visualChannels,
9614
- data,
10286
+ const layerDescriptor = getLayerDescriptor({
10287
+ mapConfig,
10288
+ layer,
9615
10289
  dataset
9616
- );
9617
- const layer = {
9618
- type,
9619
- filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[dataId],
9620
- props: {
9621
- id,
9622
- data,
9623
- ...defaultProps2,
9624
- ...createInteractionProps(interactionConfig),
9625
- ...styleProps,
9626
- ...channelProps,
9627
- ...createParametersProp(
9628
- layerBlending,
9629
- styleProps.parameters || {}
9630
- ),
9631
- // Must come after style
9632
- ...createLoadOptions(token)
9633
- },
9634
- scales
9635
- };
9636
- return layer;
10290
+ });
10291
+ return layerDescriptor;
9637
10292
  } catch (e) {
9638
10293
  console.error(e.message);
9639
10294
  return void 0;
@@ -9712,11 +10367,52 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9712
10367
  radiusScale,
9713
10368
  strokeColorField,
9714
10369
  strokeColorScale,
10370
+ sizeField: strokeWidthField,
10371
+ sizeScale: strokeWidthScale,
9715
10372
  weightField
9716
10373
  } = visualChannels;
10374
+ if (layerType === "raster") {
10375
+ const rasterMetadata = data.raster_metadata;
10376
+ if (!rasterMetadata) {
10377
+ return {
10378
+ channelProps: {},
10379
+ scales: {}
10380
+ };
10381
+ }
10382
+ const rasterStyleType = config2.visConfig.rasterStyleType;
10383
+ if (rasterStyleType === "Rgb") {
10384
+ return {
10385
+ channelProps: getRasterTileLayerStylePropsRgb({
10386
+ layerConfig: config2,
10387
+ rasterMetadata,
10388
+ visualChannels
10389
+ }),
10390
+ scales: {}
10391
+ };
10392
+ } else {
10393
+ return {
10394
+ channelProps: getRasterTileLayerStylePropsScaledBand({
10395
+ layerConfig: config2,
10396
+ visualChannels,
10397
+ rasterMetadata
10398
+ }),
10399
+ scales: {
10400
+ ...colorField && {
10401
+ fillColor: {
10402
+ field: colorField,
10403
+ type: "ordinal",
10404
+ domain: [],
10405
+ range: []
10406
+ }
10407
+ }
10408
+ }
10409
+ };
10410
+ }
10411
+ }
9717
10412
  const { heightField, heightScale } = visualChannels;
9718
10413
  const { textLabel, visConfig } = config2;
9719
10414
  const result = {};
10415
+ const updateTriggers = {};
9720
10416
  const scales = {};
9721
10417
  if (colorField) {
9722
10418
  const { colorAggregation: aggregation, colorRange: range } = visConfig;
@@ -9728,7 +10424,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9728
10424
  data
9729
10425
  );
9730
10426
  result.getFillColor = accessor;
9731
- scales.fillColor = {
10427
+ scales.fillColor = updateTriggers.getFillColor = {
9732
10428
  field: colorField,
9733
10429
  type: colorScale,
9734
10430
  ...domainAndRangeFromScale(scale2)
@@ -9747,6 +10443,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9747
10443
  result.getWeight = (d) => {
9748
10444
  return d.properties[aggregationExpAlias];
9749
10445
  };
10446
+ updateTriggers.getWeight = aggregationExpAlias;
9750
10447
  result.getPointRadius = (d, info) => {
9751
10448
  return calculateClusterRadius(
9752
10449
  d.properties,
@@ -9755,11 +10452,16 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9755
10452
  aggregationExpAlias
9756
10453
  );
9757
10454
  };
10455
+ updateTriggers.getPointRadius = {
10456
+ aggregationExpAlias,
10457
+ radiusRange: visConfig.radiusRange
10458
+ };
9758
10459
  result.textCharacterSet = "auto";
9759
10460
  result.textFontFamily = "Inter, sans";
9760
10461
  result.textFontSettings = { sdf: true };
9761
10462
  result.textFontWeight = 600;
9762
10463
  result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
10464
+ updateTriggers.getText = aggregationExpAlias;
9763
10465
  result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
9764
10466
  result.textOutlineColor = [
9765
10467
  ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
@@ -9776,6 +10478,10 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9776
10478
  );
9777
10479
  return calculateClusterTextFontSize(radius);
9778
10480
  };
10481
+ updateTriggers.getTextSize = {
10482
+ aggregationExpAlias,
10483
+ radiusRange: visConfig.radiusRange
10484
+ };
9779
10485
  }
9780
10486
  if (radiusField) {
9781
10487
  const { accessor, scale: scale2 } = getSizeAccessor(
@@ -9786,7 +10492,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9786
10492
  data
9787
10493
  );
9788
10494
  result.getPointRadius = accessor;
9789
- scales.pointRadius = {
10495
+ scales.pointRadius = updateTriggers.getPointRadius = {
9790
10496
  field: radiusField,
9791
10497
  type: radiusScale || "identity",
9792
10498
  ...domainAndRangeFromScale(scale2)
@@ -9803,12 +10509,27 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9803
10509
  data
9804
10510
  );
9805
10511
  result.getLineColor = accessor;
9806
- scales.lineColor = {
10512
+ scales.lineColor = updateTriggers.getLineColor = {
9807
10513
  field: strokeColorField,
9808
10514
  type: strokeColorScale,
9809
10515
  ...domainAndRangeFromScale(scale2)
9810
10516
  };
9811
10517
  }
10518
+ if (strokeWidthField) {
10519
+ const { accessor, scale: scale2 } = getSizeAccessor(
10520
+ strokeWidthField,
10521
+ strokeWidthScale,
10522
+ visConfig.sizeAggregation,
10523
+ visConfig.sizeRange,
10524
+ data
10525
+ );
10526
+ result.getLineWidth = accessor;
10527
+ scales.lineWidth = updateTriggers.getLineWidth = {
10528
+ field: strokeWidthField,
10529
+ type: strokeWidthScale || "identity",
10530
+ ...domainAndRangeFromScale(scale2)
10531
+ };
10532
+ }
9812
10533
  if (heightField && visConfig.enable3d) {
9813
10534
  const { accessor, scale: scale2 } = getSizeAccessor(
9814
10535
  heightField,
@@ -9818,7 +10539,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9818
10539
  data
9819
10540
  );
9820
10541
  result.getElevation = accessor;
9821
- scales.elevation = {
10542
+ scales.elevation = updateTriggers.getElevation = {
9822
10543
  field: heightField,
9823
10544
  type: heightScale || "identity",
9824
10545
  ...domainAndRangeFromScale(scale2)
@@ -9833,7 +10554,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9833
10554
  data
9834
10555
  );
9835
10556
  result.getWeight = accessor;
9836
- scales.weight = {
10557
+ scales.weight = updateTriggers.getWeight = {
9837
10558
  field: weightField,
9838
10559
  type: "identity",
9839
10560
  ...domainAndRangeFromScale(scale2)
@@ -9854,6 +10575,12 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9854
10575
  { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons },
9855
10576
  data
9856
10577
  );
10578
+ updateTriggers.getIcon = {
10579
+ customMarkersUrl,
10580
+ customMarkersRange,
10581
+ maxIconSize,
10582
+ useMaskedIcons
10583
+ };
9857
10584
  result._subLayerProps = {
9858
10585
  "points-icon": {
9859
10586
  loadOptions: {
@@ -9870,9 +10597,11 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9870
10597
  };
9871
10598
  if (getFillColor && useMaskedIcons) {
9872
10599
  result.getIconColor = getFillColor;
10600
+ updateTriggers.getIconColor = updateTriggers.getFillColor;
9873
10601
  }
9874
10602
  if (getPointRadius) {
9875
10603
  result.getIconSize = getPointRadius;
10604
+ updateTriggers.getIconSize = updateTriggers.getPointRadius;
9876
10605
  }
9877
10606
  if (visualChannels.rotationField) {
9878
10607
  const { accessor } = getSizeAccessor(
@@ -9883,6 +10612,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9883
10612
  data
9884
10613
  );
9885
10614
  result.getIconAngle = negateAccessor(accessor);
10615
+ updateTriggers.getIconAngle = updateTriggers.getRotationField;
9886
10616
  }
9887
10617
  } else if (layerType === "tileset") {
9888
10618
  result.pointType = "circle";
@@ -9927,7 +10657,13 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9927
10657
  }
9928
10658
  };
9929
10659
  }
9930
- return { channelProps: result, scales };
10660
+ return {
10661
+ channelProps: {
10662
+ ...result,
10663
+ updateTriggers
10664
+ },
10665
+ scales
10666
+ };
9931
10667
  }
9932
10668
  function createLoadOptions(accessToken) {
9933
10669
  return {
@@ -10583,9 +11319,15 @@ function hashBuckets(initialCount) {
10583
11319
  WidgetSource,
10584
11320
  WidgetTableSource,
10585
11321
  WidgetTilesetSource,
11322
+ _ErrorCode,
11323
+ _applyLayerGroupFilters,
10586
11324
  _buildFeatureFilter,
11325
+ _createVecExprEvaluator,
10587
11326
  _domainFromValues,
11327
+ _evaluateVecExpr,
10588
11328
  _getHexagonResolution,
11329
+ _getRasterTileLayerStyleProps,
11330
+ _validateVecExprSyntax,
10589
11331
  addFilter,
10590
11332
  aggregate,
10591
11333
  aggregationFunctions,
@@ -10598,9 +11340,11 @@ function hashBuckets(initialCount) {
10598
11340
  buildStatsUrl,
10599
11341
  calculateClusterRadius,
10600
11342
  calculateClusterTextFontSize,
11343
+ calculateLayerScale,
10601
11344
  clearDefaultRequestCache,
10602
11345
  clearFilters,
10603
11346
  configureSource,
11347
+ createColorScale,
10604
11348
  createPolygonSpatialFilter,
10605
11349
  createViewportSpatialFilter,
10606
11350
  fetchBasemapProps,
@@ -10615,6 +11359,7 @@ function hashBuckets(initialCount) {
10615
11359
  getDefaultAggregationExpColumnAliasForLayerType,
10616
11360
  getFilter,
10617
11361
  getIconUrlAccessor,
11362
+ getLayerDescriptor,
10618
11363
  getLayerProps,
10619
11364
  getMaxMarkerSize,
10620
11365
  getSizeAccessor,