feat: 增加 arc 弧线的分段数控制

This commit is contained in:
2912401452 2021-09-02 13:49:05 +08:00
parent 3e05aeae71
commit a7314f8f9e
7 changed files with 13 additions and 4 deletions

View File

@ -57,6 +57,7 @@ export interface ILayerModelInitializationOptions {
vertexShader: string;
fragmentShader: string;
triangulation: Triangulation;
segmentNumber?: number;
}
export interface ILayerModel {

View File

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

View File

@ -187,6 +187,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
public createAttributesAndIndices(
features: IEncodeFeature[],
triangulation: Triangulation,
segmentNumber: number
): {
attributes: {
[attributeName: string]: IAttribute;
@ -217,7 +218,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
vertices: verticesForCurrentFeature,
normals: normalsForCurrentFeature,
size: vertexSize,
} = this.triangulation(feature);
} = this.triangulation(feature, segmentNumber);
indicesForCurrentFeature.forEach((i) => {
indices.push(i + verticesNum);
});

View File

@ -858,6 +858,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
vertexShader,
fragmentShader,
triangulation,
segmentNumber,
...rest
} = options;
this.shaderModuleService.registerModule(moduleName, {
@ -872,6 +873,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
} = this.styleAttributeService.createAttributesAndIndices(
this.encodedData,
triangulation,
segmentNumber
);
return createModel({
attributes,

View File

@ -202,8 +202,8 @@ export function RasterImageTriangulation(feature: IEncodeFeature) {
* @param feature
* @param segNum 线线
*/
export function LineArcTriangulation(feature: IEncodeFeature) {
const segNum = 30;
export function LineArcTriangulation(feature: IEncodeFeature, segmentNumber?: number) {
const segNum = segmentNumber ? segmentNumber : 30;
const coordinates = feature.coordinates as IPosition[];
const positions = [];
const indexArray = [];

View File

@ -132,6 +132,8 @@ export default class ArcModel extends BaseModel {
}
public buildModels(): IModel[] {
let { segmentNumber = 30 } = this.layer.getLayerConfig() as ILineLayerStyleOptions;
return [
this.layer.buildLayerModel({
moduleName: 'arc2dline',
@ -140,6 +142,7 @@ export default class ArcModel extends BaseModel {
triangulation: LineArcTriangulation,
depth: { enable: false },
blend: this.getBlend(),
segmentNumber
}),
];
}

View File

@ -44,7 +44,7 @@ export default class Amap2demo_arcLine extends React.Component {
.style({
opacity: 0.8,
blur: 0.99,
segmentNumber: 30
segmentNumber: 3,
// lineType: 'dash',
// dashArray: [5, 5],
});