feat: 补充 pickLight 模式下 polygon 挤出对象支持抬升

This commit is contained in:
2912401452 2022-03-28 19:45:24 +08:00
parent 6f4be840f4
commit 22807a0fa7
3 changed files with 31 additions and 10 deletions

View File

@ -61,25 +61,40 @@ export default class ExtrudeModel extends BaseModel {
public buildModels(): IModel[] {
const {
pickLight = false,
mask = false,
maskInside = true,
} = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
const { frag, vert, type } = this.getShaders();
return [
this.layer.buildLayerModel({
moduleName: 'polygonExtrude',
vertexShader: pickLight
? polygonExtrudePickLightVert
: polygonExtrudeVert,
fragmentShader: pickLight
? polygonExtrudePickLightFrag
: polygonExtrudeFrag,
moduleName: type,
vertexShader: vert,
fragmentShader: frag,
triangulation: PolygonExtrudeTriangulation,
stencil: getMask(mask, maskInside),
}),
];
}
public getShaders() {
const { pickLight } = this.layer.getLayerConfig() as IPolygonLayerStyleOptions;
if(pickLight) {
return {
frag: polygonExtrudePickLightFrag,
vert: polygonExtrudePickLightVert,
type: 'polygonExtrude'
}
} else {
return {
frag: polygonExtrudeFrag,
vert: polygonExtrudeVert,
type: 'polygonExtrude'
}
}
}
public clearModels() {
this.dataTexture?.destroy();
}

View File

@ -13,6 +13,7 @@ uniform mat4 u_Mvp;
varying vec4 v_Color;
uniform float u_heightfixed: 0.0; // 默认不固定
uniform float u_raisingHeight: 0.0;
uniform float u_opacity: 1.0;
varying mat4 styleMappingMat; // 用于将在顶点着色器中计算好的样式值传递给片元
@ -56,8 +57,11 @@ void main() {
if(u_heightfixed > 0.0) { // 判断几何体是否固定高度
project_pos.z = a_Position.z * a_Size;
project_pos.z += u_raisingHeight;
if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
project_pos.z *= 4.0/pow(2.0, 21.0 - u_Zoom);
float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);
project_pos.z *= mapboxZoomScale;
project_pos.z += u_raisingHeight * mapboxZoomScale;
}
}

View File

@ -138,10 +138,12 @@ export default class Amap2demo_polygon_extrude extends React.Component {
.shape('extrude')
.color('#0DCCFF')
.active({
color: '#0DCCFF',
color: 'rgb(100,230,255)',
// color: '#00FFFF',
})
.style({
heightfixed: true,
pickLight: true,
raisingHeight: 200000,
opacity: 0.8,
});