polygon.ts 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {
  2. WholeLinePolygon,
  3. WholeLinePolygonAttrib,
  4. WholeLinePolygonProps,
  5. } from "drawing-board";
  6. import { Group } from "konva/lib/Group";
  7. import { Line } from "konva/lib/shapes/Line";
  8. import { Polygons } from "./polygons";
  9. const actShapeFactory = (attrib: WholeLinePolygonAttrib, tree: any) => {
  10. const polygons = tree.parent as Polygons;
  11. const isActive = () => polygons.currentId.value === attrib.id;
  12. const line = new Line({
  13. closed: true,
  14. });
  15. const common = () => {
  16. line.fill(
  17. isActive() ? "rgba(64, 158, 255, 0.3)" : "rgba(230, 162, 60, 0.30)"
  18. );
  19. };
  20. return {
  21. shape: line,
  22. setData(data: number[]) {
  23. line.points(data);
  24. common();
  25. },
  26. common,
  27. };
  28. };
  29. export class PYPolygon extends WholeLinePolygon<WholeLinePolygonAttrib, Group> {
  30. constructor(props: WholeLinePolygonProps<WholeLinePolygonAttrib>) {
  31. super(props);
  32. this.actShapeFactory = actShapeFactory;
  33. }
  34. mounted() {
  35. super.mounted();
  36. this.enableMouseAct(this.actShape);
  37. }
  38. }