fix(raster layer): update raster triangle

This commit is contained in:
thinkinggis 2019-11-04 11:19:45 +08:00
parent 9b8d3c8f5d
commit de276d7512
5 changed files with 46 additions and 29 deletions

View File

@ -131,7 +131,6 @@ export interface IStyleAttribute extends IStyleAttributeInitializationOptions {
export type Triangulation = ( export type Triangulation = (
feature: IEncodeFeature, feature: IEncodeFeature,
parserData: IParseDataItem,
) => { ) => {
vertices: number[]; vertices: number[];
indices: number[]; indices: number[];
@ -161,7 +160,6 @@ export interface IStyleAttributeService {
createAttributesAndIndices( createAttributesAndIndices(
encodedFeatures: IEncodeFeature[], encodedFeatures: IEncodeFeature[],
triangulation: Triangulation, triangulation: Triangulation,
parserData: IParseDataItem[],
): { ): {
attributes: { attributes: {
[attributeName: string]: IAttribute; [attributeName: string]: IAttribute;

View File

@ -167,7 +167,6 @@ export default class StyleAttributeService implements IStyleAttributeService {
public createAttributesAndIndices( public createAttributesAndIndices(
features: IEncodeFeature[], features: IEncodeFeature[],
triangulation: Triangulation, triangulation: Triangulation,
parserData: IParseDataItem[],
): { ): {
attributes: { attributes: {
[attributeName: string]: IAttribute; [attributeName: string]: IAttribute;
@ -188,7 +187,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
vertices: verticesForCurrentFeature, vertices: verticesForCurrentFeature,
normals: normalsForCurrentFeature, normals: normalsForCurrentFeature,
size: vertexSize, size: vertexSize,
} = triangulation(feature, parserData[featureIdx]); } = triangulation(feature);
indices.push(...indicesForCurrentFeature.map((i) => i + verticesNum)); indices.push(...indicesForCurrentFeature.map((i) => i + verticesNum));
vertices.push(...verticesForCurrentFeature); vertices.push(...verticesForCurrentFeature);
if (normalsForCurrentFeature) { if (normalsForCurrentFeature) {

View File

@ -351,7 +351,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> implements ILayer {
} = this.styleAttributeService.createAttributesAndIndices( } = this.styleAttributeService.createAttributesAndIndices(
this.encodedData, this.encodedData,
triangulation, triangulation,
parserData,
); );
return createModel({ return createModel({
attributes, attributes,

View File

@ -1,10 +1,7 @@
import { IEncodeFeature, IParseDataItem } from '@l7/core'; import { IEncodeFeature, IParseDataItem } from '@l7/core';
// @ts-ignore // @ts-ignore
import Martini from '@mapbox/martini'; import Martini from '@mapbox/martini';
export function RasterTriangulation( export function RasterTriangulation(parserData: IParseDataItem) {
feature: IEncodeFeature,
parserData: IParseDataItem,
) {
const { coordinates, data, min, max, width, height } = parserData; const { coordinates, data, min, max, width, height } = parserData;
const maxlength = Math.max(width, height); const maxlength = Math.max(width, height);
const gridSize = Math.pow(2, Math.ceil(Math.log2(maxlength))) + 1; const gridSize = Math.pow(2, Math.ceil(Math.log2(maxlength))) + 1;

View File

@ -24,8 +24,8 @@ interface IRasterLayerStyleOptions {
rampColors: IColorRamp; rampColors: IColorRamp;
} }
export default class ImageLayer extends BaseLayer<IRasterLayerStyleOptions> { export default class RasterLayer extends BaseLayer<IRasterLayerStyleOptions> {
public name: string = 'RasterLayer'; public name: string = 'e';
protected texture: ITexture2D; protected texture: ITexture2D;
protected colorTexture: ITexture2D; protected colorTexture: ITexture2D;
@ -81,24 +81,48 @@ export default class ImageLayer extends BaseLayer<IRasterLayerStyleOptions> {
height: imageData.height, height: imageData.height,
flipY: true, flipY: true,
}); });
this.models = [ this.models = [this.buildRasterModel()];
this.buildLayerModel({ }
moduleName: 'Raster', private buildRasterModel() {
vertexShader: rasterVert, const source = this.getSource();
fragmentShader: rasterFrag, const sourceFeature = source.data.dataArray[0];
triangulation: RasterTriangulation, const triangulation = RasterTriangulation(sourceFeature);
primitive: gl.TRIANGLES, this.shaderModuleService.registerModule('raster', {
depth: { enable: false }, vs: rasterVert,
blend: { fs: rasterFrag,
enable: true, });
func: {
srcRGB: gl.SRC_ALPHA, const { vs, fs, uniforms } = this.shaderModuleService.getModule('raster');
srcAlpha: 1, const {
dstRGB: gl.ONE_MINUS_SRC_ALPHA, createAttribute,
dstAlpha: 1, createElements,
}, createBuffer,
}, createModel,
} = this.rendererService;
return createModel({
vs,
fs,
attributes: {
a_Position: createAttribute({
buffer: createBuffer({
data: triangulation.vertices,
type: gl.FLOAT,
}),
size: 2,
}),
},
primitive: gl.TRIANGLES,
uniforms: {
...uniforms,
},
depth: {
enable: true,
},
elements: createElements({
data: triangulation.indices,
type: gl.UNSIGNED_INT,
count: triangulation.indices.length,
}), }),
]; });
} }
} }