@deck.gl/carto 9.0.10 → 9.0.12

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/dist/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import { default as H3TileLayer } from "./layers/h3-tile-layer.js";
2
2
  import { default as _PointLabelLayer } from "./layers/point-label-layer.js";
3
3
  import { default as QuadbinTileLayer } from "./layers/quadbin-tile-layer.js";
4
+ import { default as QuadbinHeatmapTileLayer } from "./layers/quadbin-heatmap-tile-layer.js";
4
5
  import { default as RasterTileLayer } from "./layers/raster-tile-layer.js";
5
6
  import { default as VectorTileLayer } from "./layers/vector-tile-layer.js";
6
7
  declare const CARTO_LAYERS: {
7
8
  H3TileLayer: typeof H3TileLayer;
8
9
  _PointLabelLayer: typeof _PointLabelLayer;
9
10
  QuadbinTileLayer: typeof QuadbinTileLayer;
11
+ QuadbinHeatmapTileLayer: typeof QuadbinHeatmapTileLayer;
10
12
  RasterTileLayer: typeof RasterTileLayer;
11
13
  VectorTileLayer: typeof VectorTileLayer;
12
14
  };
13
- export { CARTO_LAYERS, H3TileLayer, _PointLabelLayer, QuadbinTileLayer, RasterTileLayer, VectorTileLayer };
15
+ export { CARTO_LAYERS, H3TileLayer, _PointLabelLayer, QuadbinTileLayer, QuadbinHeatmapTileLayer, RasterTileLayer, VectorTileLayer };
14
16
  export { default as BASEMAP } from "./basemap.js";
15
17
  export { default as colorBins } from "./style/color-bins-style.js";
16
18
  export { default as colorCategories } from "./style/color-categories-style.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,kCAA+B;AAC9D,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,sCAAmC;AACvE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,uCAAoC;AACxE,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC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alB,CAAC;AAEF,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,eAAe,EAChB,CAAC;AAEF,YAAY,EACV,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC3B,2BAAwB"}
package/dist/index.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { default as H3TileLayer } from "./layers/h3-tile-layer.js";
2
2
  import { default as _PointLabelLayer } from "./layers/point-label-layer.js";
3
3
  import { default as QuadbinTileLayer } from "./layers/quadbin-tile-layer.js";
4
+ import { default as QuadbinHeatmapTileLayer } from "./layers/quadbin-heatmap-tile-layer.js";
4
5
  import { default as RasterTileLayer } from "./layers/raster-tile-layer.js";
5
6
  import { default as VectorTileLayer } from "./layers/vector-tile-layer.js";
6
7
  const CARTO_LAYERS = {
7
8
  H3TileLayer,
8
9
  _PointLabelLayer,
9
10
  QuadbinTileLayer,
11
+ QuadbinHeatmapTileLayer,
10
12
  RasterTileLayer,
11
13
  VectorTileLayer
12
14
  };
13
- export { CARTO_LAYERS, H3TileLayer, _PointLabelLayer, QuadbinTileLayer, RasterTileLayer, VectorTileLayer };
15
+ export { CARTO_LAYERS, H3TileLayer, _PointLabelLayer, QuadbinTileLayer, QuadbinHeatmapTileLayer, RasterTileLayer, VectorTileLayer };
14
16
  export { default as BASEMAP } from "./basemap.js";
15
17
  export { default as colorBins } from "./style/color-bins-style.js";
16
18
  export { default as colorCategories } from "./style/color-categories-style.js";
