@carto/api-client 0.5.14 → 0.5.15-alpha.raster-0

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