@carto/kepler.gl 0.0.65-alpha.labels.3 → 0.0.65-alpha.labels.4

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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@carto/kepler.gl",
3
3
  "author": "CARTO",
4
4
  "homepage": "https://github.com/CartoDB/carto-kepler#readme",
5
- "version": "0.0.65-alpha.labels.3",
5
+ "version": "0.0.65-alpha.labels.4",
6
6
  "description": "kepler.gl is a webgl based application to visualize large scale location data in the browser",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
@@ -303,7 +303,6 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
303
303
  return;
304
304
  }
305
305
 
306
- throw error;
307
306
  const errorMessage = `An error in deck.gl: ${error?.message} in ${layer?.id}`;
308
307
  const notificationId = `${layer?.id}-${error?.message}`;
309
308
 
@@ -16,7 +16,7 @@ class EnhancedTextLayer extends TextLayer {
16
16
  }
17
17
  }
18
18
 
19
- // TODO fix in deck.gl
19
+ // TODO remove once https://github.com/visgl/deck.gl/pull/7757 out
20
20
  TextLayer.defaultProps.fontSettings = {type: 'object', value: {}, optional: true, compare: 1};
21
21
 
22
22
  const defaultProps = {
@@ -41,9 +41,13 @@ export class PointLabelLayer extends CompositeLayer {
41
41
 
42
42
  // Place secondary label under main label (spacing 1 / 3 main label font size)
43
43
  const yOffset = secondary ? (1 + 1 / 3) * sizeScale : 0;
44
- const xPadding = sizeScale / 4; // Padding based on font size (font size / 4)
45
- const yPadding = sizeScale;
46
- const radiusPadding = 1 + 1 / 4; // Padding based on point radius (radius/ 4)
44
+
45
+ // Padding based on font size (font size / 4)
46
+ const xPadding = sizeScale / 4;
47
+ const yPadding = sizeScale + 1 / 4;
48
+
49
+ // Padding based on point radius (radius/ 4)
50
+ const radiusPadding = 1 + 1 / 4;
47
51
 
48
52
  return typeof getRadius === 'function'
49
53
  ? d => {
@@ -145,7 +149,8 @@ export class PointLabelLayer extends CompositeLayer {
145
149
  getSecondaryColor,
146
150
  getSecondaryText,
147
151
  secondaryOutlineColor,
148
- secondarySizeScale
152
+ secondarySizeScale,
153
+ updateTriggers
149
154
  } = this.props;
150
155
  const getPixelOffset = this.calculatePixelOffset(false);
151
156
  const backgroundPadding = this.calculateBackgroundPadding(getPixelOffset);
@@ -160,6 +165,7 @@ export class PointLabelLayer extends CompositeLayer {
160
165
  this.renderTextLayer('secondary', {
161
166
  getText: getSecondaryText,
162
167
  getPixelOffset: this.calculatePixelOffset(true),
168
+ updateTriggers: {getText: updateTriggers.getSecondaryText},
163
169
 
164
170
  // Optional overrides
165
171
  ...(getSecondaryColor && {getColor: getSecondaryColor}),
Binary file
@@ -1317,20 +1317,24 @@ class Layer {
1317
1317
  ) {
1318
1318
  const {data, mapState} = renderOpts;
1319
1319
  const {textLabel, visibilityByZoom} = this.config;
1320
- // const extensions = [...sharedProps.extensions];
1321
1320
  const extensions = [...sharedProps.extensions, collisionFilterExtension];
1322
1321
 
1323
1322
  if (!data || !data.textLabels || !data.textLabels[0] || !data.textLabels[0].getText) {
1324
1323
  return [];
1325
1324
  }
1326
1325
 
1327
- // TODO other labels
1328
- const i = 0;
1329
-
1330
1326
  const [mainLabel, secondaryLabel] = textLabel;
1331
- const {alignment, anchor, color: getColor, outlineColor, size: sizeScale} = mainLabel;
1327
+ const {
1328
+ alignment,
1329
+ anchor,
1330
+ color: getColor,
1331
+ field: mainField,
1332
+ outlineColor,
1333
+ size: sizeScale
1334
+ } = mainLabel;
1332
1335
  const {
1333
1336
  color: getSecondaryColor,
1337
+ field: secondaryField,
1334
1338
  outlineColor: secondaryOutlineColor,
1335
1339
  size: secondarySizeScale
1336
1340
  } = secondaryLabel || {};
@@ -1338,7 +1342,10 @@ class Layer {
1338
1342
  return [
1339
1343
  new PointLabelLayer({
1340
1344
  ...sharedProps,
1341
- id: `${this.id}-label`,
1345
+
1346
+ // Recreate layer when labels change otherwise rendering breaks
1347
+ // TODO could be more efficient with updateTriggers?
1348
+ id: `${this.id}-${mainField?.name}-${secondaryField?.name}-label`,
1342
1349
  data: data.data,
1343
1350
  visibilityByZoom,
1344
1351
  extensions,
@@ -1352,7 +1359,7 @@ class Layer {
1352
1359
  sizeScale,
1353
1360
  outlineColor,
1354
1361
 
1355
- ...(secondaryLabel && {
1362
+ ...(secondaryField && {
1356
1363
  getSecondaryText: data.textLabels[1].getText,
1357
1364
  getSecondaryColor,
1358
1365
  secondarySizeScale,
@@ -1379,7 +1386,8 @@ class Layer {
1379
1386
  getFilterValue: data.getFilterValue,
1380
1387
  updateTriggers: {
1381
1388
  ...updateTriggers,
1382
- getText: textLabel[i].field?.name,
1389
+ getText: mainField?.name,
1390
+ getColor: mainField?.color,
1383
1391
  getPixelOffset: {
1384
1392
  ...updateTriggers.getPixelOffset,
1385
1393
  ...updateTriggers.getRadius,
@@ -1388,7 +1396,7 @@ class Layer {
1388
1396
  },
1389
1397
  getTextAnchor: mainLabel.anchor,
1390
1398
  getAlignmentBaseline: mainLabel.alignment,
1391
- getColor: textLabel[i].color
1399
+ getSecondaryText: secondaryField?.name
1392
1400
  }
1393
1401
  })
1394
1402
  ];