@@ -0,0 +1,36 @@
1
+ import type { ShaderPass } from '@luma.gl/shadertools';
2
+ import { Color } from '@deck.gl/core';
3
+ export type HeatmapProps = {
4
+ /**
5
+ * Radius of the circle in pixels, to which the weight of an object is distributed.
6
+ *
7
+ * @default 30
8
+ */
9
+ radiusPixels?: number;
10
+ /**
11
+ * Controls how weight values are mapped to the `colorRange`, as an array of two numbers [`minValue`, `maxValue`].
12
+ *
13
+ * @default [0, 1]
14
+ */
15
+ colorDomain?: [number, number];
16
+ /**
17
+ * Specified as an array of colors [color1, color2, ...].
18
+ *
19
+ * @default `6-class YlOrRd` - [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6)
20
+ */
21
+ colorRange: Color[];
22
+ opacity: number;
23
+ };
24
+ export type HeatmapUniforms = {
25
+ radiusPixels?: number;
26
+ colorDomain?: [number, number];
27
+ color1?: [number, number, number];
28
+ color2?: [number, number, number];
29
+ color3?: [number, number, number];
30
+ color4?: [number, number, number];
31
+ color5?: [number, number, number];
32
+ color6?: [number, number, number];
33
+ opacity?: number;
34
+ };
35
+ export declare const heatmap: ShaderPass<HeatmapProps, HeatmapUniforms>;
36
+ //# sourceMappingURL=heatmap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heatmap.d.ts","sourceRoot":"","sources":["../../src/layers/heatmap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAgHpC,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B;;;;OAIG;IACH,UAAU,EAAE,KAAK,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,UAAU,CAAC,YAAY,EAAE,eAAe,CA+C7D,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { random } from '@luma.gl/shadertools';
2
+ const glsl = (s) => `${s}`;
3
+ /**
4
+ * @filter Heatmap
5
+ * @param radiusPixels Blur radius in pixels, controls smoothness of heatmap
6
+ * @param colorDomain Domain to apply to values prior to applying color scale
7
+ * @param color1-6 Colors to use in color scale
8
+ */
9
+ const fs = `\
10
+ uniform heatmapUniforms {
11
+ float radiusPixels;
12
+ vec2 colorDomain;
13
+ vec3 color1;
14
+ vec3 color2;
15
+ vec3 color3;
16
+ vec3 color4;
17
+ vec3 color5;
18
+ vec3 color6;
19
+ float opacity;
20
+ } heatmap;
21
+ const float SUPPORT = 8.0;
22
+ const vec4 STOPS = vec4(0.2, 0.4, 0.6, 0.8);
23
+ vec3 colorGradient(float value) {
24
+ vec3 c1;
25
+ vec3 c2;
26
+ vec2 range;
27
+ if (value < STOPS.x) {
28
+ range = vec2(0.0, STOPS.x);
29
+ c1 = heatmap.color1; c2 = heatmap.color2;
30
+ } else if (value < STOPS.y) {
31
+ range = STOPS.xy;
32
+ c1 = heatmap.color2; c2 = heatmap.color3;
33
+ } else if (value < STOPS.z) {
34
+ range = STOPS.yz;
35
+ c1 = heatmap.color3; c2 = heatmap.color4;
36
+ } else if (value < STOPS.w) {
37
+ range = STOPS.zw;
38
+ c1 = heatmap.color4; c2 = heatmap.color5;
39
+ } else if (value < 1.0 ) {
40
+ range = vec2(STOPS.w, 1.0);
41
+ c1 = heatmap.color5; c2 = heatmap.color6;
42
+ } else {
43
+ range = vec2(1.0, 10.0);
44
+ c1 = heatmap.color6; c2 = vec3(255.0);
45
+ }
46
+ float f = (value - range.x) / (range.y - range.x);
47
+ return mix(c1, c2, f) / 255.0;
48
+ }
49
+ const vec3 SHIFT = vec3(1.0, 256.0, 256.0 * 256.0);
50
+ float unpack(vec3 color) {
51
+ return 255.0 * dot(color, SHIFT);
52
+ }
53
+ vec4 heatmap_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
54
+ float accumulator = 0.0;
55
+ float offset = 0.5 * random(vec3(12.9898, 78.233, 151.7182), 0.0);
56
+ const float sigma = SUPPORT / 3.0;
57
+ const float a = -0.5 / (sigma * sigma);
58
+ const float w0 = 1.0 / (2.0 * 3.141592653589793 * sigma * sigma);
59
+ for (float t = -SUPPORT; t <= SUPPORT; t++) {
60
+ for (float s = -SUPPORT; s <= SUPPORT; s++) {
61
+ vec2 percent = (vec2(s, t) + offset - 0.5) / SUPPORT;
62
+ vec2 delta = percent * heatmap.radiusPixels / texSize;
63
+ vec4 offsetColor = texture(source, texCoord + delta);
64
+ float value = unpack(offsetColor.rgb);
65
+ float weight = w0 * exp(a * (s * s + t * t));
66
+ accumulator += value * weight;
67
+ }
68
+ }
69
+ float f = (accumulator - heatmap.colorDomain[0]) / (heatmap.colorDomain[1] - heatmap.colorDomain[0]);
70
+ vec4 color = vec4(0.0);
71
+ color.rgb = colorGradient(f);
72
+ color.a = smoothstep(0.0, 0.1, f);
73
+ color.a = pow(color.a, 1.0 / 2.2);
74
+ color.a *= heatmap.opacity;
75
+ return color;
76
+ }
77
+ `;
78
+ const defaultColorRange = [
79
+ [255, 255, 178],
80
+ [254, 217, 118],
81
+ [254, 178, 76],
82
+ [253, 141, 60],
83
+ [240, 59, 32],
84
+ [189, 0, 38]
85
+ ];
86
+ export const heatmap = {
87
+ name: 'heatmap',
88
+ uniformPropTypes: {
89
+ radiusPixels: { value: 20, min: 0, softMax: 100 },
90
+ colorDomain: { value: [0, 1] },
91
+ color1: { value: [0, 0, 0] },
92
+ color2: { value: [0, 0, 0] },
93
+ color3: { value: [0, 0, 0] },
94
+ color4: { value: [0, 0, 0] },
95
+ color5: { value: [0, 0, 0] },
96
+ color6: { value: [0, 0, 0] },
97
+ opacity: { value: 1, min: 0, max: 1 }
98
+ },
99
+ uniformTypes: {
100
+ radiusPixels: 'f32',
101
+ colorDomain: 'vec2<f32>',
102
+ color1: 'vec3<f32>',
103
+ color2: 'vec3<f32>',
104
+ color3: 'vec3<f32>',
105
+ color4: 'vec3<f32>',
106
+ color5: 'vec3<f32>',
107
+ color6: 'vec3<f32>',
108
+ opacity: 'f32'
109
+ },
110
+ getUniforms: opts => {
111
+ const { colorRange = defaultColorRange, radiusPixels = 20, colorDomain = [0, 1], opacity = 1 } = opts;
112
+ const [color1, color2, color3, color4, color5, color6] = colorRange;
113
+ return {
114
+ color1,
115
+ color2,
116
+ color3,
117
+ color4,
118
+ color5,
119
+ color6,
120
+ radiusPixels,
121
+ colorDomain,
122
+ opacity
123
+ };
124
+ },
125
+ dependencies: [random],
126
+ fs,
127
+ passes: [{ sampler: true }]
128
+ };
@@ -0,0 +1,27 @@
1
+ import { CompositeLayer, Layer, LayersList } from '@deck.gl/core';
2
+ type Constructor<T> = (new (...args: any[]) => T) & {
3
+ layerName: string;
4
+ };
5
+ type DrawableCompositeLayer = CompositeLayer & {
6
+ renderLayers(): Layer<{}> | null | LayersList;
7
+ };
8
+ /**
9
+ * Modifier that marks a layer for Render-to-Target rendering.
10
+ * Resulting layer must be used as a sublayer of a layer created
11
+ * with `PostProcessModifier`
12
+ */
13
+ export declare function RTTModifier(BaseLayer: any): {
14
+ new (): {
15
+ [x: string]: any;
16
+ draw(this: any, opts: any): void;
17
+ };
18
+ [x: string]: any;
19
+ layerName: string;
20
+ };
21
+ /**
22
+ * Modifier that returns the a modified Layer, which applies a
23
+ * postprocess effect to all subLayers created using `RTTModifier`
24
+ */
25
+ export declare function PostProcessModifier<T extends Constructor<DrawableCompositeLayer>>(BaseLayer: T, effect: any): T;
26
+ export {};
27
+ //# sourceMappingURL=post-process-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-process-utils.d.ts","sourceRoot":"","sources":["../../src/layers/post-process-utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,KAAK,EAGL,UAAU,EAGX,MAAM,eAAe,CAAC;AAoBvB,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,GAAG;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,CAAC;AACxE,KAAK,sBAAsB,GAAG,cAAc,GAAG;IAC7C,YAAY,IAAI,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAAC;CAC/C,CAAC;AAwBF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,SAAS,KAAA;;;8BAIN,GAAG;;;;EAiBjC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,WAAW,CAAC,sBAAsB,CAAC,EAC/E,SAAS,EAAE,CAAC,EACZ,MAAM,EAAE,GAAG,GACV,CAAC,CAwFH"}
@@ -0,0 +1,130 @@
1
+ import { Layer, PostProcessEffect } from '@deck.gl/core';
2
+ const TEXTURE_PROPS = {
3
+ format: 'rgba8unorm',
4
+ mipmaps: false,
5
+ sampler: {
6
+ minFilter: 'linear',
7
+ magFilter: 'linear',
8
+ addressModeU: 'clamp-to-edge',
9
+ addressModeV: 'clamp-to-edge'
10
+ }
11
+ };
12
+ function getPostProcessLayer(layer) {
13
+ while (layer.parent && !layer.applyPostProcess) {
14
+ layer = layer.parent;
15
+ }
16
+ return layer;
17
+ }
18
+ /**
19
+ * Dummy Layer that draws nothing, just calls back to root Layer
20
+ */
21
+ class DrawCallbackLayer extends Layer {
22
+ static { this.layerName = 'DrawCallbackLayer'; }
23
+ initializeState() {
24
+ this.id = `draw-callback-${getPostProcessLayer(this).props.id}`;
25
+ }
26
+ _drawLayer() {
27
+ getPostProcessLayer(this).applyPostProcess();
28
+ }
29
+ }
30
+ /**
31
+ * Modifier that marks a layer for Render-to-Target rendering.
32
+ * Resulting layer must be used as a sublayer of a layer created
33
+ * with `PostProcessModifier`
34
+ */
35
+ export function RTTModifier(BaseLayer) {
36
+ return class RTTLayer extends BaseLayer {
37
+ static { this.layerName = `RTT-${BaseLayer.layerName}`; }
38
+ draw(opts) {
39
+ const { moduleParameters } = opts;
40
+ const { picking } = moduleParameters;
41
+ const postProcessLayer = getPostProcessLayer(this);
42
+ if (!picking.isActive) {
43
+ postProcessLayer.enableRTT(opts);
44
+ }
45
+ // Draw actual layer
46
+ super.draw(opts);
47
+ if (!picking.isActive) {
48
+ postProcessLayer.disableRTT();
49
+ }
50
+ }
51
+ };
52
+ }
53
+ /**
54
+ * Modifier that returns the a modified Layer, which applies a
55
+ * postprocess effect to all subLayers created using `RTTModifier`
56
+ */
57
+ export function PostProcessModifier(BaseLayer, effect) {
58
+ return class PostProcessLayer extends BaseLayer {
59
+ static { this.layerName = `PostProcess${BaseLayer.layerName}`; }
60
+ initializeState(context) {
61
+ super.initializeState(context);
62
+ this._createTextures();
63
+ this.internalState.postProcess = new PostProcessEffect(effect, this.props);
64
+ this.internalState.postProcess.setup(context);
65
+ }
66
+ updateState(params) {
67
+ super.updateState(params);
68
+ this.internalState.postProcess.setProps(this.props);
69
+ }
70
+ renderLayers() {
71
+ let subLayers = super.renderLayers();
72
+ if (!subLayers) {
73
+ return null;
74
+ }
75
+ subLayers = Array.isArray(subLayers) ? subLayers : [subLayers];
76
+ return [...subLayers, new DrawCallbackLayer()];
77
+ }
78
+ _createTextures() {
79
+ const { device } = this.context;
80
+ this.internalState.renderBuffers = [0, 1].map(i => {
81
+ return device.createFramebuffer({
82
+ id: `layer-fbo-${i}`,
83
+ colorAttachments: [device.createTexture(TEXTURE_PROPS)],
84
+ depthStencilAttachment: 'depth16unorm'
85
+ });
86
+ });
87
+ }
88
+ _resizeBuffers(opts) {
89
+ // TODO we could likely render to a smaller buffer for better perf
90
+ const { moduleParameters } = opts;
91
+ const { viewport } = this.context;
92
+ const width = moduleParameters.devicePixelRatio * viewport.width;
93
+ const height = moduleParameters.devicePixelRatio * viewport.height;
94
+ this.internalState.renderBuffers.forEach((fbo) => fbo.resize({ width, height }));
95
+ }
96
+ enableRTT(opts) {
97
+ this._resizeBuffers(opts);
98
+ this.internalState.originalRenderPass = this.context.renderPass;
99
+ const [framebuffer] = this.internalState.renderBuffers;
100
+ // Create new render pass for RTT
101
+ this.internalState.internalRenderPass = this.context.device.beginRenderPass({
102
+ framebuffer,
103
+ parameters: { viewport: [0, 0, framebuffer.width, framebuffer.height] },
104
+ // Only clear on first render
105
+ clearColor: this.internalState.renderInProgress ? false : [0, 0, 0, 0]
106
+ });
107
+ this.internalState.renderInProgress = true;
108
+ this.context.renderPass = this.internalState.internalRenderPass;
109
+ }
110
+ disableRTT() {
111
+ // End render pass, and reinstate original
112
+ this.internalState.internalRenderPass.end();
113
+ this.context.renderPass = this.internalState.originalRenderPass;
114
+ }
115
+ applyPostProcess() {
116
+ if (!this.internalState.renderInProgress) {
117
+ return;
118
+ }
119
+ // Apply post process effect
120
+ const [inputBuffer, swapBuffer] = this.internalState.renderBuffers;
121
+ const { framebuffer: target } = this.context.renderPass.props;
122
+ this.internalState.postProcess.postRender({
123
+ inputBuffer,
124
+ swapBuffer,
125
+ target
126
+ });
127
+ this.internalState.renderInProgress = false;
128
+ }
129
+ };
130
+ }
@@ -0,0 +1,21 @@
1
+ import { Accessor, CompositeLayer, DefaultProps, Layer } from '@deck.gl/core';
2
+ import { HeatmapProps } from "./heatmap.js";
3
+ import { QuadbinTileLayerProps } from "./quadbin-tile-layer.js";
4
+ /** All properties supported by QuadbinHeatmapTileLayer. */
5
+ export type QuadbinHeatmapTileLayerProps<DataT = unknown> = _QuadbinHeatmapTileLayerProps<DataT> & QuadbinTileLayerProps;
6
+ /** Properties added by QuadbinHeatmapTileLayer. */
7
+ type _QuadbinHeatmapTileLayerProps<DataT> = QuadbinTileLayerProps<DataT> & HeatmapProps & {
8
+ /**
9
+ * The weight of each object.
10
+ *
11
+ * @default 1
12
+ */
13
+ getWeight?: Accessor<DataT, number>;
14
+ };
15
+ declare class QuadbinHeatmapTileLayer<DataT = any, ExtraProps extends {} = {}> extends CompositeLayer<ExtraProps & Required<_QuadbinHeatmapTileLayerProps<DataT>>> {
16
+ static layerName: string;
17
+ static defaultProps: DefaultProps<QuadbinHeatmapTileLayerProps<unknown>>;
18
+ renderLayers(): Layer;
19
+ }
20
+ export default QuadbinHeatmapTileLayer;
21
+ //# sourceMappingURL=quadbin-heatmap-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadbin-heatmap-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/quadbin-heatmap-tile-layer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAG5E,OAAO,EAAC,YAAY,EAAU,qBAAkB;AAEhD,OAAyB,EAAC,qBAAqB,EAAC,gCAA6B;AAkD7E,2DAA2D;AAC3D,MAAM,MAAM,4BAA4B,CAAC,KAAK,GAAG,OAAO,IAAI,6BAA6B,CAAC,KAAK,CAAC,GAC9F,qBAAqB,CAAC;AAExB,mDAAmD;AACnD,KAAK,6BAA6B,CAAC,KAAK,IAAI,qBAAqB,CAAC,KAAK,CAAC,GACtE,YAAY,GAAG;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAEJ,cAAM,uBAAuB,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,SAAS,EAAE,GAAG,EAAE,CAAE,SAAQ,cAAc,CAC3F,UAAU,GAAG,QAAQ,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAC5D;IACC,MAAM,CAAC,SAAS,SAA6B;IAC7C,MAAM,CAAC,YAAY,sDAAgB;IAEnC,YAAY,IAAI,KAAK;CAyCtB;AAED,eAAe,uBAAuB,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { getResolution } from 'quadbin';
2
+ import { CompositeLayer } from '@deck.gl/core';
3
+ import { SolidPolygonLayer } from '@deck.gl/layers';
4
+ import { heatmap } from "./heatmap.js";
5
+ import { RTTModifier, PostProcessModifier } from "./post-process-utils.js";
6
+ import QuadbinTileLayer from "./quadbin-tile-layer.js";
7
+ // Modified polygon layer to draw offscreen and output value expected by heatmap
8
+ class RTTSolidPolygonLayer extends RTTModifier(SolidPolygonLayer) {
9
+ static { this.layerName = 'RTTSolidPolygonLayer'; }
10
+ getShaders(type) {
11
+ const shaders = super.getShaders(type);
12
+ shaders.inject = {
13
+ 'vs:#decl': 'uniform float cellResolution;',
14
+ 'vs:DECKGL_FILTER_COLOR': `
15
+ const vec3 SHIFT = vec3(1.0, 256.0, 256.0 * 256.0);
16
+ float value = 255.0 * dot(SHIFT, color.rgb);
17
+
18
+ // Keep "power" delivered to screen constant when tiles update
19
+ float relativeZoom = log2(project_uScale) - cellResolution + 3.5; // range 0-1
20
+ float relativeArea = pow(2.0, -2.0 * relativeZoom); // range 0.25-1
21
+ value *= relativeArea;
22
+
23
+ // Pack float into 3 channels to pass to heatmap shader
24
+ color = vec4(mod(vec3(value, floor(value / SHIFT.yz)), 256.0), 255.0) / 255.0;
25
+ `
26
+ };
27
+ return shaders;
28
+ }
29
+ draw(opts) {
30
+ const cell0 = this.props.data[0];
31
+ const cellResolution = Number(getResolution(cell0.id));
32
+ for (const model of this.state.models) {
33
+ model.setUniforms({ cellResolution });
34
+ }
35
+ super.draw(opts);
36
+ }
37
+ }
38
+ // Modify QuadbinTileLayer to apply heatmap post process effect
39
+ const PostProcessQuadbinTileLayer = PostProcessModifier(QuadbinTileLayer, heatmap);
40
+ function encodeWeight(w) {
41
+ return [w % 256, Math.floor(w / 256), Math.floor(w / (256 * 256))];
42
+ }
43
+ const defaultProps = {
44
+ ...QuadbinTileLayer.defaultProps,
45
+ getWeight: { type: 'accessor', value: 1 }
46
+ };
47
+ class QuadbinHeatmapTileLayer extends CompositeLayer {
48
+ static { this.layerName = 'QuadbinHeatmapTileLayer'; }
49
+ static { this.defaultProps = defaultProps; }
50
+ renderLayers() {
51
+ const { getWeight, colorDomain, colorRange, radiusPixels, _subLayerProps } = this.props;
52
+ // Inject modified polygon layer as sublayer into TileLayer
53
+ const subLayerProps = {
54
+ ..._subLayerProps,
55
+ cell: {
56
+ ..._subLayerProps?.cell,
57
+ _subLayerProps: {
58
+ ..._subLayerProps?.cell?._subLayerProps,
59
+ fill: {
60
+ ..._subLayerProps?.cell?._subLayerProps?.fill,
61
+ type: RTTSolidPolygonLayer
62
+ }
63
+ }
64
+ }
65
+ };
66
+ const getFillColor = typeof getWeight === 'function'
67
+ ? (d, info) => encodeWeight(getWeight(d, info))
68
+ : encodeWeight(getWeight);
69
+ return new PostProcessQuadbinTileLayer(this.getSubLayerProps({
70
+ id: 'heatmap',
71
+ data: this.props.data,
72
+ getFillColor,
73
+ colorDomain,
74
+ colorRange,
75
+ radiusPixels,
76
+ _subLayerProps: subLayerProps,
77
+ updateTriggers: {
78
+ getPosition: this.props.updateTriggers.getWeight
79
+ }
80
+ }));
81
+ }
82
+ }
83
+ export default QuadbinHeatmapTileLayer;
@@ -1,7 +1,7 @@
1
1
  import { TileReader } from "./carto-raster-tile.js";
