1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { Attrib, CustomizeShape, CustomizeShapeFactory } from "../../../type";
- import { polygonShapeFactory, polygon } from "../style";
- import { WholeLine, WholeLineAttrib } from "./whole-line";
- import { getWholeLinePolygonPoints } from "../service/whole-line-base";
- import { Entity, EntityProps } from "../../entity";
- import { Line } from "konva/lib/shapes/Line";
- import { Shape } from "konva/lib/Shape";
- import { Group } from "konva/lib/Group";
- export type WholeLinePolygonAttrib = Attrib & {
- lineIds: string[];
- };
- export type WholeLinePolygonProps<
- T extends WholeLinePolygonAttrib = WholeLinePolygonAttrib
- > = EntityProps<T>;
- export class WholeLinePolygon<
- T extends WholeLinePolygonAttrib = WholeLinePolygonAttrib,
- R extends Shape | Group = Line
- > extends Entity<T, R> {
- static namespace = "polygon";
- get config() {
- return (this.parent as WholeLine).attrib;
- }
- actShape: CustomizeShape<number[], R>;
- actShapeFactory: CustomizeShapeFactory<T, number[], R>;
- constructor(props: WholeLinePolygonProps<T>) {
- props.zIndex = props.zIndex || polygon.zIndex;
- props.name = props.name || WholeLinePolygon.namespace + props.attrib.id;
- super(props);
- this.actShapeFactory =
- polygonShapeFactory as unknown as CustomizeShapeFactory<T, number[], R>;
- }
- setActShapeFactory(actShapeFactory: CustomizeShapeFactory<T, number[], R>) {
- this.actShapeFactory = actShapeFactory;
- }
- initShape() {
- this.actShape = this.actShapeFactory(this.attrib, this);
- return this.actShape.shape;
- }
- diffRedraw(): void {
- this.actShape.setData(this.getCoords());
- }
- getCoords() {
- const result: number[] = [];
- const points = getWholeLinePolygonPoints(this.config, this.attrib.id);
- if (!points.some((point) => !point)) {
- points.forEach(({ x, y }, ndx) => {
- result[ndx * 2] = x;
- result[ndx * 2 + 1] = y;
- });
- }
- return result;
- }
- mounted(): void {
- super.mounted();
- this.actShape.common(null);
- }
- }
|