@carto/kepler.gl 0.0.45 → 0.0.47-alpha.custom-markers

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.
@@ -20,6 +20,7 @@
20
20
 
21
21
  import {BrushingExtension} from '@deck.gl/extensions';
22
22
  import {ScatterplotLayer} from '@deck.gl/layers';
23
+ import {IconLayer} from '@deck.gl/layers';
23
24
 
24
25
  import Layer from '../base-layer';
25
26
  import {hexToRgb} from 'utils/color-utils';
@@ -43,6 +44,8 @@ const brushingExtension = new BrushingExtension();
43
44
  export const pointVisConfigs = {
44
45
  radius: 'radius',
45
46
  fixedRadius: 'fixedRadius',
47
+ customMarkers: 'customMarkers',
48
+ customMarkersUrl: 'customMarkersUrl',
46
49
  opacity: 'opacity',
47
50
  outline: 'outline',
48
51
  thickness: 'thickness',
@@ -237,6 +240,13 @@ export default class PointLayer extends Layer {
237
240
  this.updateMeta({bounds});
238
241
  }
239
242
 
243
+ isLayerHovered(objectInfo) {
244
+ return (
245
+ (objectInfo?.picked && objectInfo?.layer?.props?.id === this.id) ||
246
+ objectInfo?.layer?.props?.id === `${this.id}-icon`
247
+ );
248
+ }
249
+
240
250
  renderLayer(opts) {
241
251
  const {data, gpuFilter, objectHovered, mapState, interactionConfig} = opts;
242
252
 
@@ -245,14 +255,6 @@ export default class PointLayer extends Layer {
245
255
  const radiusScale = this.getRadiusScale(fixedRadius);
246
256
  const radiusUnits = this.getRadiusUnit(fixedRadius);
247
257
 
248
- const layerProps = {
249
- stroked: this.config.visConfig.outline,
250
- filled: this.config.visConfig.filled,
251
- lineWidthScale: this.config.visConfig.thickness,
252
- radiusScale,
253
- ...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})
254
- };
255
-
256
258
  const updateTriggers = {
257
259
  getPosition: this.config.columns,
258
260
  getFilterValue: gpuFilter.filterValueUpdateTriggers,
@@ -278,16 +280,91 @@ export default class PointLayer extends Layer {
278
280
  };
279
281
  const hoveredObject = this.hasHoveredObject(objectHovered);
280
282
 
283
+ const textLabelLayer = this.renderTextLabelLayer(
284
+ {
285
+ getPosition: data.getPosition,
286
+ sharedProps,
287
+ getPixelOffset,
288
+ updateTriggers
289
+ },
290
+ opts
291
+ );
292
+ const commonLayerProps = {
293
+ ...defaultLayerProps,
294
+ parameters: {
295
+ // circles will be flat on the map when the altitude column is not used
296
+ depthTest: this.config.columns.altitude?.fieldIdx > -1
297
+ }
298
+ };
299
+
300
+ const {customMarkers, customMarkersUrl} = this.config.visConfig;
301
+ const customMarkersConfigured = customMarkers && Boolean(customMarkersUrl);
302
+ const customMarkersMisConfigured = customMarkers && !customMarkersConfigured;
303
+ if (customMarkersConfigured) {
304
+ const maxIconSize = this.getMaxMarkerSize();
305
+
306
+ const iconLayerProps = {
307
+ getIcon: () => {
308
+ const url = customMarkersUrl;
309
+ return {
310
+ id: `${url}@@${maxIconSize}`,
311
+ url,
312
+ width: maxIconSize,
313
+ height: maxIconSize,
314
+ mask: true
315
+ };
316
+ },
317
+ getPosition: data.getPosition,
318
+ getSize: data.getRadius,
319
+ sizeScale: radiusScale,
320
+ sizeUnits: 'pixels'
321
+ };
322
+
323
+ return [
324
+ new IconLayer({
325
+ ...commonLayerProps,
326
+ ...iconLayerProps,
327
+ id: `${defaultLayerProps.id}-icon`,
328
+ data: data.data,
329
+ getColor: data.getFillColor,
330
+ getFilterValue: data.getFilterValue,
331
+ updateTriggers: {
332
+ getFilterValue: updateTriggers.getFilterValue,
333
+ getColor: updateTriggers.getFillColor,
334
+ getIcon: [customMarkersUrl, maxIconSize],
335
+ getSize: updateTriggers.getRadius
336
+ }
337
+ }),
338
+ ...(hoveredObject
339
+ ? [
340
+ new IconLayer({
341
+ ...iconLayerProps,
342
+ ...this.getDefaultHoverLayerProps(),
343
+ id: `${defaultLayerProps.id}-icon-hovered`,
344
+ data: [hoveredObject],
345
+ getColor: this.config.highlightColor
346
+ })
347
+ ]
348
+ : []),
349
+ ...textLabelLayer
350
+ ];
351
+ }
352
+
353
+ const scatterPlotLayerProps = {
354
+ stroked: this.config.visConfig.outline,
355
+ filled: this.config.visConfig.filled,
356
+ lineWidthScale: this.config.visConfig.thickness,
357
+ // TODO: invent better way to render something when customMarkers are not yet configured
358
+ radiusScale: customMarkersMisConfigured ? radiusScale / 2 : radiusScale,
359
+ ...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})
360
+ };
361
+
281
362
  return [
282
363
  new ScatterplotLayer({
283
- ...defaultLayerProps,
284
364
  ...brushingProps,
285
- ...layerProps,
286
365
  ...data,
287
- parameters: {
288
- // circles will be flat on the map when the altitude column is not used
289
- depthTest: this.config.columns.altitude?.fieldIdx > -1
290
- },
366
+ ...commonLayerProps,
367
+ ...scatterPlotLayerProps,
291
368
  radiusUnits,
292
369
  lineWidthUnits: 'pixels',
293
370
  updateTriggers,
@@ -298,7 +375,7 @@ export default class PointLayer extends Layer {
298
375
  ? [
299
376
  new ScatterplotLayer({
300
377
  ...this.getDefaultHoverLayerProps(),
301
- ...layerProps,
378
+ ...scatterPlotLayerProps,
302
379
  data: [hoveredObject],
303
380
  getLineColor: this.config.highlightColor,
304
381
  getFillColor: this.config.highlightColor,
@@ -308,15 +385,7 @@ export default class PointLayer extends Layer {
308
385
  ]
309
386
  : []),
310
387
  // text label layer
311
- ...this.renderTextLabelLayer(
312
- {
313
- getPosition: data.getPosition,
314
- sharedProps,
315
- getPixelOffset,
316
- updateTriggers
317
- },
318
- opts
319
- )
388
+ ...textLabelLayer
320
389
  ];
321
390
  }
322
391
  }
@@ -85,6 +85,7 @@ export default {
85
85
  layer: {
86
86
  required: 'Required*',
87
87
  radius: 'Radius',
88
+ size: 'Size',
88
89
  color: 'Color',
89
90
  fillColor: 'Fill Color',
90
91
  outline: 'Outline',
@@ -101,6 +102,7 @@ export default {
101
102
  elevationByDescription: 'When off, height is based on count of points',
102
103
  colorByDescription: 'When off, color is based on count of points',
103
104
  aggregateBy: 'Aggregate {field} by',
105
+ addUrl: 'Add URL',
104
106
  '3DModel': '3D Model',
105
107
  '3DModelOptions': '3D Model Options',
106
108
  type: {
@@ -161,7 +163,9 @@ export default {
161
163
  weightIntensity: 'Weight Intensity',
162
164
  zoomScale: 'Zoom Scale',
163
165
  heightRange: 'Height Range',
164
- heightMultiplier: 'Height Multiplier'
166
+ heightMultiplier: 'Height Multiplier',
167
+ customMarkers: 'Custom markers',
168
+ url: 'Add URL'
165
169
  },
166
170
  layerVisibility: {
167
171
  title: 'Visibility by zoom level'