Skip to content

Commit

Permalink
Fix regl bool uniform (#2420)
Browse files Browse the repository at this point in the history
* fix: regl bool 兼容问题导致raster terrain rgb 不能显示

* chore: 移除未使用函数

* chore: commit changeset
  • Loading branch information
lzxue authored Apr 22, 2024
1 parent 1bf4847 commit bb0af05
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .changeset/late-plums-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@antv/l7-layers': patch
'@antv/l7-component': patch
'@antv/l7-core': patch
'@antv/l7': patch
'@antv/l7-map': patch
'@antv/l7-maps': patch
'@antv/l7-renderer': patch
'@antv/l7-scene': patch
'@antv/l7-source': patch
'@antv/l7-test-utils': patch
'@antv/l7-three': patch
'@antv/l7-utils': patch
---

fix regl bool uniform
27 changes: 27 additions & 0 deletions packages/layers/__tests__/tile/raster-tile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,31 @@ describe('raster-tile', () => {
scene.addLayer(layer1);
scene.setZoom(12);
});

it('rasterLayer rgb', async () => {
const layer = new RasterLayer()
.source(
'https://tiles{1-3}.geovisearth.com/base/v1/terrain_rgb/{z}/{x}/{y}?format=png&tmsIds=w&token=b2a0cfc132cd60b61391b9dd63c15711eadb9b38a9943e3f98160d5710aef788',
{
parser: {
type: 'rasterTile',
dataType: 'terrainRGB',
tileSize: 256,
zoomOffset: 0,
},
},
)
.style({
clampLow: false,
clampHigh: false,
domain: [0, 7000],
rampColors: {
colors: ['#d73027', '#fc8d59', '#fee08b', '#d9ef8b', '#91cf60', '#1a9850'],
positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
},
});

scene.addLayer(layer);
scene.setZoom(12);
});
});
6 changes: 6 additions & 0 deletions packages/layers/src/core/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ export default class BaseModel<ChildLayerStyleOptions = {}> implements ILayerMod
...attributeInfo.uniformsOption,
...commoninfo.uniformsOption,
};
// 兼容 Regl Boolean 类型
Object.keys(result).forEach((key) => {
if (typeof result[key] === 'boolean') {
result[key] = result[key] ? 1 : 0;
}
});
//如果是regl渲染 需要在uniform中带上u_texture 暂时用this.rendererService.device判断
if (
!this.rendererService.hasOwnProperty('device') &&
Expand Down
13 changes: 0 additions & 13 deletions packages/layers/src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
export function formatUniformsOption2Std140(uniformsOption: { [key: string]: any }) {
let std140_str = '';
Object.keys(uniformsOption).forEach((key) => {
const value = uniformsOption[key];
if (Array.isArray(value)) {
std140_str += `vec${value.length} ${key};\n`;
} else {
std140_str += `flot ${key};\n`;
}
});
return std140_str;
}

export function MultipleOfFourNumber(num: number) {
return Math.max(Math.ceil(num / 4) * 4, 4);
}

0 comments on commit bb0af05

Please sign in to comment.