@deck.gl/aggregation-layers 9.0.4 → 9.0.6
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/dist.dev.js +2 -2
- package/dist/heatmap-layer/heatmap-layer.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +2 -2
- package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
- package/dist/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +1 -1
- package/dist.min.js +2 -2
- package/package.json +2 -2
- package/src/heatmap-layer/heatmap-layer.ts +1 -1
- package/src/screen-grid-layer/screen-grid-cell-layer.ts +1 -1
- package/src/utils/gpu-grid-aggregation/gpu-grid-aggregator.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screen-grid-cell-layer.d.ts","sourceRoot":"","sources":["../../src/screen-grid-layer/screen-grid-cell-layer.ts"],"names":[],"mappings":"AAoBA,OAAO,
|
|
1
|
+
{"version":3,"file":"screen-grid-cell-layer.d.ts","sourceRoot":"","sources":["../../src/screen-grid-layer/screen-grid-cell-layer.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,KAAK,EAAW,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAE,UAAU,EAAgB,gBAAgB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAI9F,OAAO,KAAK,EAAC,qBAAqB,EAAC,+BAA4B;AAC/D,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAclD,uDAAuD;AACvD,MAAM,MAAM,wBAAwB,CAAC,KAAK,GAAG,OAAO,IAAI,yBAAyB,CAAC,KAAK,CAAC,GACtF,UAAU,CAAC;AAEb,8CAA8C;AAC9C,MAAM,MAAM,yBAAyB,CAAC,KAAK,IAAI,qBAAqB,CAAC,KAAK,CAAC,GAAG;IAC5E,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,mBAAmB,CAAC,KAAK,GAAG,GAAG,EAAE,WAAW,SAAS,EAAE,GAAG,EAAE,CAAE,SAAQ,KAAK,CAC9F,WAAW,GAAG,QAAQ,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CACzD;IACC,MAAM,CAAC,SAAS,SAAyB;IACzC,MAAM,CAAC,YAAY,kDAAgB;IAEnC,KAAK,EAAG;QACN,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;IAEF,UAAU,IAAI;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,YAAY,EAAE,CAAA;KAAC;IAI/D,eAAe;IAYf,iBAAiB,CAAC,EAAC,WAAW,EAAC;;KAAA;IAK/B,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC;IAe1C,IAAI,CAAC,EAAC,QAAQ,EAAC;;KAAA;IA2Bf,0BAA0B,CAAC,SAAS,KAAA,EAAE,EAAC,YAAY,EAAC;;KAAA;IAkBpD,SAAS,IAAI,KAAK;IAsBlB,gBAAgB,IAAI,OAAO;IAe3B,eAAe,CAAC,QAAQ,KAAA,EAAE,KAAK,KAAA,EAAE,WAAW,KAAA,GAAG,IAAI;CA2BpD"}
|
|
@@ -302,7 +302,7 @@ export default class GPUGridAggregator {
|
|
|
302
302
|
}
|
|
303
303
|
// render all aggregated grid-cells to generate Min, Max or MaxMin data texture
|
|
304
304
|
_renderToMaxMinTexture(opts) {
|
|
305
|
-
const { id,
|
|
305
|
+
const { id, gridSize, minOrMaxFb, combineMaxMin, clearParams = {} } = opts;
|
|
306
306
|
const { framebuffers } = this.state;
|
|
307
307
|
const { allAggregationModel } = this;
|
|
308
308
|
this.device.withParametersWebGL({
|
package/dist.min.js
CHANGED
|
@@ -232,7 +232,7 @@ meanValues.xyz = isCellValid ? aggregationValues.xyz/aggregationValues.w : vec3(
|
|
|
232
232
|
meanValues.w = aggregationValues.w;
|
|
233
233
|
gl_PointSize = 1.0;
|
|
234
234
|
}
|
|
235
|
-
`;var Mi={minFilter:"nearest",magFilter:"nearest"};function Z(n,t){let{width:e=1,height:o=1,data:i=null,parameters:r=Mi}=t;return n.createTexture({data:i,format:"rgba32float",mipmaps:!1,sampler:r,width:e,height:o})}function xt(n,t){let{id:e,width:o=1,height:i=1,texture:r}=t;return n.createFramebuffer({id:e,width:o,height:i,colorAttachments:[r]})}var Ti=["aggregationBuffer","maxMinBuffer","minBuffer","maxBuffer"],we={maxData:"maxBuffer",minData:"minBuffer",maxMinData:"maxMinBuffer"},Ci=["float32-renderable-webgl","texture-blend-float-webgl"],C=class{static getAggregationData({aggregationData:t,maxData:e,minData:o,maxMinData:i,pixelIndex:r}){let s=r*Pe,a={};return t&&(a.cellCount=t[s+3],a.cellWeight=t[s]),i?(a.maxCellWieght=i[0],a.minCellWeight=i[3]):(e&&(a.maxCellWieght=e[0],a.totalCount=e[3]),o&&(a.minCellWeight=o[0],a.totalCount=o[3])),a}static getCellData({countsData:t,size:e=1}){let o=t.length/4,i=new Float32Array(o*e),r=new Uint32Array(o);for(let s=0;s<o;s++){for(let a=0;a<e;a++)i[s*e+a]=t[s*4+a];r[s]=t[s*4+3]}return{cellCounts:r,cellWeights:i}}static isSupported(t){return Ci.every(e=>t.features.has(e))}constructor(t,e={}){this.state={weightAttributes:{},textures:{},meanTextures:{},buffers:{},framebuffers:{},maxMinFramebuffers:{},minFramebuffers:{},maxFramebuffers:{},equations:{},shaderOptions:{},modelDirty:!1,resources:{},results:{}},this.id=e.id||"gpu-grid-aggregator",this.device=t;let o=["float32-renderable-webgl"];this._hasGPUSupport=o.every(i=>t.features.has(i)),this._hasGPUSupport&&this._setupModels()}delete(){let{gridAggregationModel:t,allAggregationModel:e,meanTransform:o}=this,{textures:i,framebuffers:r,maxMinFramebuffers:s,minFramebuffers:a,maxFramebuffers:l,meanTextures:c,resources:g}=this.state;t?.destroy(),e?.destroy(),o?.destroy(),Pi([r,i,s,a,l,c,g])}run(t={}){this.setState({results:{}});let e=this._normalizeAggregationParams(t);return this._runAggregation(e)}getData(t){let e={},o=this.state.results;o[t].aggregationData||(o[t].aggregationData=o[t].aggregationBuffer.getData()),e.aggregationData=o[t].aggregationData;for(let i in we){let r=we[i];(o[t][i]||o[t][r])&&(o[t][i]=o[t][i]||o[t][r].getData(),e[i]=o[t][i])}return e}updateShaders(t={}){this.setState({shaderOptions:t,modelDirty:!0})}_normalizeAggregationParams(t){let e={...Te,...t},{weights:o}=e;return o&&(e.weights=Ei(o)),e}setState(t){Object.assign(this.state,t)}_getAggregateData(t){let e={},{textures:o,framebuffers:i,maxMinFramebuffers:r,minFramebuffers:s,maxFramebuffers:a,resources:l}=this.state,{weights:c}=t;for(let g in c){e[g]={};let{needMin:f,needMax:d,combineMaxMin:p}=c[g];e[g].aggregationTexture=o[g],e[g].aggregationBuffer=this.device.readPixelsToBufferWebGL(i[g],{target:c[g].aggregationBuffer,sourceType:5126}),f&&d&&p?(e[g].maxMinBuffer=this.device.readPixelsToBufferWebGL(r[g],{target:c[g].maxMinBuffer,sourceType:5126}),e[g].maxMinTexture=l[`${g}-maxMinTexture`]):(f&&(e[g].minBuffer=this.device.readPixelsToBufferWebGL(s[g],{target:c[g].minBuffer,sourceType:5126}),e[g].minTexture=l[`${g}-minTexture`]),d&&(e[g].maxBuffer=this.device.readPixelsToBufferWebGL(a[g],{target:c[g].maxBuffer,sourceType:5126}),e[g].maxTexture=l[`${g}-maxTexture`]))}return this._trackGPUResultBuffers(e,c),e}_renderAggregateData(t){let{cellSize:e,projectPoints:o,attributes:i,moduleSettings:r,numCol:s,numRow:a,weights:l,translation:c,scaling:g}=t,{maxMinFramebuffers:f,minFramebuffers:d,maxFramebuffers:p}=this.state,x=[s,a],h={blend:!0,depthTest:!1,blendFunc:[1,1]},A={cellSize:e,gridSize:x,projectPoints:o,translation:c,scaling:g};for(let S in l){let{needMin:y,needMax:_}=l[S],b=y&&_&&l[S].combineMaxMin;this._renderToWeightsTexture({id:S,parameters:h,moduleSettings:r,uniforms:A,gridSize:x,attributes:i,weights:l}),b?this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:Ce},gridSize:x,minOrMaxFb:f[S],clearParams:{clearColor:[0,0,0,W]},combineMaxMin:b}):(y&&this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:Jt},gridSize:x,minOrMaxFb:d[S],clearParams:{clearColor:[W,W,W,0]},combineMaxMin:b}),_&&this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:te},gridSize:x,minOrMaxFb:p[S],clearParams:{clearColor:[0,0,0,0]},combineMaxMin:b}))}}_renderToMaxMinTexture(t){let{id:e,
|
|
235
|
+
`;var Mi={minFilter:"nearest",magFilter:"nearest"};function Z(n,t){let{width:e=1,height:o=1,data:i=null,parameters:r=Mi}=t;return n.createTexture({data:i,format:"rgba32float",mipmaps:!1,sampler:r,width:e,height:o})}function xt(n,t){let{id:e,width:o=1,height:i=1,texture:r}=t;return n.createFramebuffer({id:e,width:o,height:i,colorAttachments:[r]})}var Ti=["aggregationBuffer","maxMinBuffer","minBuffer","maxBuffer"],we={maxData:"maxBuffer",minData:"minBuffer",maxMinData:"maxMinBuffer"},Ci=["float32-renderable-webgl","texture-blend-float-webgl"],C=class{static getAggregationData({aggregationData:t,maxData:e,minData:o,maxMinData:i,pixelIndex:r}){let s=r*Pe,a={};return t&&(a.cellCount=t[s+3],a.cellWeight=t[s]),i?(a.maxCellWieght=i[0],a.minCellWeight=i[3]):(e&&(a.maxCellWieght=e[0],a.totalCount=e[3]),o&&(a.minCellWeight=o[0],a.totalCount=o[3])),a}static getCellData({countsData:t,size:e=1}){let o=t.length/4,i=new Float32Array(o*e),r=new Uint32Array(o);for(let s=0;s<o;s++){for(let a=0;a<e;a++)i[s*e+a]=t[s*4+a];r[s]=t[s*4+3]}return{cellCounts:r,cellWeights:i}}static isSupported(t){return Ci.every(e=>t.features.has(e))}constructor(t,e={}){this.state={weightAttributes:{},textures:{},meanTextures:{},buffers:{},framebuffers:{},maxMinFramebuffers:{},minFramebuffers:{},maxFramebuffers:{},equations:{},shaderOptions:{},modelDirty:!1,resources:{},results:{}},this.id=e.id||"gpu-grid-aggregator",this.device=t;let o=["float32-renderable-webgl"];this._hasGPUSupport=o.every(i=>t.features.has(i)),this._hasGPUSupport&&this._setupModels()}delete(){let{gridAggregationModel:t,allAggregationModel:e,meanTransform:o}=this,{textures:i,framebuffers:r,maxMinFramebuffers:s,minFramebuffers:a,maxFramebuffers:l,meanTextures:c,resources:g}=this.state;t?.destroy(),e?.destroy(),o?.destroy(),Pi([r,i,s,a,l,c,g])}run(t={}){this.setState({results:{}});let e=this._normalizeAggregationParams(t);return this._runAggregation(e)}getData(t){let e={},o=this.state.results;o[t].aggregationData||(o[t].aggregationData=o[t].aggregationBuffer.getData()),e.aggregationData=o[t].aggregationData;for(let i in we){let r=we[i];(o[t][i]||o[t][r])&&(o[t][i]=o[t][i]||o[t][r].getData(),e[i]=o[t][i])}return e}updateShaders(t={}){this.setState({shaderOptions:t,modelDirty:!0})}_normalizeAggregationParams(t){let e={...Te,...t},{weights:o}=e;return o&&(e.weights=Ei(o)),e}setState(t){Object.assign(this.state,t)}_getAggregateData(t){let e={},{textures:o,framebuffers:i,maxMinFramebuffers:r,minFramebuffers:s,maxFramebuffers:a,resources:l}=this.state,{weights:c}=t;for(let g in c){e[g]={};let{needMin:f,needMax:d,combineMaxMin:p}=c[g];e[g].aggregationTexture=o[g],e[g].aggregationBuffer=this.device.readPixelsToBufferWebGL(i[g],{target:c[g].aggregationBuffer,sourceType:5126}),f&&d&&p?(e[g].maxMinBuffer=this.device.readPixelsToBufferWebGL(r[g],{target:c[g].maxMinBuffer,sourceType:5126}),e[g].maxMinTexture=l[`${g}-maxMinTexture`]):(f&&(e[g].minBuffer=this.device.readPixelsToBufferWebGL(s[g],{target:c[g].minBuffer,sourceType:5126}),e[g].minTexture=l[`${g}-minTexture`]),d&&(e[g].maxBuffer=this.device.readPixelsToBufferWebGL(a[g],{target:c[g].maxBuffer,sourceType:5126}),e[g].maxTexture=l[`${g}-maxTexture`]))}return this._trackGPUResultBuffers(e,c),e}_renderAggregateData(t){let{cellSize:e,projectPoints:o,attributes:i,moduleSettings:r,numCol:s,numRow:a,weights:l,translation:c,scaling:g}=t,{maxMinFramebuffers:f,minFramebuffers:d,maxFramebuffers:p}=this.state,x=[s,a],h={blend:!0,depthTest:!1,blendFunc:[1,1]},A={cellSize:e,gridSize:x,projectPoints:o,translation:c,scaling:g};for(let S in l){let{needMin:y,needMax:_}=l[S],b=y&&_&&l[S].combineMaxMin;this._renderToWeightsTexture({id:S,parameters:h,moduleSettings:r,uniforms:A,gridSize:x,attributes:i,weights:l}),b?this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:Ce},gridSize:x,minOrMaxFb:f[S],clearParams:{clearColor:[0,0,0,W]},combineMaxMin:b}):(y&&this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:Jt},gridSize:x,minOrMaxFb:d[S],clearParams:{clearColor:[W,W,W,0]},combineMaxMin:b}),_&&this._renderToMaxMinTexture({id:S,parameters:{...h,blendEquation:te},gridSize:x,minOrMaxFb:p[S],clearParams:{clearColor:[0,0,0,0]},combineMaxMin:b}))}}_renderToMaxMinTexture(t){let{id:e,gridSize:o,minOrMaxFb:i,combineMaxMin:r,clearParams:s={}}=t,{framebuffers:a}=this.state,{allAggregationModel:l}=this;this.device.withParametersWebGL({...s,framebuffer:i,viewport:[0,0,o[0],o[1]]},()=>{this.device.clearWebGL({color:!0}),l.setUniforms({gridSize:o,combineMaxMin:r}),l.setBindings({uSampler:a[e].texture}),l.draw()})}_renderToWeightsTexture(t){let{id:e,parameters:o,moduleSettings:i,uniforms:r,gridSize:s,weights:a}=t,{framebuffers:l,equations:c,weightAttributes:g}=this.state,{gridAggregationModel:f}=this,{operation:d}=a[e],p=d===T.MIN?[W,W,W,0]:[0,0,0,0];if(this.device.withParametersWebGL({framebuffer:l[e],viewport:[0,0,s[0],s[1]],clearColor:p},()=>{this.device.clearWebGL({color:!0});let x={weights:g[e]};f.draw({parameters:{...o,blendEquation:c[e]},moduleSettings:i,uniforms:r,attributes:x})}),d===T.MEAN){let{meanTextures:x,textures:h}=this.state,A={_sourceTextures:{aggregationValues:x[e]},_targetTexture:h[e],elementCount:h[e].width*h[e].height};this.meanTransform?this.meanTransform.update(A):this.meanTransform=Oi(this.device,A),this.meanTransform.run({parameters:{blend:!1,depthTest:!1}}),l[e].attach({[36064]:h[e]})}}_runAggregation(t){this._updateModels(t),this._setupFramebuffers(t),this._renderAggregateData(t);let e=this._getAggregateData(t);return this.setState({results:e}),e}_setupFramebuffers(t){let{textures:e,framebuffers:o,maxMinFramebuffers:i,minFramebuffers:r,maxFramebuffers:s,meanTextures:a,equations:l}=this.state,{weights:c}=t,{numCol:g,numRow:f}=t,d={width:g,height:f};for(let p in c){let{needMin:x,needMax:h,combineMaxMin:A,operation:S}=c[p];e[p]=c[p].aggregationTexture||e[p]||Z(this.device,{id:`${p}-texture`,width:g,height:f}),e[p].resize(d);let y=e[p];S===T.MEAN&&(a[p]=a[p]||Z(this.device,{id:`${p}-mean-texture`,width:g,height:f}),a[p].resize(d),y=a[p]),o[p]?o[p].attach({[36064]:y}):o[p]=xt(this.device,{id:`${p}-fb`,width:g,height:f,texture:y}),o[p].resize(d),l[p]=ee[S]||ee[T.SUM],(x||h)&&(x&&h&&A?i[p]||(y=c[p].maxMinTexture||this._getMinMaxTexture(`${p}-maxMinTexture`),i[p]=xt(this.device,{id:`${p}-maxMinFb`,texture:y})):(x&&(r[p]||(y=c[p].minTexture||this._getMinMaxTexture(`${p}-minTexture`),r[p]=xt(this.device,{id:`${p}-minFb`,texture:y}))),h&&(s[p]||(y=c[p].maxTexture||this._getMinMaxTexture(`${p}-maxTexture`),s[p]=xt(this.device,{id:`${p}-maxFb`,texture:y})))))}}_getMinMaxTexture(t){let{resources:e}=this.state;return e[t]||(e[t]=Z(this.device,{id:"resourceName"})),e[t]}_setupModels({numCol:t=0,numRow:e=0}={}){let{shaderOptions:o}=this.state;if(this.gridAggregationModel?.destroy(),this.gridAggregationModel=Ni(this.device,o),!this.allAggregationModel){let i=t*e;this.allAggregationModel=Di(this.device,i)}}_setupWeightAttributes(t){let{weightAttributes:e}=this.state,{weights:o}=t;for(let i in o)e[i]=t.attributes[i]}_trackGPUResultBuffers(t,e){let{resources:o}=this.state;for(let i in t)if(t[i]){for(let r of Ti)if(t[i][r]&&e[i][r]!==t[i][r]){let s=`gpu-result-${i}-${r}`;o[s]&&o[s].delete(),o[s]=t[i][r]}}}_updateModels(t){let{vertexCount:e,attributes:o,numCol:i,numRow:r}=t,{modelDirty:s}=this.state;s&&(this._setupModels(t),this.setState({modelDirty:!1})),this._setupWeightAttributes(t),this.gridAggregationModel.setVertexCount(e),this.gridAggregationModel.setAttributes(o),this.allAggregationModel.setInstanceCount(i*r)}};function Ei(n){let t={};for(let e in n)t[e]={...Ee,...n[e]};return t}function Pi(n){n=Array.isArray(n)?n:[n],n.forEach(t=>{for(let e in t)t[e].delete()})}function Ni(n,t){let e=(0,J._mergeShaders)({vs:Ne,fs:De,modules:[K,J.project32]},t);return new vt.Model(n,{id:"Grid-Aggregation-Model",vertexCount:1,drawMode:0,shaderAssembler:(0,J.getShaderAssembler)(),...e})}function Di(n,t){return new vt.Model(n,{id:"All-Aggregation-Model",vs:Oe,fs:Le,modules:[K],vertexCount:1,topology:"point-list",isInstanced:!0,instanceCount:t,attributes:{position:[0,0]}})}function Oi(n,t){return new vt.TextureTransform(n,{vs:Fe,_targetTextureVarying:"meanValues",...t})}var Ot=M(q(),1),et=M(E(),1);var D=[[255,255,178],[254,217,118],[254,178,76],[253,141,60],[240,59,32],[189,0,38]];function z(n,t=!1,e=Float32Array){let o;if(Number.isFinite(n[0]))o=new e(n);else{o=new e(n.length*4);let i=0;for(let r=0;r<n.length;r++){let s=n[r];o[i++]=s[0],o[i++]=s[1],o[i++]=s[2],o[i++]=Number.isFinite(s[3])?s[3]:255}}if(t)for(let i=0;i<o.length;i++)o[i]/=255;return o}var Ie=`#version 300 es
|
|
236
236
|
#define SHADER_NAME screen-grid-layer-vertex-shader
|
|
237
237
|
#define RANGE_COUNT 6
|
|
238
238
|
in vec3 positions;
|
|
@@ -504,6 +504,6 @@ void main() {
|
|
|
504
504
|
fragColor = outTexture;
|
|
505
505
|
fragColor.g = outTexture.r / max(1.0, outTexture.a);
|
|
506
506
|
}
|
|
507
|
-
`;var _r=2,de={format:"rgba8unorm",mipmaps:!1,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}},ai=[0,0],br={SUM:0,MEAN:1},Mr={getPosition:{type:"accessor",value:n=>n.position},getWeight:{type:"accessor",value:1},intensity:{type:"number",min:0,value:1},radiusPixels:{type:"number",min:1,max:100,value:50},colorRange:D,threshold:{type:"number",min:0,max:1,value:.05},colorDomain:{type:"array",value:null,optional:!0},aggregation:"SUM",weightsTextureSize:{type:"number",min:128,max:2048,value:2048},debounceTimeout:{type:"number",min:0,max:1e3,value:500}},Tr=["float32-renderable-webgl","texture-blend-float-webgl"],Cr={data:{props:["radiusPixels"]}},Kt=class extends P{initializeState(){super.initializeAggregationLayer(Cr),this.setState({colorDomain:ai}),this._setupTextureParams(),this._setupAttributes(),this._setupResources()}shouldUpdateState({changeFlags:t}){return t.somethingChanged}updateState(t){super.updateState(t),this._updateHeatmapState(t)}_updateHeatmapState(t){let{props:e,oldProps:o}=t,i=this._getChangeFlags(t);(i.dataChanged||i.viewportChanged)&&(i.boundsChanged=this._updateBounds(i.dataChanged),this._updateTextureRenderingBounds()),i.dataChanged||i.boundsChanged?(clearTimeout(this.state.updateTimer),this.setState({isWeightMapDirty:!0})):i.viewportZoomChanged&&this._debouncedUpdateWeightmap(),e.colorRange!==o.colorRange&&this._updateColorTexture(t),this.state.isWeightMapDirty&&this._updateWeightmap(),this.setState({zoom:t.context.viewport.zoom})}renderLayers(){let{weightsTexture:t,triPositionBuffer:e,triTexCoordBuffer:o,maxWeightsTexture:i,colorTexture:r,colorDomain:s}=this.state,{updateTriggers:a,intensity:l,threshold:c,aggregation:g}=this.props,f=this.getSubLayerClass("triangle",Tt);return new f(this.getSubLayerProps({id:"triangle-layer",updateTriggers:a}),{coordinateSystem:R.COORDINATE_SYSTEM.DEFAULT,data:{attributes:{positions:e,texCoords:o}},vertexCount:4,maxTexture:i,colorTexture:r,aggregationMode:br[g]||0,weightsTexture:t,intensity:l,threshold:c,colorDomain:s})}finalizeState(t){super.finalizeState(t);let{weightsTransform:e,weightsTexture:o,maxWeightTransform:i,maxWeightsTexture:r,triPositionBuffer:s,triTexCoordBuffer:a,colorTexture:l,updateTimer:c}=this.state;e?.destroy(),o?.destroy(),i?.destroy(),r?.destroy(),s?.destroy(),a?.destroy(),l?.destroy(),c&&clearTimeout(c)}_getAttributeManager(){return new R.AttributeManager(this.context.device,{id:this.props.id,stats:this.context.stats})}_getChangeFlags(t){let e={},{dimensions:o}=this.state;e.dataChanged=this.isAttributeChanged()&&"attribute changed"||this.isAggregationDirty(t,{compareAll:!0,dimension:o.data})&&"aggregation is dirty",e.viewportChanged=t.changeFlags.viewportChanged;let{zoom:i}=this.state;return(!t.context.viewport||t.context.viewport.zoom!==i)&&(e.viewportZoomChanged=!0),e}_createTextures(){let{textureSize:t,format:e}=this.state;this.setState({weightsTexture:this.context.device.createTexture({...de,width:t,height:t,format:e}),maxWeightsTexture:this.context.device.createTexture({...de,width:1,height:1,format:e})})}_setupAttributes(){this.getAttributeManager().add({positions:{size:3,type:"float64",accessor:"getPosition"},weights:{size:1,accessor:"getWeight"}}),this.setState({positionAttributeName:"positions"})}_setupTextureParams(){let{device:t}=this.context,{weightsTextureSize:e}=this.props,o=Math.min(e,t.limits.maxTextureDimension2D),i=Tr.every(a=>t.features.has(a)),r=i?"rgba32float":"rgba8unorm",s=i?1:1/255;this.setState({textureSize:o,format:r,weightsScale:s}),i||R.log.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, falling back to low precision format`)()}_createWeightsTransform(t){let{weightsTransform:e}=this.state,{weightsTexture:o}=this.state,i=this.getAttributeManager();e?.destroy(),e=new pe.TextureTransform(this.context.device,{id:`${this.id}-weights-transform`,bufferLayout:i.getBufferLayouts(),vertexCount:1,targetTexture:o,parameters:{depthWriteEnabled:!1,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"},topology:"point-list",...t}),this.setState({weightsTransform:e})}_setupResources(){this._createTextures();let{device:t}=this.context,{textureSize:e,weightsTexture:o,maxWeightsTexture:i}=this.state,r=this.getShaders({vs:ge,fs:fe});this._createWeightsTransform(r);let s=this.getShaders({vs:ni,fs:si}),a=new pe.TextureTransform(t,{id:`${this.id}-max-weights-transform`,bindings:{inTexture:o},uniforms:{textureSize:e},targetTexture:i,...s,vertexCount:e*e,topology:"point-list",parameters:{depthWriteEnabled:!1,blendColorOperation:"max",blendAlphaOperation:"max",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"}});this.setState({weightsTexture:o,maxWeightsTexture:i,maxWeightTransform:a,zoom:null,triPositionBuffer:t.createBuffer({byteLength:48}),triTexCoordBuffer:t.createBuffer({byteLength:48})})}updateShaders(t){this._createWeightsTransform({vs:ge,fs:fe,...t})}_updateMaxWeightValue(){let{maxWeightTransform:t
|
|
507
|
+
`;var _r=2,de={format:"rgba8unorm",mipmaps:!1,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}},ai=[0,0],br={SUM:0,MEAN:1},Mr={getPosition:{type:"accessor",value:n=>n.position},getWeight:{type:"accessor",value:1},intensity:{type:"number",min:0,value:1},radiusPixels:{type:"number",min:1,max:100,value:50},colorRange:D,threshold:{type:"number",min:0,max:1,value:.05},colorDomain:{type:"array",value:null,optional:!0},aggregation:"SUM",weightsTextureSize:{type:"number",min:128,max:2048,value:2048},debounceTimeout:{type:"number",min:0,max:1e3,value:500}},Tr=["float32-renderable-webgl","texture-blend-float-webgl"],Cr={data:{props:["radiusPixels"]}},Kt=class extends P{initializeState(){super.initializeAggregationLayer(Cr),this.setState({colorDomain:ai}),this._setupTextureParams(),this._setupAttributes(),this._setupResources()}shouldUpdateState({changeFlags:t}){return t.somethingChanged}updateState(t){super.updateState(t),this._updateHeatmapState(t)}_updateHeatmapState(t){let{props:e,oldProps:o}=t,i=this._getChangeFlags(t);(i.dataChanged||i.viewportChanged)&&(i.boundsChanged=this._updateBounds(i.dataChanged),this._updateTextureRenderingBounds()),i.dataChanged||i.boundsChanged?(clearTimeout(this.state.updateTimer),this.setState({isWeightMapDirty:!0})):i.viewportZoomChanged&&this._debouncedUpdateWeightmap(),e.colorRange!==o.colorRange&&this._updateColorTexture(t),this.state.isWeightMapDirty&&this._updateWeightmap(),this.setState({zoom:t.context.viewport.zoom})}renderLayers(){let{weightsTexture:t,triPositionBuffer:e,triTexCoordBuffer:o,maxWeightsTexture:i,colorTexture:r,colorDomain:s}=this.state,{updateTriggers:a,intensity:l,threshold:c,aggregation:g}=this.props,f=this.getSubLayerClass("triangle",Tt);return new f(this.getSubLayerProps({id:"triangle-layer",updateTriggers:a}),{coordinateSystem:R.COORDINATE_SYSTEM.DEFAULT,data:{attributes:{positions:e,texCoords:o}},vertexCount:4,maxTexture:i,colorTexture:r,aggregationMode:br[g]||0,weightsTexture:t,intensity:l,threshold:c,colorDomain:s})}finalizeState(t){super.finalizeState(t);let{weightsTransform:e,weightsTexture:o,maxWeightTransform:i,maxWeightsTexture:r,triPositionBuffer:s,triTexCoordBuffer:a,colorTexture:l,updateTimer:c}=this.state;e?.destroy(),o?.destroy(),i?.destroy(),r?.destroy(),s?.destroy(),a?.destroy(),l?.destroy(),c&&clearTimeout(c)}_getAttributeManager(){return new R.AttributeManager(this.context.device,{id:this.props.id,stats:this.context.stats})}_getChangeFlags(t){let e={},{dimensions:o}=this.state;e.dataChanged=this.isAttributeChanged()&&"attribute changed"||this.isAggregationDirty(t,{compareAll:!0,dimension:o.data})&&"aggregation is dirty",e.viewportChanged=t.changeFlags.viewportChanged;let{zoom:i}=this.state;return(!t.context.viewport||t.context.viewport.zoom!==i)&&(e.viewportZoomChanged=!0),e}_createTextures(){let{textureSize:t,format:e}=this.state;this.setState({weightsTexture:this.context.device.createTexture({...de,width:t,height:t,format:e}),maxWeightsTexture:this.context.device.createTexture({...de,width:1,height:1,format:e})})}_setupAttributes(){this.getAttributeManager().add({positions:{size:3,type:"float64",accessor:"getPosition"},weights:{size:1,accessor:"getWeight"}}),this.setState({positionAttributeName:"positions"})}_setupTextureParams(){let{device:t}=this.context,{weightsTextureSize:e}=this.props,o=Math.min(e,t.limits.maxTextureDimension2D),i=Tr.every(a=>t.features.has(a)),r=i?"rgba32float":"rgba8unorm",s=i?1:1/255;this.setState({textureSize:o,format:r,weightsScale:s}),i||R.log.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, falling back to low precision format`)()}_createWeightsTransform(t){let{weightsTransform:e}=this.state,{weightsTexture:o}=this.state,i=this.getAttributeManager();e?.destroy(),e=new pe.TextureTransform(this.context.device,{id:`${this.id}-weights-transform`,bufferLayout:i.getBufferLayouts(),vertexCount:1,targetTexture:o,parameters:{depthWriteEnabled:!1,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"},topology:"point-list",...t}),this.setState({weightsTransform:e})}_setupResources(){this._createTextures();let{device:t}=this.context,{textureSize:e,weightsTexture:o,maxWeightsTexture:i}=this.state,r=this.getShaders({vs:ge,fs:fe});this._createWeightsTransform(r);let s=this.getShaders({vs:ni,fs:si}),a=new pe.TextureTransform(t,{id:`${this.id}-max-weights-transform`,bindings:{inTexture:o},uniforms:{textureSize:e},targetTexture:i,...s,vertexCount:e*e,topology:"point-list",parameters:{depthWriteEnabled:!1,blendColorOperation:"max",blendAlphaOperation:"max",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"}});this.setState({weightsTexture:o,maxWeightsTexture:i,maxWeightTransform:a,zoom:null,triPositionBuffer:t.createBuffer({byteLength:48}),triTexCoordBuffer:t.createBuffer({byteLength:48})})}updateShaders(t){this._createWeightsTransform({vs:ge,fs:fe,...t})}_updateMaxWeightValue(){let{maxWeightTransform:t}=this.state;t.run({parameters:{viewport:[0,0,1,1]},clearColor:[0,0,0,0]})}_updateBounds(t=!1){let{viewport:e}=this.context,o=[e.unproject([0,0]),e.unproject([e.width,0]),e.unproject([e.width,e.height]),e.unproject([0,e.height])].map(a=>a.map(Math.fround)),i=Zo(o),r={visibleWorldBounds:i,viewportCorners:o},s=!1;if(t||!this.state.worldBounds||!Jo(this.state.worldBounds,i)){let a=this._worldToCommonBounds(i),l=this._commonToWorldBounds(a);this.props.coordinateSystem===R.COORDINATE_SYSTEM.LNGLAT&&(l[1]=Math.max(l[1],-85.051129),l[3]=Math.min(l[3],85.051129),l[0]=Math.max(l[0],-360),l[2]=Math.min(l[2],360));let c=this._worldToCommonBounds(l);r.worldBounds=l,r.normalizedCommonBounds=c,s=!0}return this.setState(r),s}_updateTextureRenderingBounds(){let{triPositionBuffer:t,triTexCoordBuffer:e,normalizedCommonBounds:o,viewportCorners:i}=this.state,{viewport:r}=this.context;t.write(ce(i,3));let s=i.map(a=>ei(r.projectPosition(a),o));e.write(ce(s,2))}_updateColorTexture(t){let{colorRange:e}=t.props,{colorTexture:o}=this.state,i=z(e,!1,Uint8Array);o&&o?.width===e.length?o.setSubImageData({data:i}):(o?.destroy(),o=this.context.device.createTexture({...de,data:i,width:e.length,height:1})),this.setState({colorTexture:o})}_updateWeightmap(){let{radiusPixels:t,colorDomain:e,aggregation:o}=this.props,{worldBounds:i,textureSize:r,weightsScale:s}=this.state,a=this.state.weightsTransform;this.state.isWeightMapDirty=!1;let l=this._worldToCommonBounds(i,{useLayerCoordinateSystem:!0});if(e&&o==="SUM"){let{viewport:h}=this.context,A=h.distanceScales.metersPerUnit[2]*(l[2]-l[0])/r;this.state.colorDomain=e.map(S=>S*A*s)}else this.state.colorDomain=e||ai;let g=this.getAttributeManager().getAttributes(),f=this.getModuleSettings(),d=g.positions.buffer,p={radiusPixels:t,commonBounds:l,textureWidth:r,weightsScale:s},x=g.weights.buffer;a.model.setAttributes({positions:d,weights:x}),a.model.setVertexCount(this.getNumInstances()),a.model.setUniforms(p),a.model.updateModuleSettings(f),a.run({parameters:{viewport:[0,0,r,r]},clearColor:[0,0,0,0]}),this._updateMaxWeightValue()}_debouncedUpdateWeightmap(t=!1){let{updateTimer:e}=this.state,{debounceTimeout:o}=this.props;t?(e=null,this._updateBounds(!0),this._updateTextureRenderingBounds(),this.setState({isWeightMapDirty:!0})):(this.setState({isWeightMapDirty:!1}),clearTimeout(e),e=setTimeout(this._debouncedUpdateWeightmap.bind(this,!0),o)),this.setState({updateTimer:e})}_worldToCommonBounds(t,e={}){let{useLayerCoordinateSystem:o=!1}=e,[i,r,s,a]=t,{viewport:l}=this.context,{textureSize:c}=this.state,{coordinateSystem:g}=this.props,f=o&&(g===R.COORDINATE_SYSTEM.LNGLAT_OFFSETS||g===R.COORDINATE_SYSTEM.METER_OFFSETS),d=f?l.projectPosition(this.props.coordinateOrigin):[0,0],p=c*_r/l.scale,x,h;return o&&!f?(x=this.projectPosition([i,r,0]),h=this.projectPosition([s,a,0])):(x=l.projectPosition([i,r,0]),h=l.projectPosition([s,a,0])),ti([x[0]-d[0],x[1]-d[1],h[0]-d[0],h[1]-d[1]],p,p)}_commonToWorldBounds(t){let[e,o,i,r]=t,{viewport:s}=this.context,a=s.unprojectPosition([e,o]),l=s.unprojectPosition([i,r]);return a.slice(0,2).concat(l.slice(0,2))}},Ct=Kt;(()=>{Kt.layerName="HeatmapLayer"})(),(()=>{Kt.defaultProps=Mr})();return pi(Et);})();
|
|
508
508
|
return __exports__;
|
|
509
509
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "deck.gl layers that aggregate the input data into alternative representations",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "9.0.
|
|
6
|
+
"version": "9.0.6",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@luma.gl/core": "^9.0.0",
|
|
50
50
|
"@luma.gl/engine": "^9.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "fdbf68be3761c1a7e4bf5d2c6b20792fd8796937"
|
|
53
53
|
}
|
|
@@ -469,7 +469,7 @@ export default class HeatmapLayer<
|
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
_updateMaxWeightValue() {
|
|
472
|
-
const {maxWeightTransform
|
|
472
|
+
const {maxWeightTransform} = this.state;
|
|
473
473
|
|
|
474
474
|
maxWeightTransform!.run({
|
|
475
475
|
parameters: {viewport: [0, 0, 1, 1]},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
19
|
// THE SOFTWARE.
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {Texture} from '@luma.gl/core';
|
|
22
22
|
import {Model, Geometry} from '@luma.gl/engine';
|
|
23
23
|
import {Layer, LayerProps, log, picking, UpdateParameters, DefaultProps} from '@deck.gl/core';
|
|
24
24
|
import {defaultColorRange, colorRangeToFlatArray} from '../utils/color-utils';
|
|
@@ -22,7 +22,7 @@ import type {Device, DeviceFeature} from '@luma.gl/core';
|
|
|
22
22
|
import {Model, TextureTransform} from '@luma.gl/engine';
|
|
23
23
|
import {fp64arithmetic} from '@luma.gl/shadertools';
|
|
24
24
|
import {GL} from '@luma.gl/constants';
|
|
25
|
-
import {
|
|
25
|
+
import {project32, _mergeShaders as mergeShaders, getShaderAssembler} from '@deck.gl/core';
|
|
26
26
|
|
|
27
27
|
import {
|
|
28
28
|
DEFAULT_RUN_PARAMS,
|
|
@@ -397,7 +397,7 @@ export default class GPUGridAggregator {
|
|
|
397
397
|
|
|
398
398
|
// render all aggregated grid-cells to generate Min, Max or MaxMin data texture
|
|
399
399
|
_renderToMaxMinTexture(opts) {
|
|
400
|
-
const {id,
|
|
400
|
+
const {id, gridSize, minOrMaxFb, combineMaxMin, clearParams = {}} = opts;
|
|
401
401
|
const {framebuffers} = this.state;
|
|
402
402
|
const {allAggregationModel} = this;
|
|
403
403
|
|