Home > SCH_PrimitivePolygon > create
SCH_PrimitivePolygon.create() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Create Polygon
Signature
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
Parameters
Parameter | Type | Description |
|---|---|---|
line | Array<number> | Coordinate group, a continuous set of lines described by |
color | string | null | (Optional) Color, |
fillColor | string | null | (Optional) Fill color. |
lineWidth | number | null | (Optional) Line width, range |
lineType | ESCH_PrimitiveLineType | null | (Optional) Line type. |
Returns
Promise<ISCH_PrimitivePolygon | undefined>
Polygon primitive object
Example
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