From aad31d37bbbd21faf9634ae0b78301a48b3d724e Mon Sep 17 00:00:00 2001 From: YiQianYao <42212176+2912401452@users.noreply.github.com> Date: Thu, 14 Jul 2022 15:41:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20option=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E3=80=81shader=20=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#1235)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 在点图层中去除 global 的耦合 * style: lint style * fix: 修复更新 style 的同时更新了 option 带来的问题 * style: lint style * feat: 拆除 arc3d 地球模式和普通模式的耦合 * style: lint style * fix: 修复 earthExtrude shader 路径错误、option 更新错误 * style: lint style --- packages/layers/src/core/BaseLayer.ts | 18 ++++++++++------ .../layers/src/point/models/earthExtrude.ts | 21 +++++++------------ packages/layers/src/point/models/extrude.ts | 15 +------------ 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index 75a89a8644..bce6e20953 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -246,6 +246,13 @@ export default class BaseLayer public updateLayerConfig( configToUpdate: Partial, ) { + // 同步 rawConfig + Object.keys(configToUpdate).map((key) => { + if (key in this.rawConfig) { + // @ts-ignore + this.rawConfig[key] = configToUpdate[key]; + } + }); if (!this.inited) { this.needUpdateConfig = { ...this.needUpdateConfig, @@ -635,13 +642,12 @@ export default class BaseLayer ); } - // this.rawConfig = { - // ...this.rawConfig, - // ...rest, - // }; + this.rawConfig = { + ...this.rawConfig, + ...rest, + }; if (this.container) { - // this.updateLayerConfig(this.rawConfig); - this.updateLayerConfig(rest); + this.updateLayerConfig(this.rawConfig); this.styleNeedUpdate = true; } diff --git a/packages/layers/src/point/models/earthExtrude.ts b/packages/layers/src/point/models/earthExtrude.ts index 980252acec..03474379fa 100644 --- a/packages/layers/src/point/models/earthExtrude.ts +++ b/packages/layers/src/point/models/earthExtrude.ts @@ -12,8 +12,8 @@ import { IPointLayerStyleOptions } from '../../core/interface'; import { PointExtrudeTriangulation } from '../../core/triangulation'; import { lglt2xyz } from '../../earth/utils'; import { calculateCentroid } from '../../utils/geo'; -import pointExtrudeFrag from '../shaders/earth/extrude/extrude_frag.glsl'; -import pointExtrudeVert from '../shaders/earth/extrude/extrude_vert.glsl'; +import pointExtrudeFrag from '../shaders/earth/extrude_frag.glsl'; +import pointExtrudeVert from '../shaders/earth/extrude_vert.glsl'; export default class ExtrudeModel extends BaseModel { private raiseCount: number = 0; @@ -162,8 +162,6 @@ export default class ExtrudeModel extends BaseModel { this.dataTexture?.destroy(); } protected registerBuiltinAttributes() { - // TODO: 判断当前的点图层的模型是普通地图模式还是地球模式 - const isGlobel = this.mapService.version === 'GLOBEL'; // point layer size; this.styleAttributeService.registerStyleAttribute({ name: 'size', @@ -239,16 +237,11 @@ export default class ExtrudeModel extends BaseModel { size: 3, update: (feature: IEncodeFeature, featureIdx: number) => { const coordinates = calculateCentroid(feature.coordinates); - if (isGlobel) { - // TODO: 在地球模式下需要将传入 shader 的经纬度转化成对应的 xyz 坐标 - return lglt2xyz([coordinates[0], coordinates[1]]) as [ - number, - number, - number, - ]; - } else { - return [coordinates[0], coordinates[1], 0]; - } + return lglt2xyz([coordinates[0], coordinates[1]]) as [ + number, + number, + number, + ]; }, }, }); diff --git a/packages/layers/src/point/models/extrude.ts b/packages/layers/src/point/models/extrude.ts index d096ea5fd0..62a55779e1 100644 --- a/packages/layers/src/point/models/extrude.ts +++ b/packages/layers/src/point/models/extrude.ts @@ -10,7 +10,6 @@ import { isNumber } from 'lodash'; import BaseModel from '../../core/BaseModel'; import { IPointLayerStyleOptions } from '../../core/interface'; import { PointExtrudeTriangulation } from '../../core/triangulation'; -import { lglt2xyz } from '../../earth/utils'; import { calculateCentroid } from '../../utils/geo'; import pointExtrudeFrag from '../shaders/extrude/extrude_frag.glsl'; import pointExtrudeVert from '../shaders/extrude/extrude_vert.glsl'; @@ -103,7 +102,6 @@ export default class ExtrudeModel extends BaseModel { } } } - return { // 圆柱体的拾取高亮是否要计算光照 u_pickLight: Number(pickLight), @@ -162,8 +160,6 @@ export default class ExtrudeModel extends BaseModel { this.dataTexture?.destroy(); } protected registerBuiltinAttributes() { - // TODO: 判断当前的点图层的模型是普通地图模式还是地球模式 - const isGlobel = this.mapService.version === 'GLOBEL'; // point layer size; this.styleAttributeService.registerStyleAttribute({ name: 'size', @@ -239,16 +235,7 @@ export default class ExtrudeModel extends BaseModel { size: 3, update: (feature: IEncodeFeature, featureIdx: number) => { const coordinates = calculateCentroid(feature.coordinates); - if (isGlobel) { - // TODO: 在地球模式下需要将传入 shader 的经纬度转化成对应的 xyz 坐标 - return lglt2xyz([coordinates[0], coordinates[1]]) as [ - number, - number, - number, - ]; - } else { - return [coordinates[0], coordinates[1], 0]; - } + return [coordinates[0], coordinates[1], 0]; }, }, });