Geometry.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { dataService } from "../Service/DataService";
  2. import { mathUtil } from "../Util/MathUtil";
  3. export default class Geometry {
  4. constructor() {
  5. this.display = true;
  6. }
  7. setId(vectorId) {
  8. if (vectorId == null || typeof vectorId === "undefined") {
  9. vectorId = dataService.getCurrentId();
  10. dataService.updateCurrentId();
  11. this.vectorId = this.geoType + vectorId;
  12. } else {
  13. this.vectorId = vectorId;
  14. }
  15. }
  16. getIndex() {
  17. return this.index;
  18. }
  19. setIndex(index) {
  20. this.index = index;
  21. }
  22. getPoints() {
  23. return this.points;
  24. }
  25. setPoints(points) {
  26. this.points = JSON.parse(JSON.stringify(points));
  27. }
  28. setPointParent(parentId, dir) {
  29. if (this.parent == null) {
  30. this.parent = {};
  31. }
  32. this.parent[parentId] = dir;
  33. }
  34. setEdgeParent(parentId) {
  35. if (this.parent == null) {
  36. this.parent = {};
  37. }
  38. this.parent = parentId;
  39. }
  40. setLeftEdge(edgeId) {
  41. this.leftEdgeId = edgeId;
  42. }
  43. setRightEdge(edgeId) {
  44. this.rightEdgeId = edgeId;
  45. }
  46. setDisplay(value) {
  47. this.display = value;
  48. }
  49. setParent(value) {
  50. this.parent = value;
  51. }
  52. getParent() {
  53. return this.parent;
  54. }
  55. setValue(value) {
  56. this.value = value;
  57. }
  58. getValue() {
  59. return this.value;
  60. }
  61. getCenter() {
  62. return this.center;
  63. }
  64. setCenter(center) {
  65. if (center) {
  66. this.center = {};
  67. this.center.x = center.x;
  68. this.center.y = center.y;
  69. }
  70. }
  71. setColor(value) {
  72. this.color = value;
  73. }
  74. getColor() {
  75. return this.color;
  76. }
  77. getStyle() {
  78. return this.style;
  79. }
  80. setStyle(style) {
  81. this.style = style;
  82. }
  83. getStyle() {
  84. return this.weight;
  85. }
  86. setWeight(weight) {
  87. this.weight = weight;
  88. }
  89. getWeight() {
  90. return this.weight;
  91. }
  92. setPhotoUrl(src) {
  93. this.photoUrl = src;
  94. }
  95. setPhotoImg(type) {
  96. this.photoImage = type;
  97. }
  98. getType() {
  99. return this.type;
  100. }
  101. setType(type) {
  102. this.type = type;
  103. }
  104. getCategory() {
  105. return this.category;
  106. }
  107. setLocationMode(value) {
  108. this.locationMode = value;
  109. }
  110. setLinkedBasePointId(id) {
  111. this.linkedBasePointId = id;
  112. }
  113. setLinkedTestPointId(id) {
  114. this.linkedTestPointId = id;
  115. }
  116. getLocationMode() {
  117. return this.locationMode;
  118. }
  119. // ptSrc: 圆上某点(初始点);
  120. // ptRotationCenter: 圆心点;
  121. // angle: 旋转角度° -- [angle * M_PI / 180]:将角度换算为弧度
  122. // 【注意】angle 逆时针为正,顺时针为负
  123. rotatePoint(ptSrc, ptRotationCenter, angle) {
  124. angle = -1 * angle; //设计是逆时针为负,顺时针为正
  125. var a = ptRotationCenter.x;
  126. var b = ptRotationCenter.y;
  127. var x0 = ptSrc.x;
  128. var y0 = ptSrc.y;
  129. var rx =
  130. a +
  131. (x0 - a) * Math.cos((angle * Math.PI) / 180) -
  132. (y0 - b) * Math.sin((angle * Math.PI) / 180);
  133. var ry =
  134. b +
  135. (x0 - a) * Math.sin((angle * Math.PI) / 180) +
  136. (y0 - b) * Math.cos((angle * Math.PI) / 180);
  137. var json = { x: rx, y: ry };
  138. return json;
  139. }
  140. }