SVG.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import VectorType from "../enum/VectorType.js";
  2. import Geometry from "./Geometry.js";
  3. import { mathUtil } from "../Util/MathUtil.js";
  4. import { coordinate } from "../Coordinate.js";
  5. import Constant from "../Constant.js";
  6. //const sideWidth = 10;
  7. export default class SVG extends Geometry {
  8. constructor(center, vectorId) {
  9. super();
  10. this.center = center;
  11. this.points = null; //包裹的矩形的四个顶点
  12. this.angle = 0; //逆时针为负,顺时针为正。单位是:°
  13. this.scale = 1; //缩放比例
  14. this.name = null;
  15. this.geoType = VectorType.SVG;
  16. this.setId(vectorId);
  17. }
  18. // createDefaultPoints() {
  19. // this.points = [];
  20. // this.points[0] = {
  21. // x: this.center.x - sideWidth / 2,
  22. // y: this.center.y + sideWidth / 2,
  23. // };
  24. // this.points[1] = {
  25. // x: this.center.x + sideWidth / 2,
  26. // y: this.center.y + sideWidth / 2,
  27. // };
  28. // this.points[2] = {
  29. // x: this.center.x + sideWidth / 2,
  30. // y: this.center.y - sideWidth / 2,
  31. // };
  32. // this.points[3] = {
  33. // x: this.center.x - sideWidth / 2,
  34. // y: this.center.y - sideWidth / 2,
  35. // };
  36. // }
  37. getBoundingVertexs(center) {
  38. const boundingVertexs = [];
  39. const rec = this.getLengthWidth();
  40. const length = this.getScale() * rec.length * this.scale;
  41. const width = this.getScale() * rec.width * this.scale;
  42. const minX = center.x - length / 2;
  43. const minY = center.y - width / 2;
  44. const maxX = center.x + length / 2;
  45. const maxY = center.y + width / 2;
  46. const point1 = this.rotatePoint(
  47. {
  48. x: minX,
  49. y: maxY,
  50. },
  51. center,
  52. this.angle
  53. );
  54. const point2 = this.rotatePoint(
  55. {
  56. x: maxX,
  57. y: maxY,
  58. },
  59. center,
  60. this.angle
  61. );
  62. const point3 = this.rotatePoint(
  63. {
  64. x: maxX,
  65. y: minY,
  66. },
  67. center,
  68. this.angle
  69. );
  70. const point4 = this.rotatePoint(
  71. {
  72. x: minX,
  73. y: minY,
  74. },
  75. center,
  76. this.angle
  77. );
  78. boundingVertexs.push(point1);
  79. boundingVertexs.push(point2);
  80. boundingVertexs.push(point3);
  81. boundingVertexs.push(point4);
  82. return boundingVertexs;
  83. }
  84. //不同图例,缩放比不一样
  85. getScale() {
  86. return 1;
  87. }
  88. getLengthWidth() {
  89. return {
  90. length: 32,
  91. width: 32,
  92. };
  93. }
  94. }