@carto/api-client 0.5.15 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,9 +125,16 @@ __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
+ _getLog10ScaleSteps: () => getLog10ScaleSteps,
136
+ _getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
137
+ _validateVecExprSyntax: () => validateVecExprSyntax,
131
138
  addFilter: () => addFilter,
132
139
  aggregate: () => aggregate,
133
140
  aggregationFunctions: () => aggregationFunctions,
@@ -140,9 +147,11 @@ __export(src_exports, {
140
147
  buildStatsUrl: () => buildStatsUrl,
141
148
  calculateClusterRadius: () => calculateClusterRadius,
142
149
  calculateClusterTextFontSize: () => calculateClusterTextFontSize,
150
+ calculateLayerScale: () => calculateLayerScale,
143
151
  clearDefaultRequestCache: () => clearDefaultRequestCache,
144
152
  clearFilters: () => clearFilters,
145
153
  configureSource: () => configureSource,
154
+ createColorScale: () => createColorScale,
146
155
  createPolygonSpatialFilter: () => createPolygonSpatialFilter,
147
156
  createViewportSpatialFilter: () => createViewportSpatialFilter,
148
157
  fetchBasemapProps: () => fetchBasemapProps,
@@ -157,6 +166,7 @@ __export(src_exports, {
157
166
  getDefaultAggregationExpColumnAliasForLayerType: () => getDefaultAggregationExpColumnAliasForLayerType,
158
167
  getFilter: () => getFilter,
159
168
  getIconUrlAccessor: () => getIconUrlAccessor,
169
+ getLayerDescriptor: () => getLayerDescriptor,
160
170
  getLayerProps: () => getLayerProps,
161
171
  getMaxMarkerSize: () => getMaxMarkerSize,
162
172
  getSizeAccessor: () => getSizeAccessor,
@@ -6420,7 +6430,8 @@ var AVAILABLE_MODELS = [
6420
6430
  "timeseries",
6421
6431
  "range",
6422
6432
  "scatterplot",
6423
- "table"
6433
+ "table",
6434
+ "aggregations"
6424
6435
  ];
6425
6436
  var { V3 } = ApiVersion;
6426
6437
  var REQUEST_GET_MAX_URL_LENGTH = 2048;
@@ -6863,6 +6874,30 @@ var WidgetRemoteSource = class extends WidgetSource {
6863
6874
  categories: res.metadata?.categories
6864
6875
  }));
6865
6876
  }
6877
+ async getAggregations(options) {
6878
+ const {
6879
+ signal,
6880
+ filters = this.props.filters,
6881
+ filterOwner,
6882
+ spatialFilter,
6883
+ spatialFiltersMode,
6884
+ aggregations
6885
+ } = options;
6886
+ return executeModel({
6887
+ model: "aggregations",
6888
+ source: {
6889
+ ...this.getModelSource(filters, filterOwner),
6890
+ spatialFiltersMode,
6891
+ spatialFilter
6892
+ },
6893
+ params: {
6894
+ aggregations
6895
+ },
6896
+ opts: { signal, headers: this.props.headers }
6897
+ }).then((res) => ({
6898
+ rows: res.rows.map((row) => normalizeObjectKeys(row))
6899
+ }));
6900
+ }
6866
6901
  /** @experimental */
6867
6902
  async getExtent(options = {}) {
6868
6903
  const { signal, filters = this.props.filters, filterOwner } = options;
@@ -7685,6 +7720,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7685
7720
  assertColumn(this._features, column);
7686
7721
  }
7687
7722
  const targetOperation = aggregationFunctions[operation2];
7723
+ assert2(targetOperation, `Unsupported aggregation operation: ${operation2}`);
7688
7724
  return {
7689
7725
  value: targetOperation(filteredFeatures, column, joinOperation)
7690
7726
  };
@@ -7883,6 +7919,39 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7883
7919
  max: aggregationFunctions.max(filteredFeatures, column)
7884
7920
  };
7885
7921
  }
7922
+ async getAggregations({
7923
+ aggregations,
7924
+ filters,
7925
+ filterOwner,
7926
+ spatialFilter
7927
+ }) {
7928
+ const filteredFeatures = this._getFilteredFeatures(
7929
+ spatialFilter,
7930
+ filters,
7931
+ filterOwner
7932
+ );
7933
+ if (!this._features.length) {
7934
+ return { rows: [] };
7935
+ }
7936
+ assert2(
7937
+ typeof aggregations !== "string",
7938
+ "Unsupported tileset SQL aggregation"
7939
+ );
7940
+ const result = {};
7941
+ const usedAliases = /* @__PURE__ */ new Set();
7942
+ for (const { column, operation: operation2, alias } of aggregations) {
7943
+ if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
7944
+ assertColumn(this._features, column);
7945
+ }
7946
+ const aliasKey = alias.toLowerCase();
7947
+ assert2(!usedAliases.has(aliasKey), `Duplicate alias: ${aliasKey}`);
7948
+ usedAliases.add(aliasKey);
7949
+ const targetOperation = aggregationFunctions[operation2];
7950
+ assert2(targetOperation, `Unsupported operation: ${operation2}`);
7951
+ result[alias] = targetOperation(filteredFeatures, column);
7952
+ }
7953
+ return { rows: [result] };
7954
+ }
7886
7955
  /** @experimental */
7887
7956
  async getExtent() {
7888
7957
  return Promise.reject(new Error("not implemented"));
@@ -8117,6 +8186,16 @@ var WidgetTilesetSource = class extends WidgetSource {
8117
8186
  }) {
8118
8187
  return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
8119
8188
  }
8189
+ async getAggregations({
8190
+ signal,
8191
+ ...options
8192
+ }) {
8193
+ return this._executeWorkerMethod(
8194
+ "getAggregations" /* GET_AGGREGATIONS */,
8195
+ [options],
8196
+ signal
8197
+ );
8198
+ }
8120
8199
  /** @experimental */