2
2
  import { parsePbf } from "./tile-loader-utils.js";
3
3
  import { getWorkerUrl } from "../../utils.js";
4
- const VERSION = typeof "9.0.10" !== 'undefined' ? "9.0.10" : 'latest';
4
+ const VERSION = typeof "9.0.12" !== 'undefined' ? "9.0.12" : 'latest';
5
5
  const id = 'cartoRasterTile';
6
6
  const DEFAULT_OPTIONS = {
7
7
  cartoRasterTile: {
@@ -2,7 +2,7 @@ import { TileReader } from "./carto-spatial-tile.js";
2
2
  import { parsePbf } from "./tile-loader-utils.js";
3
3
  import { getWorkerUrl } from "../../utils.js";
4
4
  import { binaryToSpatialjson } from "./spatialjson-utils.js";
5
- const VERSION = typeof "9.0.10" !== 'undefined' ? "9.0.10" : 'latest';
5
+ const VERSION = typeof "9.0.12" !== 'undefined' ? "9.0.12" : 'latest';
6
6
  const id = 'cartoSpatialTile';
7
7
  const DEFAULT_OPTIONS = {
8
8
  cartoSpatialTile: {
@@ -2,7 +2,7 @@ import earcut from 'earcut';
2
2
  import { TileReader } from "./carto-tile.js";
3
3
  import { parsePbf } from "./tile-loader-utils.js";
4
4
  import { getWorkerUrl } from "../../utils.js";
5
- const VERSION = typeof "9.0.10" !== 'undefined' ? "9.0.10" : 'latest';
5
+ const VERSION = typeof "9.0.12" !== 'undefined' ? "9.0.12" : 'latest';
6
6
  const id = 'cartoVectorTile';
7
7
  const DEFAULT_OPTIONS = {
8
8
  cartoVectorTile: {