point.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { PolygonsPointAttrib } from "@/request/type";
  2. import {
  3. openEntityDrag,
  4. getRealAbsoluteSize,
  5. WholeLinePoint,
  6. getWholeLinePolygonPoints,
  7. WholeLinePointProps,
  8. } from "drawing-board";
  9. import { Path } from "konva/lib/shapes/Path";
  10. import { Group } from "konva/lib/Group";
  11. import { Circle } from "konva/lib/shapes/Circle";
  12. import { Label, Tag } from "konva/lib/shapes/Label";
  13. import { Text } from "konva/lib/shapes/Text";
  14. import { Polygons } from "./polygons";
  15. const actShapeFactory = (attrib: PolygonsPointAttrib, tree: any) => {
  16. const polygons = tree.parent as Polygons;
  17. const size = { width: 40, height: 40 };
  18. const out = new Path({
  19. data: `M22 44C32.6667 33.891 38 25.891 38 20C38 11.1634 30.8366 4 22 4C13.1634 4 6 11.1634 6 20C6 25.891 11.3333 33.891 22 44Z`,
  20. });
  21. const inner = new Path({
  22. fill: "#fff",
  23. data: `M22 30C27.5228 30 32 25.5228 32 20C32 14.4772 27.5228 10 22 10C16.4772 10 12 14.4772 12 20C12 25.5228 16.4772 30 22 30Z`,
  24. });
  25. const rect = new Circle({
  26. radius: Math.min(size.width, size.height) / 2,
  27. fill: "rgba(0, 0, 0, 0)",
  28. offset: { x: -size.width / 2, y: -size.height / 2 },
  29. });
  30. const index = new Text({
  31. name: "text",
  32. text: `1`,
  33. fontFamily: "Calibri",
  34. fontSize: 12,
  35. padding: 5,
  36. offsetY: -8,
  37. fill: "#000",
  38. });
  39. const label = new Label({
  40. visible: false,
  41. opacity: 0.75,
  42. name: "label",
  43. offsetX: -size.width / 2,
  44. offsetY: -6,
  45. });
  46. label.add(
  47. new Tag({
  48. name: "tag",
  49. fill: "rgba(255, 255, 255, 0.8)",
  50. pointerDirection: "down",
  51. pointerWidth: 5,
  52. pointerHeight: 5,
  53. lineJoin: "round",
  54. shadowColor: "black",
  55. shadowBlur: 10,
  56. shadowOffsetX: 10,
  57. shadowOffsetY: 10,
  58. shadowOpacity: 0.5,
  59. }),
  60. new Text({
  61. name: "text",
  62. text: `P${attrib.id}`,
  63. fontFamily: "Calibri",
  64. fontSize: 10,
  65. padding: 5,
  66. fill: "#000",
  67. })
  68. );
  69. const offsetGroup = new Group();
  70. offsetGroup.add(out, inner, rect, label, index);
  71. offsetGroup.x(-size.width / 2);
  72. offsetGroup.y(-size.height);
  73. const group = new Group();
  74. group.add(offsetGroup);
  75. const setStyle = () => {
  76. let [width, height] = getRealAbsoluteSize(group, [1, 1]);
  77. group.scale({ x: width, y: height });
  78. if (polygons.currentPolygonId) {
  79. const points = getWholeLinePolygonPoints(
  80. polygons.attrib,
  81. polygons.currentPolygonId
  82. ).map(({ id }) => id);
  83. const ndx = points.indexOf(attrib.id);
  84. if (~ndx) {
  85. index.text((ndx + 1).toString()).visible(true);
  86. index.offsetX(-rect.width() / 2 + index.width() / 2.5);
  87. return;
  88. }
  89. }
  90. index.visible(false);
  91. };
  92. const result = {
  93. shape: group,
  94. common: () => {
  95. out.fill(attrib.rtk ? "#728190" : "#409EFF");
  96. label.visible(false);
  97. polygons.bus.emit("hoverPoint", null);
  98. },
  99. hover: () => {
  100. out.fill(attrib.rtk ? "#728190" : "#E6A23C");
  101. label.visible(true);
  102. polygons.bus.emit("hoverPoint", tree.attrib);
  103. },
  104. setData(data: number[]) {
  105. setStyle();
  106. group.x(data[0]);
  107. group.y(data[1]);
  108. },
  109. active() {
  110. out.fill("#E6A23C");
  111. if (!polygons.currentPolygonId) {
  112. polygons.bus.emit("activePoint", tree.attrib);
  113. }
  114. },
  115. draging() {
  116. out.fill("#E6A23C");
  117. },
  118. };
  119. if (attrib.rtk) {
  120. return result;
  121. } else {
  122. return {
  123. ...result,
  124. draging() {
  125. out.fill("#E6A23C");
  126. },
  127. };
  128. }
  129. };
  130. export class PYPoint extends WholeLinePoint<PolygonsPointAttrib, Group> {
  131. constructor(props: WholeLinePointProps<PolygonsPointAttrib>) {
  132. super(props);
  133. this.actShapeFactory = actShapeFactory;
  134. }
  135. mounted() {
  136. super.mounted();
  137. if (!this.attrib.rtk) {
  138. openEntityDrag(this, {
  139. readyHandler: (attrib) => {
  140. return [attrib.x, attrib.y];
  141. },
  142. moveHandler: (pointAttrib, move) => {
  143. pointAttrib.x = move[0];
  144. pointAttrib.y = move[1];
  145. },
  146. });
  147. }
  148. this.enableMouseAct(this.actShape);
  149. }
  150. }