8121
8200
  async getExtent() {
8122
8201
  return Promise.resolve({
@@ -8739,11 +8818,253 @@ var basemap_styles_default = {
8739
8818
  DARK_MATTER_NOLABELS: getStyleUrl("dark-matter-nolabels")
8740
8819
  };
8741
8820
 
8742
- // src/fetch-map/fetch-map.ts
8821
+ // src/fetch-map/raster-layer.ts
8743
8822
  init_cjs_shims();
8744
8823
 
8745
- // src/fetch-map/parse-map.ts
8824
+ // src/fetch-map/vec-expr-evaluator.ts
8746
8825
  init_cjs_shims();
8826
+ var import_jsep = __toESM(require("jsep"), 1);
8827
+ function createVecExprEvaluator(expression) {
8828
+ try {
8829
+ const parsed = compile(expression);
8830
+ const evalFun = (context) => evaluate(parsed, context);
8831
+ evalFun.symbols = getSymbols(parsed);
8832
+ return evalFun;
8833
+ } catch {
8834
+ return null;
8835
+ }
8836
+ }
8837
+ function evaluateVecExpr(expression, context) {
8838
+ try {
8839
+ return createVecExprEvaluator(expression)?.(context);
8840
+ } catch {
8841
+ return null;
8842
+ }
8843
+ }
8844
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
8845
+ ErrorCode2[ErrorCode2["InvalidSyntax"] = 0] = "InvalidSyntax";
8846
+ ErrorCode2[ErrorCode2["UnknownIdentifier"] = 1] = "UnknownIdentifier";
8847
+ return ErrorCode2;
8848
+ })(ErrorCode || {});
8849
+ function validateVecExprSyntax(expression, context) {
8850
+ let parsed;
8851
+ try {
8852
+ parsed = compile(expression);
8853
+ } catch (e) {
8854
+ return {
8855
+ valid: false,
8856
+ errorCode: 0 /* InvalidSyntax */,
8857
+ errorMessage: e && "message" in e ? String(e.message) : String(e)
8858
+ };
8859
+ }
8860
+ return validate(parsed, context);
8861
+ }
8862
+ function createResultArray(typeTemplate, length2 = typeTemplate.length) {
8863
+ return new Array(length2);
8864
+ }
8865
+ function isVecLike(a) {
8866
+ return Array.isArray(a) || ArrayBuffer.isView(a);
8867
+ }
8868
+ var createBinopVec = (scalarBinOp) => (left, right) => {
8869
+ const length2 = Math.min(left.length, right.length);
8870
+ const r = createResultArray(left, length2);
8871
+ for (let i = 0; i < length2; i++) {
8872
+ r[i] = scalarBinOp(left[i], right[i]);
8873
+ }
8874
+ return r;
8875
+ };
8876
+ var createBinopVecNum = (scalarBinOp) => (left, right) => {
8877
+ const length2 = left.length;
8878
+ const r = createResultArray(left, length2);
8879
+ for (let i = 0; i < length2; i++) {
8880
+ r[i] = scalarBinOp(left[i], right);
8881
+ }
8882
+ return r;
8883
+ };
8884
+ var createBinopNumVec = (scalarBinOp) => (left, right) => {
8885
+ const length2 = right.length;
8886
+ const r = createResultArray(right, length2);
8887
+ for (let i = 0; i < length2; i++) {
8888
+ r[i] = scalarBinOp(left, right[i]);
8889
+ }
8890
+ return r;
8891
+ };
8892
+ var createUnopVec = (scalarUnop) => (a) => {
8893
+ const length2 = a.length;
8894
+ const r = createResultArray(a, length2);
8895
+ for (let i = 0; i < length2; i++) {
8896
+ r[i] = scalarUnop(a[i]);
8897
+ }
8898
+ return r;
8899
+ };
8900
+ function mapDictValues(dict, fun) {
8901
+ return Object.keys(dict).reduce(
8902
+ (acc, key) => {
8903
+ acc[key] = fun(dict[key]);
8904
+ return acc;
8905
+ },
8906
+ {}
8907
+ );
8908
+ }
8909
+ var binopsNum = {
8910
+ "||": (a, b) => a || b,
8911
+ "&&": (a, b) => a && b,
8912
+ "|": (a, b) => a | b,
8913
+ "^": (a, b) => a ^ b,
8914
+ "&": (a, b) => a & b,
8915
+ "==": (a, b) => Number(a == b),
8916
+ "!=": (a, b) => Number(a != b),
8917
+ "===": (a, b) => Number(a === b),
8918
+ "!==": (a, b) => Number(a !== b),
8919
+ "<": (a, b) => Number(a < b),
8920
+ ">": (a, b) => Number(a > b),
8921
+ "<=": (a, b) => Number(a <= b),
8922
+ ">=": (a, b) => Number(a >= b),
8923
+ "<<": (a, b) => a << b,
8924
+ ">>": (a, b) => a >> b,
8925
+ ">>>": (a, b) => a >>> b,
8926
+ "+": (a, b) => a + b,
8927
+ "-": (a, b) => a - b,
8928
+ "*": (a, b) => a * b,
8929
+ "/": (a, b) => a / b,
8930
+ "%": (a, b) => a % b
8931
+ };
8932
+ var unopsNum = {
8933
+ "-": (a) => -a,
8934
+ "+": (a) => +a,
8935
+ "~": (a) => ~a,
8936
+ "!": (a) => Number(!a)
8937
+ };
8938
+ var binopsVector = mapDictValues(binopsNum, createBinopVec);
8939
+ var binopsNumVec = mapDictValues(binopsNum, createBinopNumVec);
8940
+ var binopsVecNum = mapDictValues(binopsNum, createBinopVecNum);
8941
+ var unopsVector = mapDictValues(unopsNum, createUnopVec);
8942
+ function getBinop(operator, left, right) {
8943
+ const isLeftVec = isVecLike(left);
8944
+ const isRightVec = isVecLike(right);
8945
+ if (isLeftVec && isRightVec) {
8946
+ return binopsVector[operator];
8947
+ } else if (isLeftVec) {
8948
+ return binopsVecNum[operator];
8949
+ } else if (isRightVec) {
8950
+ return binopsNumVec[operator];
8951
+ } else {
8952
+ return binopsNum[operator];
8953
+ }
8954
+ }
8955
+ function evaluate(_node, context) {
8956
+ const node = _node;
8957
+ switch (node.type) {
8958
+ case "BinaryExpression": {
8959
+ const left = evaluate(node.left, context);
8960
+ const right = evaluate(node.right, context);
8961
+ const binopFun = getBinop(node.operator, left, right);
8962
+ return binopFun(left, right);
8963
+ }
8964
+ case "ConditionalExpression": {
8965
+ const val = evaluate(node.test, context);
8966
+ if (isVecLike(val)) {
8967
+ const length2 = val.length;
8968
+ const consequentVal = evaluate(node.consequent, context);
8969
+ const alternateVal = evaluate(node.alternate, context);
8970
+ const r = createResultArray(val);
8971
+ for (let i = 0; i < length2; i++) {
8972
+ const entryVal = val[i] ? consequentVal : alternateVal;
8973
+ r[i] = isVecLike(entryVal) ? entryVal[i] ?? NaN : entryVal;
8974
+ }
8975
+ return r;
8976
+ } else {
8977
+ return val ? evaluate(node.consequent, context) : evaluate(node.alternate, context);
8978
+ }
8979
+ }
8980
+ case "Identifier":
8981
+ return context[node.name];
8982
+ case "Literal":
8983
+ return node.value;
8984
+ case "UnaryExpression": {
8985
+ const val = evaluate(node.argument, context);
8986
+ const unopFun = isVecLike(val) ? unopsVector[node.operator] : unopsNum[node.operator];
8987
+ return unopFun(val);
8988
+ }
8989
+ default:
8990
+ return void 0;
8991
+ }
8992
+ }
8993
+ var validResult = { valid: true };
8994
+ function visit(_node, visitor) {
8995
+ const node = _node;
8996
+ visitor(node);
8997
+ switch (node.type) {
8998
+ case "BinaryExpression": {
8999
+ visit(node.left, visitor);
9000
+ visit(node.right, visitor);
9001
+ break;
9002
+ }
9003
+ case "ConditionalExpression": {
9004
+ visit(node.test, visitor);
9005
+ visit(node.consequent, visitor);
9006
+ visit(node.alternate, visitor);
9007
+ break;
9008
+ }
9009
+ case "UnaryExpression": {
9010
+ visit(node.argument, visitor);
9011
+ break;
9012
+ }
9013
+ }
9014
+ }
9015
+ var supportedExpressionTypes = [
9016
+ "BinaryExpression",
9017
+ "UnaryExpression",
9018
+ "ConditionalExpression",
9019
+ "LogicalExpression",
9020
+ "Identifier",
9021
+ "Literal"
9022
+ ];
9023
+ function validate(_node, context) {
9024
+ const node = _node;
9025
+ const errors = [];
9026
+ visit(node, (node2) => {
9027
+ if (!supportedExpressionTypes.includes(node2.type)) {
9028
+ errors.push({
9029
+ valid: false,
9030
+ errorCode: 0 /* InvalidSyntax */,
9031
+ errorMessage: `Not allowed`
9032
+ });
9033
+ return;
9034
+ }
9035
+ if (node2.type === "Identifier") {
9036
+ if (!Object.prototype.hasOwnProperty.call(context, node2.name)) {
9037
+ return errors.push({
9038
+ valid: false,
9039
+ errorCode: 1 /* UnknownIdentifier */,
9040
+ errorMessage: `"${node2.name}" not found`
9041
+ });
9042
+ }
9043
+ }
9044
+ if (node2.type === "Literal") {
9045
+ if (typeof node2.value !== "number") {
9046
+ return errors.push({
9047
+ valid: false,
9048
+ errorCode: 0 /* InvalidSyntax */,
9049
+ errorMessage: `Only number literals are supported`
9050
+ });
9051
+ }
9052
+ }
9053
+ });
9054
+ return errors.length ? errors[0] : validResult;
9055
+ }
9056
+ function getSymbols(node) {
9057
+ const symbols = /* @__PURE__ */ new Set();
9058
+ visit(node, (node2) => {
9059
+ if (node2.type === "Identifier") {
9060
+ symbols.add(node2.name);
9061
+ }
9062
+ });
9063
+ return Array.from(symbols);
9064
+ }
9065
+ function compile(expression) {
9066
+ return (0, import_jsep.default)(expression);
9067
+ }
8747
9068
 
8748
9069
  // src/fetch-map/layer-map.ts
8749
9070
  init_cjs_shims();
@@ -9342,6 +9663,37 @@ function formatDate(value) {
9342
9663
  function formatTimestamp(value) {
9343
9664
  return String(Math.floor(new Date(value).getTime() / 1e3));
9344
9665
  }
9666
+ function roundedPow10(exp) {
9667
+ const raw = Math.pow(10, exp);
9668
+ if (exp < 0) {
9669
+ const shift = Math.pow(10, -exp);
9670
+ return Math.round(raw * shift) / shift;
9671
+ }
9672
+ return raw;
9673
+ }
9674
+ function getLog10ScaleSteps({
9675
+ min: min2,
9676
+ max: max2,
9677
+ steps
9678
+ }) {
9679
+ if (min2 === 0) {
9680
+ if (max2 === Infinity) {
9681
+ return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9682
+ }
9683
+ const maxLog = Math.log10(max2);
9684
+ const endExponent = Math.ceil(maxLog);
9685
+ const startExponent = endExponent - steps + 1;
9686
+ return [...Array(steps - 1)].map(
9687
+ (_v, i) => roundedPow10(startExponent + i)
9688
+ );
9689
+ } else {
9690
+ const minLog = Math.log10(min2);
9691
+ const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9692
+ return [...Array(steps - 1)].map(
9693
+ (_v, i) => roundedPow10(startExponent + i)
9694
+ );
9695
+ }
9696
+ }
9345
9697
 
9346
9698
  // src/fetch-map/layer-map.ts
9347
9699
  var SCALE_FUNCS = {
@@ -9358,7 +9710,19 @@ var SCALE_FUNCS = {
9358
9710
  function identity2(v2) {
9359
9711
  return v2;
9360
9712
  }
9713
+ var hexToRGB = (c) => {
9714
+ const { r, g, b } = rgb(c);
9715
+ return [r, g, b];
9716
+ };
9717
+ var rgbToHex = (c) => {
9718
+ const [r, g, b] = c;
9719
+ const rStr = r.toString(16).padStart(2, "0");
9720
+ const gStr = g.toString(16).padStart(2, "0");
9721
+ const bStr = b.toString(16).padStart(2, "0");
9722
+ return `#${rStr}${gStr}${bStr}`.toUpperCase();
9723
+ };
9361
9724
  var UNKNOWN_COLOR = "#868d91";
9725
+ var UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
9362
9726
  var OPACITY_MAP = {
9363
9727
  getFillColor: "opacity",
9364
9728
  getLineColor: "strokeOpacity",
@@ -9391,6 +9755,12 @@ var sharedPropMap = {
9391
9755
  wireframe: "wireframe"
9392
9756
  }
9393
9757
  };
9758
+ var rasterPropsMap = {
9759
+ isVisible: "visible",
9760
+ visConfig: {
9761
+ opacity: "opacity"
9762
+ }
9763
+ };
9394
9764
  var customMarkersPropsMap = {
9395
9765
  color: "getIconColor",
9396
9766
  visConfig: {
@@ -9434,6 +9804,12 @@ function getLayerProps(type, config2, dataset) {
9434
9804
  `Outdated layer type: ${type}. Please open map in CARTO Builder to automatically migrate.`
9435
9805
  );
9436
9806
  }
9807
+ if (type === "raster") {
9808
+ return {
9809
+ propMap: rasterPropsMap,
9810
+ defaultProps: {}
9811
+ };
9812
+ }
9437
9813
  let basePropMap = sharedPropMap;
9438
9814
  if (config2.visConfig?.customMarkers) {
9439
9815
  basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
@@ -9454,16 +9830,19 @@ function getLayerProps(type, config2, dataset) {
9454
9830
  }
9455
9831
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9456
9832
  if (scaleType === "ordinal" || scaleType === "point") {
9833
+ if (!attribute.categories) {
9834
+ return [0, 1];
9835
+ }
9457
9836
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9458
9837
  }
9459
9838
  if (scaleType === "quantile" && attribute.quantiles) {
9460
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9839
+ return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9461
9840
  }
9462
9841
  let { min: min2 } = attribute;
9463
9842
  if (scaleType === "log" && min2 === 0) {
9464
9843
  min2 = 1e-5;
9465
9844
  }
9466
- return [min2, attribute.max];
9845
+ return [min2 ?? 0, attribute.max ?? 1];
9467
9846
  }
9468
9847
  function domainFromValues(values, scaleType) {
9469
9848
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9484,12 +9863,14 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9484
9863
  if (data.tilestats) {
9485
9864
  const { attributes } = data.tilestats.layers[0];
9486
9865
  const attribute = attributes.find((a) => a.attribute === name);
9487
- return domainFromAttribute(attribute, scaleType, scaleLength);
9866
+ if (attribute) {
9867
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9868
+ }
9488
9869
  }
9489
9870
  return [0, 1];
9490
9871
  }
9491
9872
  function normalizeAccessor(accessor, data) {
9492
- if (data.features || data.tilestats) {
9873
+ if (data.features || data.tilestats || data.raster_metadata) {
9493
9874
  return (object, info) => {
9494
9875
  if (object) {
9495
9876
  return accessor(object.properties || object.__source.object.properties);
@@ -9522,46 +9903,75 @@ function findAccessorKey(keys, properties) {
9522
9903
  return keys;
9523
9904
  }
9524
9905
  function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range }, opacity, data) {
9525
- const scale2 = calculateLayerScale(
9906
+ const { scale: scale2, domain } = calculateLayerScale(
9526
9907
  colorColumn || name,
9527
- scaleType,
9908
+ colorColumn ? "identity" : scaleType,
9528
9909
  range,
9529
9910
  data
9530
9911
  );
9531
9912
  const alpha = opacityToAlpha(opacity);
9532
- let accessorKeys = getAccessorKeys(name, aggregation);
9913
+ let accessorKeys = getAccessorKeys(colorColumn || name, aggregation);
9533
9914
  const accessor = (properties) => {
9534
9915
  if (!(accessorKeys[0] in properties)) {
9535
9916
  accessorKeys = findAccessorKey(accessorKeys, properties);
9536
9917
  }
9537
9918
  const propertyValue = properties[accessorKeys[0]];
9538
- const { r, g, b } = rgb(scale2(propertyValue));
9539
- return [r, g, b, propertyValue === null ? 0 : alpha];
9919
+ const scaled = scale2(propertyValue);
9920
+ const rgb2 = typeof scaled === "string" ? hexToRGB(scaled) : scaled;
9921
+ return [...rgb2, propertyValue === null ? 0 : alpha];
9922
+ };
9923
+ return {
9924
+ accessor: normalizeAccessor(accessor, data),
9925
+ scaleDomain: scale2.domain(),
9926
+ domain,
9927
+ range: (scale2.range() || []).map(rgbToHex)
9540
9928
  };
9541
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
9542
9929
  }
9543
9930
  function calculateLayerScale(name, scaleType, range, data) {
9544
- const scale2 = SCALE_FUNCS[scaleType]();
9545
9931
  let domain = [];
9932
+ let scaleDomain;
9546
9933
  let scaleColor = [];
9547
- if (scaleType !== "identity") {
9548
- const { colorMap, colors } = range;
9549
- if (Array.isArray(colorMap)) {
9934
+ const { colors } = range;
9935
+ if (scaleType === "custom") {
9936
+ domain = calculateDomain(data, name, scaleType, colors.length);
9937
+ const [min2, max2] = domain;
9938
+ if (range.uiCustomScaleType === "logarithmic") {
9939
+ scaleDomain = getLog10ScaleSteps({
9940
+ min: min2,
9941
+ max: max2,
9942
+ steps: colors.length
9943
+ });
9944
+ scaleColor = colors;
9945
+ } else if (range.colorMap) {
9946
+ const { colorMap } = range;
9947
+ scaleDomain = [];
9550
9948
  colorMap.forEach(([value, color2]) => {
9551
- domain.push(value);
9949
+ scaleDomain.push(Number(value));
9552
9950
  scaleColor.push(color2);
9553
9951
  });
9554
- } else {
9555
- domain = calculateDomain(data, name, scaleType, colors.length);
9556
- scaleColor = colors;
9557
9952
  }
9953
+ } else if (scaleType !== "identity") {
9954
+ domain = calculateDomain(data, name, scaleType, colors.length);
9955
+ scaleColor = colors;
9558
9956
  if (scaleType === "ordinal") {
9559
9957
  domain = domain.slice(0, scaleColor.length);
9560
9958
  }
9561
9959
  }
9960
+ return {
9961
+ scale: createColorScale(
9962
+ scaleType,
9963
+ scaleDomain || domain,
9964
+ scaleColor.map(hexToRGB),
9965
+ UNKNOWN_COLOR_RGB
9966
+ ),
9967
+ domain
9968
+ };
9969
+ }
9970
+ function createColorScale(scaleType, domain, range, unknown) {
9971
+ const scale2 = SCALE_FUNCS[scaleType]();
9562
9972
  scale2.domain(domain);
9563
- scale2.range(scaleColor);
9564
- scale2.unknown(UNKNOWN_COLOR);
9973
+ scale2.range(range);
9974
+ scale2.unknown(unknown);
9565
9975
  return scale2;
9566
9976
  }
9567
9977
  var FALLBACK_ICON = "data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==";
@@ -9611,9 +10021,13 @@ function negateAccessor(accessor) {
9611
10021
  }
9612
10022
  function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9613
10023
  const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
9614
- if (scaleType) {
10024
+ let domain = [];
10025
+ if (scaleType && range) {
9615
10026
  if (aggregation !== AggregationTypes.Count) {
9616
- scale2.domain(calculateDomain(data, name, scaleType));
10027
+ domain = calculateDomain(data, name, scaleType);
10028
+ scale2.domain(domain);
10029
+ } else {
10030
+ domain = scale2.domain();
9617
10031
  }
9618
10032
  scale2.range(range);
9619
10033
  }
@@ -9625,7 +10039,12 @@ function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
9625
10039
  const propertyValue = properties[accessorKeys[0]];
9626
10040
  return scale2(propertyValue);
9627
10041
  };
9628
- return { accessor: normalizeAccessor(accessor, data), scale: scale2 };
10042
+ return {
10043
+ accessor: normalizeAccessor(accessor, data),
10044
+ domain,
10045
+ scaleDomain: domain,
10046
+ range
10047
+ };
9629
10048
  }
9630
10049
  var FORMATS = {
9631
10050
  date: formatDate,
@@ -9676,13 +10095,424 @@ function calculateClusterTextFontSize(radius) {
9676
10095
  return 11;
9677
10096
  }
9678
10097
 
10098
+ // src/fetch-map/raster-layer.ts
10099
+ var UNKNOWN_COLOR2 = [134, 141, 145];
10100
+ var RASTER_COLOR_BANDS = ["red", "green", "blue"];
10101
+ function getHasDataPredicate(noData) {
10102
+ if (noData === "nan") {
10103
+ return (v2) => !isNaN(v2);
10104
+ }
10105
+ if (typeof noData === "string") {
10106
+ noData = parseFloat(noData);
10107
+ }
10108
+ if (typeof noData === "number") {
10109
+ return (v2) => v2 !== noData && !isNaN(v2);
10110
+ }
10111
+ return () => true;
10112
+ }
10113
+ function createRasterColumnLayerDataTransform(transform) {
10114
+ return (data) => {
10115
+ if (!data || !("data" in data) || !data?.data?.cells?.numericProps) {
10116
+ return data;
10117
+ }
10118
+ return transform(data);
10119
+ };
10120
+ }
10121
+ function createEvaluationContext(numericProps, noData) {
10122
+ const hasData = getHasDataPredicate(noData);
10123
+ const bands = Object.entries(numericProps).map(([bandName, { value }]) => ({
10124
+ bandName,
10125
+ values: value,
10126
+ copied: false
10127
+ }));
10128
+ const length2 = bands[0].values.length;
10129
+ for (let i = 0; i < length2; i++) {
10130
+ let hasSomeData = false;
10131
+ for (let j = 0; j < bands.length; j++) {
10132
+ hasSomeData = hasSomeData || hasData(bands[j].values[i]);
10133
+ }
10134
+ if (!hasSomeData) {
10135
+ for (let j = 0; j < bands.length; j++) {
10136
+ if (!bands[j].copied) {
10137
+ bands[j].copied = true;
10138
+ bands[j].values = Array.from(bands[j].values);
10139
+ }
10140
+ bands[j].values[i] = NaN;
10141
+ }
10142
+ }
10143
+ }
10144
+ const context = bands.reduce(
10145
+ (agg, { bandName, values }) => {
10146
+ agg[bandName] = values;
10147
+ return agg;
10148
+ },
10149
+ {}
10150
+ );
10151
+ return context;
10152
+ }
10153
+ function createExprDataTransform({
10154
+ colorBand,
10155
+ rasterMetadata,
10156
+ usedSymbols
10157
+ }) {
10158
+ if (!colorBand || !colorBand.type || colorBand.type === "none") {
10159
+ return void 0;
10160
+ }
10161
+ const expr = colorBand?.type === "expression" ? colorBand.value : void 0;
10162
+ const vecExprEvaluator = expr ? createVecExprEvaluator(expr) : void 0;
10163
+ const dataTransform = createRasterColumnLayerDataTransform(
10164
+ (dataWrapped) => {
10165
+ const data = dataWrapped.data;
10166
+ if (expr) {
10167
+ const cachedResult = dataWrapped.customExpressionResults?.[expr];
10168
+ if (cachedResult) {
10169
+ return dataWrapped;
10170
+ }
10171
+ }
10172
+ let context = dataWrapped.expressionEvalContext;
10173
+ if (!context) {
10174
+ const usedNumericProps = usedSymbols.reduce(
10175
+ (acc, symbol) => {
10176
+ acc[symbol] = data.cells.numericProps[symbol];
10177
+ return acc;
10178
+ },
10179
+ {}
10180
+ );
10181
+ context = createEvaluationContext(
10182
+ usedNumericProps,
10183
+ rasterMetadata.nodata
10184
+ );
10185
+ dataWrapped = {
10186
+ ...dataWrapped,
10187
+ expressionEvalContext: context
10188
+ };
10189
+ }
10190
+ if (!vecExprEvaluator || !expr) return dataWrapped;
10191
+ const evalResult = vecExprEvaluator(context);
10192
+ return {
10193
+ ...dataWrapped,
10194
+ customExpressionResults: {
10195
+ ...dataWrapped.customExpressionResults,
10196
+ [expr]: evalResult
10197
+ }
10198
+ };
10199
+ }
10200
+ );
10201
+ return dataTransform;
10202
+ }
10203
+ function combineDataTransforms(dataTransforms) {
10204
+ const actualTransforms = dataTransforms.filter((v2) => v2);
10205
+ if (actualTransforms.length === 0) return void 0;
10206
+ if (actualTransforms.length === 1) return actualTransforms[0];
10207
+ return (data) => actualTransforms.reduce(
10208
+ (aggData, transformFun) => transformFun(aggData),
10209
+ data
10210
+ );
10211
+ }
10212
+ function createRgbToColorBufferDataTransform({
10213
+ bandDefs,
10214
+ attribute
10215
+ }) {
10216
+ return createRasterColumnLayerDataTransform(
10217
+ (dataWrapped) => {
10218
+ const length2 = dataWrapped.length;
10219
+ const getBandBufferOrValue = (colorBand) => {
10220
+ if (colorBand?.type === "expression") {
10221
+ return dataWrapped.customExpressionResults?.[colorBand.value];
10222
+ }
10223
+ if (colorBand?.type === "band") {
10224
+ return dataWrapped.expressionEvalContext?.[colorBand.value];
10225
+ }
10226
+ return 0;
10227
+ };
10228
+ const red = getBandBufferOrValue(bandDefs.red);
10229
+ const green = getBandBufferOrValue(bandDefs.green);
10230
+ const blue = getBandBufferOrValue(bandDefs.blue);
10231
+ const colorBuffer = new Uint8Array(length2 * 4);
10232
+ for (let inputIndex = 0, outputIndex = 0; inputIndex < length2; inputIndex++, outputIndex += 4) {
10233
+ const redRaw = typeof red === "number" ? red : red ? red[inputIndex] : NaN;
10234
+ const greenRaw = typeof green === "number" ? green : green ? green[inputIndex] : NaN;
10235
+ const blueRaw = typeof blue === "number" ? blue : blue ? blue[inputIndex] : NaN;
10236
+ if (isNaN(redRaw) && isNaN(greenRaw) && isNaN(blueRaw)) {
10237
+ bufferSetRgba(colorBuffer, outputIndex, 0, 0, 0, 0);
10238
+ } else {
10239
+ bufferSetRgba(
10240
+ colorBuffer,
10241
+ outputIndex,
10242
+ redRaw,
10243
+ greenRaw,
10244
+ blueRaw,
10245
+ 255
10246
+ );
10247
+ }
10248
+ }
10249
+ dataWrapped.customExpressionResults = void 0;
10250
+ dataWrapped.expressionEvalContext = void 0;
10251
+ return {
10252
+ ...dataWrapped,
10253
+ attributes: {
10254
+ [attribute]: colorBuffer
10255
+ }
10256
+ };
10257
+ }
10258
+ );
10259
+ }
10260
+ function getUsedSymbols(colorBands) {
10261
+ return Array.from(
10262
+ colorBands.reduce((symbols, band) => {
10263
+ if (band.type === "expression") {
10264
+ const expressionSymbols = createVecExprEvaluator(band.value)?.symbols || [];
10265
+ expressionSymbols.forEach((symbol) => symbols.add(symbol));
10266
+ }
10267
+ if (band.type === "band") {
10268
+ symbols.add(band.value);
10269
+ }
10270
+ return symbols;
10271
+ }, /* @__PURE__ */ new Set())
10272
+ );
10273
+ }
10274
+ function getRasterTileLayerStylePropsRgb({
10275
+ layerConfig,
10276
+ rasterMetadata,
10277
+ visualChannels
10278
+ }) {
10279
+ const { visConfig } = layerConfig;
10280
+ const { colorBands } = visConfig;
10281
+ const bandDefs = {
10282
+ red: colorBands?.find((band) => band.band === "red"),
10283
+ green: colorBands?.find((band) => band.band === "green"),
10284
+ blue: colorBands?.find((band) => band.band === "blue")
10285
+ };
10286
+ const rgbToInstanceFillColorsDataTransform = createRgbToColorBufferDataTransform({
10287
+ bandDefs,
10288
+ attribute: "instanceFillColors"
10289
+ });
10290
+ const usedSymbols = colorBands ? getUsedSymbols(colorBands) : [];
10291
+ const bandTransforms = RASTER_COLOR_BANDS.map(
10292
+ (band) => createExprDataTransform({
10293
+ colorBand: bandDefs[band],
10294
+ rasterMetadata,
10295
+ usedSymbols
10296
+ })
10297
+ );
10298
+ const combinedDataTransform = combineDataTransforms([
10299
+ ...bandTransforms,
10300
+ rgbToInstanceFillColorsDataTransform
10301
+ ]);
10302
+ return {
10303
+ dataTransform: combinedDataTransform,
10304
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10305
+ layerConfig,
10306
+ visualChannels
10307
+ })
10308
+ };
10309
+ }
10310
+ function createBandColorScaleDataTransform({
10311
+ bandName,
10312
+ scaleFun,
10313
+ nodata,
10314
+ attribute
10315
+ }) {
10316
+ const hasData = getHasDataPredicate(nodata);
10317
+ return createRasterColumnLayerDataTransform(
10318
+ (dataWrapped) => {
10319
+ const length2 = dataWrapped.length;
10320
+ const bandBuffer = dataWrapped.data.cells.numericProps[bandName].value;
10321
+ const colorBuffer = new Uint8Array(length2 * 4);
10322
+ for (let i = 0; i < length2; i++) {
10323
+ const rawValue = bandBuffer[i];
10324
+ if (!hasData(rawValue)) {
10325
+ bufferSetRgba(colorBuffer, i * 4, 0, 0, 0, 0);
10326
+ } else {
10327
+ const colorRgb = scaleFun(rawValue);
10328
+ bufferSetRgba(
10329
+ colorBuffer,
10330
+ i * 4,
10331
+ colorRgb[0],
10332
+ colorRgb[1],
10333
+ colorRgb[2],
10334
+ 255
10335
+ );
10336
+ }
10337
+ }
10338
+ return {
10339
+ ...dataWrapped,
10340
+ attributes: {
10341
+ [attribute]: colorBuffer
10342
+ }
10343
+ };
10344
+ }
10345
+ );
10346
+ }
10347
+ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10348
+ if (scaleType === "ordinal") {
10349
+ return colorRange.colorMap?.map(([value]) => value) || [];
10350
+ }
10351
+ if (scaleType === "custom") {
10352
+ if (colorRange.uiCustomScaleType === "logarithmic") {
10353
+ return getLog10ScaleSteps({
10354
+ min: band.stats.min,
10355
+ max: band.stats.max,
10356
+ steps: colorRange.colors.length
10357
+ });
10358
+ } else {
10359
+ return colorRange.colorMap?.map(([value]) => value) || [];
10360
+ }
10361
+ }
10362
+ const scaleLength = colorRange.colors.length;
10363
+ if (scaleType === "quantile") {
10364
+ const quantiles = band.stats.quantiles?.[scaleLength];
10365
+ if (!quantiles) {
10366
+ return [0, 1];
10367
+ }
10368
+ return [band.stats.min, ...quantiles, band.stats.max];
10369
+ }
10370
+ return [band.stats.min, band.stats.max];
10371
+ }
10372
+ function getRasterTileLayerStylePropsScaledBand({
10373
+ layerConfig,
10374
+ rasterMetadata,
10375
+ visualChannels
10376
+ }) {
10377
+ const { visConfig } = layerConfig;
10378
+ const { colorField } = visualChannels;
10379
+ const { rasterStyleType } = visConfig;
10380
+ const colorRange = rasterStyleType === "ColorRange" ? visConfig.colorRange : visConfig.uniqueValuesColorRange;
10381
+ const scaleType = rasterStyleType === "ColorRange" ? visualChannels.colorScale : "ordinal";
10382
+ const bandInfo = rasterMetadata.bands.find(
10383
+ (band) => band.name === colorField?.name
10384
+ );
10385
+ if (!colorField?.name || !scaleType || !colorRange || !bandInfo) {
10386
+ return {};
10387
+ }
10388
+ const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
10389
+ const scaleFun = createColorScale(
10390
+ scaleType,
10391
+ domain,
10392
+ colorRange.colors.map(hexToRGB2),
10393
+ UNKNOWN_COLOR2
10394
+ );
10395
+ const bandColorScaleDataTransform = createBandColorScaleDataTransform({
10396
+ bandName: bandInfo.name,
10397
+ scaleFun,
10398
+ nodata: bandInfo?.nodata ?? rasterMetadata.nodata,
10399
+ attribute: "instanceFillColors"
10400
+ });
10401
+ return {
10402
+ dataTransform: bandColorScaleDataTransform,
10403
+ updateTriggers: getRasterTileLayerUpdateTriggers({
10404
+ layerConfig,
10405
+ visualChannels
10406
+ })
10407
+ };
10408
+ }
10409
+ function getRasterTileLayerStyleProps({
10410
+ layerConfig,
10411
+ visualChannels,
10412
+ rasterMetadata
10413
+ }) {
10414
+ const { visConfig } = layerConfig;
10415
+ const { rasterStyleType } = visConfig;
10416
+ if (rasterStyleType === "Rgb") {
10417
+ return getRasterTileLayerStylePropsRgb({
10418
+ layerConfig,
10419
+ rasterMetadata,
10420
+ visualChannels
10421
+ });
10422
+ } else {
10423
+ return getRasterTileLayerStylePropsScaledBand({
10424
+ layerConfig,
10425
+ rasterMetadata,
10426
+ visualChannels
10427
+ });
10428
+ }
10429
+ }
10430
+ function getRasterTileLayerUpdateTriggers({
10431
+ layerConfig,
10432
+ visualChannels
10433
+ }) {
10434
+ const { visConfig } = layerConfig;
10435
+ const { rasterStyleType } = visConfig;
10436
+ const getFillColorUpdateTriggers = {
10437
+ rasterStyleType
10438
+ };
10439
+ if (rasterStyleType === "ColorRange") {
10440
+ getFillColorUpdateTriggers.colorRange = visConfig.colorRange?.colors;
10441
+ getFillColorUpdateTriggers.colorMap = visConfig.colorRange?.colorMap;
10442
+ getFillColorUpdateTriggers.colorScale = visualChannels.colorScale;
10443
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10444
+ } else if (rasterStyleType === "UniqueValues") {
10445
+ getFillColorUpdateTriggers.colorMap = visConfig.uniqueValuesColorRange?.colorMap;
10446
+ getFillColorUpdateTriggers.colorFieldId = visualChannels.colorField?.name;
10447
+ } else if (rasterStyleType === "Rgb") {
10448
+ getFillColorUpdateTriggers.colorBands = visConfig.colorBands;
10449
+ }
10450
+ return {
10451
+ getFillColor: getFillColorUpdateTriggers
10452
+ };
10453
+ }
10454
+ function bufferSetRgba(target, index, r, g, b, a) {
10455
+ target[index + 0] = r;
10456
+ target[index + 1] = g;
10457
+ target[index + 2] = b;
10458
+ target[index + 3] = a;
10459
+ }
10460
+ function hexToRGB2(hexColor) {
10461
+ const r = parseInt(hexColor.slice(1, 3), 16);
10462
+ const g = parseInt(hexColor.slice(3, 5), 16);
10463
+ const b = parseInt(hexColor.slice(5, 7), 16);
10464
+ return [r, g, b];
10465
+ }
10466
+
10467
+ // src/fetch-map/fetch-map.ts
10468
+ init_cjs_shims();
10469
+
9679
10470
  // src/fetch-map/parse-map.ts
10471
+ init_cjs_shims();
10472
+ function getLayerDescriptor({
10473
+ mapConfig,
10474
+ layer,
10475
+ dataset
10476
+ }) {
10477
+ const { filters, visState } = mapConfig;
10478
+ const { layerBlending, interactionConfig } = visState;
10479
+ const { id, type, config: config2, visualChannels } = layer;
10480
+ const { data, id: datasetId } = dataset;
10481
+ const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config2, dataset);
10482
+ const styleProps = createStyleProps(config2, propMap);
10483
+ const { channelProps, scales } = createChannelProps(
10484
+ id,
10485
+ type,
10486
+ config2,
10487
+ visualChannels,
10488
+ data,
10489
+ dataset
10490
+ );
10491
+ const layerDescriptor = {
10492
+ type,
10493
+ filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[datasetId],
10494
+ props: {
10495
+ id,
10496
+ data,
10497
+ ...defaultProps2,
10498
+ ...createInteractionProps(interactionConfig),
10499
+ ...styleProps,
10500
+ ...channelProps,
10501
+ ...createParametersProp(layerBlending, styleProps.parameters || {}),
10502
+ // Must come after style
10503
+ ...createLoadOptions(data.accessToken)
10504
+ },
10505
+ scales
10506
+ };
10507
+ return layerDescriptor;
10508
+ }
9680
10509
  function parseMap(json) {
9681
10510
  const { keplerMapConfig, datasets, token } = json;
9682
10511
  assert2(keplerMapConfig.version === "v1", "Only support Kepler v1");
9683
- const config2 = keplerMapConfig.config;
9684
- const { filters, mapState, mapStyle, popupSettings, legendSettings } = config2;
9685
- const { layers, layerBlending, interactionConfig } = config2.visState;
10512
+ const mapConfig = keplerMapConfig.config;
10513
+ const { mapState, mapStyle, popupSettings, legendSettings, visState } = mapConfig;
10514
+ const { layers } = visState;
10515
+ const layersReverse = [...layers].reverse();
9686
10516
  return {
9687
10517
  id: json.id,
9688
10518
  title: json.title,
@@ -9695,45 +10525,19 @@ function parseMap(json) {
9695
10525
  popupSettings,
9696
10526
  legendSettings,
9697
10527
  token,
9698
- layers: layers.reverse().map(({ id, type, config: config3, visualChannels }) => {
10528
+ layers: layersReverse.map((layer) => {
9699
10529
  try {
9700
- const { dataId } = config3;
10530
+ const { dataId } = layer.config;
9701
10531
  const dataset = datasets.find(
9702
10532
  (d) => d.id === dataId
9703
10533
  );
9704
10534
  assert2(dataset, `No dataset matching dataId: ${dataId}`);
9705
- const { data } = dataset;
9706
- assert2(data, `No data loaded for dataId: ${dataId}`);
9707
- const { propMap, defaultProps: defaultProps2 } = getLayerProps(type, config3, dataset);
9708
- const styleProps = createStyleProps(config3, propMap);
9709
- const { channelProps, scales } = createChannelProps(
9710
- id,
9711
- type,
9712
- config3,
9713
- visualChannels,
9714
- data,
10535
+ const layerDescriptor = getLayerDescriptor({
10536
+ mapConfig,
10537
+ layer,
9715
10538
  dataset
9716
- );
9717
- const layer = {
9718
- type,
9719
- filters: isEmptyObject(filters) || isRemoteCalculationSupported(dataset) ? void 0 : filters[dataId],
9720
- props: {
9721
- id,
9722
- data,
9723
- ...defaultProps2,
9724
- ...createInteractionProps(interactionConfig),
9725
- ...styleProps,
9726
- ...channelProps,
9727
- ...createParametersProp(
9728
- layerBlending,
9729
- styleProps.parameters || {}
9730
- ),
9731
- // Must come after style
9732
- ...createLoadOptions(token)
9733
- },
9734
- scales
9735
- };
9736
- return layer;
10539
+ });
10540
+ return layerDescriptor;
9737
10541
  } catch (e) {
9738
10542
  console.error(e.message);
9739
10543
  return void 0;
@@ -9798,43 +10602,63 @@ function createStyleProps(config2, mapping) {
9798
10602
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
9799
10603
  return result;
9800
10604
  }
9801
- function domainAndRangeFromScale(scale2) {
9802
- return {
9803
- domain: scale2.domain(),
9804
- range: scale2.range()
9805
- };
9806
- }
9807
10605
  function createChannelProps(id, layerType, config2, visualChannels, data, dataset) {
9808
- const {
9809
- colorField,
9810
- colorScale,
9811
- radiusField,
9812
- radiusScale,
9813
- strokeColorField,
9814
- strokeColorScale,
9815
- weightField
9816
- } = visualChannels;
9817
- const { heightField, heightScale } = visualChannels;
10606
+ if (layerType === "raster") {
10607
+ const rasterMetadata = data.raster_metadata;
10608
+ if (!rasterMetadata) {
10609
+ return {
10610
+ channelProps: {},
10611
+ scales: {}
10612
+ };
10613
+ }
10614
+ const rasterStyleType = config2.visConfig.rasterStyleType;
10615
+ if (rasterStyleType === "Rgb") {
10616
+ return {
10617
+ channelProps: getRasterTileLayerStylePropsRgb({
10618
+ layerConfig: config2,
10619
+ rasterMetadata,
10620
+ visualChannels
10621
+ }),
10622
+ scales: {}
10623
+ // TODO
10624
+ };
10625
+ } else {
10626
+ return {
10627
+ channelProps: getRasterTileLayerStylePropsScaledBand({
10628
+ layerConfig: config2,
10629
+ visualChannels,
10630
+ rasterMetadata
10631
+ }),
10632
+ scales: {
10633
+ // TODO
10634
+ }
10635
+ };
10636
+ }
10637
+ }
9818
10638
  const { textLabel, visConfig } = config2;
9819
10639
  const result = {};
10640
+ const updateTriggers = {};
9820
10641
  const scales = {};
9821
- if (colorField) {
9822
- const { colorAggregation: aggregation, colorRange: range } = visConfig;
9823
- const { accessor, scale: scale2 } = getColorAccessor(
9824
- colorField,
9825
- colorScale,
9826
- { aggregation, range },
9827
- visConfig.opacity,
9828
- data
9829
- );
9830
- result.getFillColor = accessor;
9831
- scales.fillColor = {
9832
- field: colorField,
9833
- type: colorScale,
9834
- ...domainAndRangeFromScale(scale2)
9835
- };
9836
- } else if (visConfig.filled) {
9837
- scales.fillColor = {};
10642
+ {
10643
+ const { colorField, colorScale } = visualChannels;
10644
+ const { colorRange, colorAggregation } = visConfig;
10645
+ if (colorField && colorScale && colorRange) {
10646
+ const { accessor, ...scaleProps } = getColorAccessor(
10647
+ colorField,
10648
+ colorScale,
10649
+ { aggregation: colorAggregation, range: colorRange },
10650
+ visConfig.opacity,
10651
+ data
10652
+ );
10653
+ result.getFillColor = accessor;
10654
+ scales.fillColor = updateTriggers.getFillColor = {
10655
+ field: colorField,
10656
+ type: colorScale,
10657
+ ...scaleProps
10658
+ };
10659
+ } else {
10660
+ scales.fillColor = {};
10661
+ }
9838
10662
  }
9839
10663
  if (layerType === "clusterTile") {
9840
10664
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
@@ -9847,6 +10671,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9847
10671
  result.getWeight = (d) => {
9848
10672
  return d.properties[aggregationExpAlias];
9849
10673
  };
10674
+ updateTriggers.getWeight = aggregationExpAlias;
9850
10675
  result.getPointRadius = (d, info) => {
9851
10676
  return calculateClusterRadius(
9852
10677
  d.properties,
@@ -9855,11 +10680,16 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9855
10680
  aggregationExpAlias
9856
10681
  );
9857
10682
  };
10683
+ updateTriggers.getPointRadius = {
10684
+ aggregationExpAlias,
10685
+ radiusRange: visConfig.radiusRange
10686
+ };
9858
10687
  result.textCharacterSet = "auto";
9859
10688
  result.textFontFamily = "Inter, sans";
9860
10689
  result.textFontSettings = { sdf: true };
9861
10690
  result.textFontWeight = 600;
9862
10691
  result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
10692
+ updateTriggers.getText = aggregationExpAlias;
9863
10693
  result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
9864
10694
  result.textOutlineColor = [
9865
10695
  ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
@@ -9876,68 +10706,107 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9876
10706
  );
9877
10707
  return calculateClusterTextFontSize(radius);
9878
10708
  };
9879
- }
9880
- if (radiusField) {
9881
- const { accessor, scale: scale2 } = getSizeAccessor(
9882
- radiusField,
9883
- radiusScale,
9884
- visConfig.sizeAggregation,
9885
- visConfig.radiusRange || visConfig.sizeRange,
9886
- data
9887
- );
9888
- result.getPointRadius = accessor;
9889
- scales.pointRadius = {
9890
- field: radiusField,
9891
- type: radiusScale || "identity",
9892
- ...domainAndRangeFromScale(scale2)
10709
+ updateTriggers.getTextSize = {
10710
+ aggregationExpAlias,
10711
+ radiusRange: visConfig.radiusRange
9893
10712
  };
9894
10713
  }
9895
- if (strokeColorField) {
9896
- const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
9897
- const { strokeColorAggregation: aggregation, strokeColorRange: range } = visConfig;
9898
- const { accessor, scale: scale2 } = getColorAccessor(
9899
- strokeColorField,
9900
- strokeColorScale,
9901
- { aggregation, range },
9902
- opacity,
9903
- data
9904
- );
9905
- result.getLineColor = accessor;
9906
- scales.lineColor = {
9907
- field: strokeColorField,
9908
- type: strokeColorScale,
9909
- ...domainAndRangeFromScale(scale2)
9910
- };
10714
+ {
10715
+ const radiusRange = visConfig.radiusRange;
10716
+ const { radiusField, radiusScale } = visualChannels;
10717
+ if (radiusField && radiusRange && radiusScale) {
10718
+ const { accessor, ...scaleProps } = getSizeAccessor(
10719
+ radiusField,
10720
+ radiusScale,
10721
+ visConfig.sizeAggregation,
10722
+ radiusRange,
10723
+ data
10724
+ );
10725
+ result.getPointRadius = accessor;
10726
+ scales.pointRadius = updateTriggers.getPointRadius = {
10727
+ field: radiusField,
10728
+ type: radiusScale,
10729
+ ...scaleProps
10730
+ };
10731
+ }
9911
10732
  }
9912
- if (heightField && visConfig.enable3d) {
9913
- const { accessor, scale: scale2 } = getSizeAccessor(
9914
- heightField,
9915
- heightScale,
9916
- visConfig.heightAggregation,
9917
- visConfig.heightRange || visConfig.sizeRange,
9918
- data
9919
- );
9920
- result.getElevation = accessor;
9921
- scales.elevation = {
9922
- field: heightField,
9923
- type: heightScale || "identity",
9924
- ...domainAndRangeFromScale(scale2)
9925
- };
10733
+ {
10734
+ const strokeColorRange = visConfig.strokeColorRange;
10735
+ const { strokeColorScale, strokeColorField } = visualChannels;
10736
+ if (strokeColorField && strokeColorRange && strokeColorScale) {
10737
+ const { strokeColorAggregation: aggregation } = visConfig;
10738
+ const opacity = visConfig.strokeOpacity !== void 0 ? visConfig.strokeOpacity : 1;
10739
+ const { accessor, ...scaleProps } = getColorAccessor(
10740
+ strokeColorField,
10741
+ strokeColorScale,
10742
+ { aggregation, range: strokeColorRange },
10743
+ opacity,
10744
+ data
10745
+ );
10746
+ result.getLineColor = accessor;
10747
+ scales.lineColor = updateTriggers.getLineColor = {
10748
+ field: strokeColorField,
10749
+ type: strokeColorScale,
10750
+ ...scaleProps
10751
+ };
10752
+ }
9926
10753
  }
9927
- if (weightField) {
9928
- const { accessor, scale: scale2 } = getSizeAccessor(
9929
- weightField,
9930
- void 0,
9931
- visConfig.weightAggregation,
9932
- void 0,
9933
- data
9934
- );
9935
- result.getWeight = accessor;
9936
- scales.weight = {
9937
- field: weightField,
9938
- type: "identity",
9939
- ...domainAndRangeFromScale(scale2)
9940
- };
10754
+ {
10755
+ const { sizeField: strokeWidthField, sizeScale: strokeWidthScale } = visualChannels;
10756
+ const { sizeRange, sizeAggregation } = visConfig;
10757
+ if (strokeWidthField && sizeRange) {
10758
+ const { accessor, ...scaleProps } = getSizeAccessor(
10759
+ strokeWidthField,
10760
+ strokeWidthScale,
10761
+ sizeAggregation,
10762
+ sizeRange,
10763
+ data
10764
+ );
10765
+ result.getLineWidth = accessor;
10766
+ scales.lineWidth = updateTriggers.getLineWidth = {
10767
+ field: strokeWidthField,
10768
+ type: strokeWidthScale || "identity",
10769
+ ...scaleProps
10770
+ };
10771
+ }
10772
+ }
10773
+ {
10774
+ const { enable3d, heightRange } = visConfig;
10775
+ const { heightField, heightScale } = visualChannels;
10776
+ if (heightField && heightRange && enable3d) {
10777
+ const { accessor, ...scaleProps } = getSizeAccessor(
10778
+ heightField,
10779
+ heightScale,
10780
+ visConfig.heightAggregation,
10781
+ heightRange,
10782
+ data
10783
+ );
10784
+ result.getElevation = accessor;
10785
+ scales.elevation = updateTriggers.getElevation = {
10786
+ field: heightField,
10787
+ type: heightScale || "identity",
10788
+ ...scaleProps
10789
+ };
10790
+ }
10791
+ }
10792
+ {
10793
+ const { weightField } = visualChannels;
10794
+ const { weightAggregation } = visConfig;
10795
+ if (weightField && weightAggregation) {
10796
+ const { accessor, ...scaleProps } = getSizeAccessor(
10797
+ weightField,
10798
+ void 0,
10799
+ weightAggregation,
10800
+ void 0,
10801
+ data
10802
+ );
10803
+ result.getWeight = accessor;
10804
+ scales.weight = updateTriggers.getWeight = {
10805
+ field: weightField,
10806
+ type: "identity",
10807
+ ...scaleProps
10808
+ };
10809
+ }
9941
10810
  }
9942
10811
  if (visConfig.customMarkers) {
9943
10812
  const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
@@ -9954,6 +10823,12 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9954
10823
  { fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons },
9955
10824
  data
9956
10825
  );
10826
+ updateTriggers.getIcon = {
10827
+ customMarkersUrl,
10828
+ customMarkersRange,
10829
+ maxIconSize,
10830
+ useMaskedIcons
10831
+ };
9957
10832
  result._subLayerProps = {
9958
10833
  "points-icon": {
9959
10834
  loadOptions: {
@@ -9970,9 +10845,11 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9970
10845
  };
9971
10846
  if (getFillColor && useMaskedIcons) {
9972
10847
  result.getIconColor = getFillColor;
10848
+ updateTriggers.getIconColor = updateTriggers.getFillColor;
9973
10849
  }
9974
10850
  if (getPointRadius) {
9975
10851
  result.getIconSize = getPointRadius;
10852
+ updateTriggers.getIconSize = updateTriggers.getPointRadius;
9976
10853
  }
9977
10854
  if (visualChannels.rotationField) {
9978
10855
  const { accessor } = getSizeAccessor(
@@ -9983,6 +10860,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
9983
10860
  data
9984
10861
  );
9985
10862
  result.getIconAngle = negateAccessor(accessor);
10863
+ updateTriggers.getIconAngle = updateTriggers.getRotationField;
9986
10864
  }
9987
10865
  } else if (layerType === "tileset") {
9988
10866
  result.pointType = "circle";
@@ -10027,7 +10905,13 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10027
10905
  }
10028
10906
  };
10029
10907
  }
10030
- return { channelProps: result, scales };
10908
+ return {
10909
+ channelProps: {
10910
+ ...result,
10911
+ updateTriggers
10912
+ },
10913
+ scales
10914
+ };
10031
10915
  }
10032
10916
  function createLoadOptions(accessToken) {
10033
10917
  return {
@@ -10683,9 +11567,16 @@ function hashBuckets(initialCount) {
10683
11567
  WidgetSource,
10684
11568
  WidgetTableSource,
10685
11569
  WidgetTilesetSource,
11570
+ _ErrorCode,
11571
+ _applyLayerGroupFilters,
10686
11572
  _buildFeatureFilter,
11573
+ _createVecExprEvaluator,
10687
11574
  _domainFromValues,
11575
+ _evaluateVecExpr,
10688
11576
  _getHexagonResolution,
11577
+ _getLog10ScaleSteps,
11578
+ _getRasterTileLayerStyleProps,
11579
+ _validateVecExprSyntax,
10689
11580
  addFilter,
10690
11581
  aggregate,
10691
11582
  aggregationFunctions,
@@ -10698,9 +11589,11 @@ function hashBuckets(initialCount) {
10698
11589
  buildStatsUrl,
10699
11590
  calculateClusterRadius,
10700
11591
  calculateClusterTextFontSize,
11592
+ calculateLayerScale,
10701
11593
  clearDefaultRequestCache,
10702
11594
  clearFilters,
10703
11595
  configureSource,
11596
+ createColorScale,
10704
11597
  createPolygonSpatialFilter,
10705
11598
  createViewportSpatialFilter,
10706
11599
  fetchBasemapProps,
@@ -10715,6 +11608,7 @@ function hashBuckets(initialCount) {
10715
11608
  getDefaultAggregationExpColumnAliasForLayerType,
10716
11609
  getFilter,
10717
11610
  getIconUrlAccessor,
11611
+ getLayerDescriptor,
10718
11612
  getLayerProps,
10719
11613
  getMaxMarkerSize,
10720
11614
  getSizeAccessor,