LocationModeControl.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { mathUtil } from "../Util/MathUtil";
  2. import { textService } from "../Service/TextService";
  3. import { listenLayer } from "../ListenLayer";
  4. import Settings from "../Settings";
  5. import { dataService } from "../Service/DataService";
  6. import { lineService } from "../Service/LineService";
  7. import { pointService } from "../Service/PointService";
  8. import VectorCategory from "../enum/VectorCategory";
  9. import Constant from "../Constant";
  10. export default class LocationModeControl {
  11. constructor() {}
  12. //设置直角定位法
  13. setAngle() {
  14. let selectBasePoint = this.isFocusBasePoint();
  15. if (selectBasePoint) {
  16. let points = dataService.getPoints();
  17. for (let key in points) {
  18. let point = dataService.getPoint(key);
  19. if (point.getCategory() == VectorCategory.Point.FixPoint) {
  20. this.setSingleFixPointByAngle(
  21. point.vectorId,
  22. selectBasePoint.vectorId
  23. );
  24. }
  25. }
  26. }
  27. }
  28. //对一个点进行直角定位法
  29. //生成两条定位线和一条辅助线
  30. setSingleFixPointByAngle(fixPointId, basePointId) {
  31. let fixPoint = dataService.getPoint(fixPointId);
  32. let basePoint = dataService.getPoint(basePointId);
  33. let baseLine = dataService.getLine(Settings.baseLineId);
  34. let startPoint = dataService.getPoint(baseLine.startId);
  35. let endPoint = dataService.getPoint(baseLine.endId);
  36. let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
  37. let vLine = mathUtil.getVerticalLine(baseLineGeometry, fixPoint);
  38. let join = mathUtil.getJoinLinePoint(basePoint, vLine);
  39. join = pointService.create(join);
  40. join.setLocationMode(Constant.angleLocationMode);
  41. let locationLineByFixPoint = lineService.createByPointId(
  42. fixPointId,
  43. join.vectorId,
  44. VectorCategory.Line.LocationLineByFixPoint
  45. );
  46. locationLineByFixPoint.setLocationMode(Constant.angleLocationMode);
  47. let locationLineByBasePoint = mathUtil.getVerticalLine(vLine, basePoint);
  48. join = mathUtil.getIntersectionPoint(locationLineByBasePoint, vLine);
  49. join = pointService.create(join);
  50. join.setLocationMode(Constant.angleLocationMode);
  51. locationLineByBasePoint = lineService.createByPointId(
  52. basePointId,
  53. join.vectorId,
  54. VectorCategory.Line.LocationLineByBasePoint
  55. );
  56. locationLineByBasePoint.setLocationMode(Constant.angleLocationMode);
  57. let guideLocationLine = lineService.createByPointId(
  58. fixPointId,
  59. join.vectorId,
  60. VectorCategory.Line.GuideLocationLine
  61. );
  62. guideLocationLine.setLocationMode(Constant.angleLocationMode);
  63. }
  64. /******************************************************************************************************************************************************/
  65. //设置综合定位法
  66. setAll() {}
  67. /******************************************************************************************************************************************************/
  68. isFocusBasePoint() {
  69. if (Settings.selectBasePointId) {
  70. let point = dataService.getPoint(Settings.selectBasePointId);
  71. if (point.getCategory() == VectorCategory.Point.BasePoint) {
  72. return point;
  73. }
  74. }
  75. return null;
  76. }
  77. }
  78. const locationModeControl = new LocationModeControl();
  79. export { locationModeControl };