Home > SCH_PrimitivePolygon > create
SCH_PrimitivePolygon.create() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
创建多边形
签名
typescript
function create(
line: Array<number>,
color?: string | null,
fillColor?: string | null,
lineWidth?: number | null,
lineType?: ESCH_PrimitiveLineType | null,
): Promise<ISCH_PrimitivePolygon | undefined>;1
2
3
4
5
6
7
2
3
4
5
6
7
参数名
参数 | 类型 | 描述 |
|---|---|---|
line | Array<number> | 坐标组,连续的一组 |
color | string | null | (可选) 颜色, |
fillColor | string | null | (可选) 填充颜色, |
lineWidth | number | null | (可选) 线宽,范围 |
lineType | ESCH_PrimitiveLineType | null | (可选) 线型, |
返回值
Promise<ISCH_PrimitivePolygon | undefined>
多边形图元对象
示例
javascript
// 1. 生成随机起点坐标,避免与画布上已有的多边形重合(SCH 坐标单位 10mil)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 创建一个 4 顶点矩形多边形:顶点依次为左下、右下、右上、左上,红色虚线边线、黄色填充、线宽 6
const line = [x, y, x + 400, y, x + 400, y + 300, x, y + 300];
const polygon = await eda.sch_PrimitivePolygon.create(line, '#FF0000', '#FFFF00', 6, 1);
// 3. 创建类保留现场,不删除图元
console.log('primitiveId:', polygon.getState_PrimitiveId());
console.log('primitiveType:', polygon.getState_PrimitiveType());
console.log('line:', JSON.stringify(polygon.getState_Line()));
console.log('color:', polygon.getState_Color());
console.log('fillColor:', polygon.getState_FillColor());
console.log('lineWidth:', polygon.getState_LineWidth());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15