Tag.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import VectorType from "../enum/VectorType.js";
  2. import Geometry from "./Geometry";
  3. // import { mathUtil } from '../MathUtil.js'
  4. import { coordinate } from "../Coordinate";
  5. import Constant from "../Constant.js";
  6. //不靠墙
  7. export default class Tag extends Geometry {
  8. constructor(center, vectorId) {
  9. super();
  10. this.center = center;
  11. this.points2d = [];
  12. //this.title = KanKan.Config.i18n('cad.input')
  13. this.title = "";
  14. this.des = ""; //面积
  15. this.unit = "m"; //或者ft
  16. this.name = "标注";
  17. this.adding = true;
  18. this.sideWidth = 30; //像素
  19. this.sideThickness = 30; //像素
  20. this.geoType = VectorType.Tag;
  21. this.setId(vectorId);
  22. }
  23. isContain(position) {
  24. let points = [];
  25. points.push(this.points2d[0]);
  26. points.push(this.points2d[1]);
  27. points.push(this.points2d[2]);
  28. points.push(this.points2d[3]);
  29. return mathUtil.isPointInPoly(position, points);
  30. }
  31. setPoints2d() {
  32. this.points2d = [];
  33. const minX =
  34. this.center.x -
  35. ((this.sideWidth / coordinate.res) * Constant.defaultZoom) /
  36. coordinate.zoom /
  37. 2;
  38. const minY =
  39. this.center.y -
  40. ((this.sideThickness / coordinate.res) * Constant.defaultZoom) /
  41. coordinate.zoom /
  42. 2;
  43. const maxX =
  44. this.center.x +
  45. ((this.sideWidth / coordinate.res) * Constant.defaultZoom) /
  46. coordinate.zoom /
  47. 2;
  48. const maxY =
  49. this.center.y +
  50. ((this.sideThickness / coordinate.res) * Constant.defaultZoom) /
  51. coordinate.zoom /
  52. 2;
  53. const point1 = {
  54. x: minX,
  55. y: maxY,
  56. };
  57. const point2 = {
  58. x: maxX,
  59. y: maxY,
  60. };
  61. const point3 = {
  62. x: maxX,
  63. y: minY,
  64. };
  65. const point4 = {
  66. x: minX,
  67. y: minY,
  68. };
  69. this.points2d.push(point1);
  70. this.points2d.push(point2);
  71. this.points2d.push(point3);
  72. this.points2d.push(point4);
  73. //-
  74. let dx = (point1.x - this.center.x) / 2;
  75. //+
  76. let dy = (point1.y - this.center.y) / 2;
  77. this.points2d.push({
  78. x: point1.x - dx,
  79. y: point1.y - dy,
  80. });
  81. this.points2d.push({
  82. x: point2.x + dx,
  83. y: point1.y - dy,
  84. });
  85. this.points2d.push({
  86. x: this.center.x,
  87. y: point1.y - dy,
  88. });
  89. this.points2d.push({
  90. x: this.center.x,
  91. y: point3.y + dy,
  92. });
  93. }
  94. setTitle(title) {
  95. this.title = title;
  96. }
  97. setDes(des) {
  98. this.des = des;
  99. }
  100. setUnit(unit) {
  101. this.unit = unit;
  102. }
  103. setAdding(flag) {
  104. this.adding = flag;
  105. }
  106. }