|
@@ -1,16 +1,21 @@
|
|
|
import Point from "../Geometry/Point.js";
|
|
|
import Line from "../Geometry/Line.js";
|
|
|
+import Road from "../Geometry/Road.js";
|
|
|
+import Edge from "../Geometry/Edge.js";
|
|
|
+import MeasureLine from "../Geometry/MeasureLine.js";
|
|
|
import ElementEvents from "../enum/ElementEvents.js";
|
|
|
import { listenLayer } from "../ListenLayer";
|
|
|
import Constant from "../Constant";
|
|
|
import { dataService } from "./DataService.js";
|
|
|
import { mathUtil } from "../Util/MathUtil";
|
|
|
import { coordinate } from "../Coordinate.js";
|
|
|
-import { roadService } from "./RoadService.js";
|
|
|
+import { edgeService } from "./EdgeService.js";
|
|
|
|
|
|
export class ElementService {
|
|
|
constructor() {
|
|
|
- this.addingRoadPoint = null;
|
|
|
+ this.point = null;
|
|
|
+
|
|
|
+ this.newMeasureLine = null;
|
|
|
this.newRoad = null;
|
|
|
|
|
|
this.checkLines = {
|
|
@@ -26,12 +31,15 @@ export class ElementService {
|
|
|
}
|
|
|
|
|
|
init() {
|
|
|
- this.addingRoadPoint = new Point(0, 0);
|
|
|
- this.addingRoadPoint.name = ElementEvents.AddingRoadPoint;
|
|
|
+ this.point = new Point(0, 0);
|
|
|
+ this.point.name = ElementEvents.AddingPoint;
|
|
|
|
|
|
- this.newRoad = new Line({ x: 0, y: 0 }, { x: 1, y: 1 });
|
|
|
+ this.newRoad = this.createTempRoad();
|
|
|
this.newRoad.name = ElementEvents.NewRoad;
|
|
|
|
|
|
+ this.newMeasureLine = new MeasureLine({ x: 0, y: 0 }, { x: 1, y: 1 });
|
|
|
+ this.newMeasureLine.name = ElementEvents.NewMeasureLine;
|
|
|
+
|
|
|
this.checkLines.X = new Line({ x: 0, y: 0 }, { x: 1, y: 1 });
|
|
|
this.checkLines.X.name = ElementEvents.CheckLinesX;
|
|
|
|
|
@@ -47,16 +55,54 @@ export class ElementService {
|
|
|
this.hideAll();
|
|
|
}
|
|
|
|
|
|
- showStartAddRoad() {
|
|
|
- this.addingRoadPoint.display = true;
|
|
|
+ createTempRoad() {
|
|
|
+ let p1 = new Point({ x: 0, y: 0 });
|
|
|
+ let p2 = new Point({ x: 1, y: 1 });
|
|
|
+ this.newRoad = new Road(p1.vectorId, p2.vectorId);
|
|
|
+ this.newRoad.start = p1;
|
|
|
+ this.newRoad.end = p2;
|
|
|
+
|
|
|
+ let edgePoints = mathUtil.RectangleVertex(
|
|
|
+ p1,
|
|
|
+ p2,
|
|
|
+ Constant.defaultRoadWidth
|
|
|
+ );
|
|
|
+
|
|
|
+ let leftEdge = new Edge(
|
|
|
+ edgePoints.leftEdgeStart,
|
|
|
+ edgePoints.leftEdgeEnd,
|
|
|
+ null,
|
|
|
+ this.newRoad.vectorId
|
|
|
+ );
|
|
|
+
|
|
|
+ let rightEdge = new Edge(
|
|
|
+ edgePoints.rightEdgeStart,
|
|
|
+ edgePoints.rightEdgeEnd,
|
|
|
+ null,
|
|
|
+ this.newRoad.vectorId
|
|
|
+ );
|
|
|
+
|
|
|
+ this.newRoad.setLeftEdge(leftEdge.vectorId);
|
|
|
+ this.newRoad.setRightEdge(rightEdge.vectorId);
|
|
|
+ leftEdge.setEdgeParent(this.newRoad.vectorId);
|
|
|
+ rightEdge.setEdgeParent(this.newRoad.vectorId);
|
|
|
+ this.newRoad.leftEdge = leftEdge;
|
|
|
+ this.newRoad.rightEdge = rightEdge;
|
|
|
+
|
|
|
+ this.hideNewRoad();
|
|
|
+ return this.newRoad;
|
|
|
+ }
|
|
|
+
|
|
|
+ showPoint() {
|
|
|
+ this.point.display = true;
|
|
|
}
|
|
|
|
|
|
- hideStartAddRoad() {
|
|
|
- this.addingRoadPoint.display = false;
|
|
|
+ hidePoint() {
|
|
|
+ this.point.display = false;
|
|
|
}
|
|
|
|
|
|
- setAddingRoadPoint(position) {
|
|
|
- this.addingRoadPoint.setPosition(position);
|
|
|
+ setPoint(position) {
|
|
|
+ this.point.setPosition(position);
|
|
|
}
|
|
|
|
|
|
showNewRoad() {
|
|
@@ -68,17 +114,24 @@ export class ElementService {
|
|
|
}
|
|
|
|
|
|
setNewRoad(point1, point2) {
|
|
|
- this.newRoad.setPositions(point1, point2);
|
|
|
- }
|
|
|
-
|
|
|
- setNewRoadStartPosition(startPosition) {
|
|
|
- this.newRoad.start.x = startPosition.x;
|
|
|
- this.newRoad.start.y = startPosition.y;
|
|
|
- }
|
|
|
-
|
|
|
- setNewRoadEndPosition(endPosition) {
|
|
|
- this.newRoad.end.x = endPosition.x;
|
|
|
- this.newRoad.end.y = endPosition.y;
|
|
|
+ this.newRoad.start.setPosition(point1);
|
|
|
+ this.newRoad.end.setPosition(point2);
|
|
|
+ //需要更新Edge坐标
|
|
|
+ if (!mathUtil.equalPoint(point1, point2)) {
|
|
|
+ let edgePoints = mathUtil.RectangleVertex(
|
|
|
+ point1,
|
|
|
+ point2,
|
|
|
+ Constant.defaultRoadWidth
|
|
|
+ );
|
|
|
+ this.newRoad.leftEdge.setPositions(
|
|
|
+ edgePoints.leftEdgeStart,
|
|
|
+ edgePoints.leftEdgeEnd
|
|
|
+ );
|
|
|
+ this.newRoad.rightEdge.setPositions(
|
|
|
+ edgePoints.rightEdgeStart,
|
|
|
+ edgePoints.rightEdgeEnd
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
setNewRoadState(state) {
|
|
@@ -137,11 +190,20 @@ export class ElementService {
|
|
|
this.vCheckLines.Y.setPositions(point1, point2);
|
|
|
}
|
|
|
|
|
|
+ showNewMeasureLine() {
|
|
|
+ this.newMeasureLine.display = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ hideNewMeasureLine() {
|
|
|
+ this.newMeasureLine.display = false;
|
|
|
+ }
|
|
|
+
|
|
|
hideAll() {
|
|
|
this.hideCheckLinesX();
|
|
|
this.hideCheckLinesY();
|
|
|
- this.hideStartAddRoad();
|
|
|
+ this.hidePoint();
|
|
|
this.hideNewRoad();
|
|
|
+ this.hideNewMeasureLine();
|
|
|
this.hideVCheckLinesX();
|
|
|
this.hideVCheckLinesY();
|
|
|
}
|
|
@@ -207,41 +269,41 @@ export class ElementService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //pointId是角度的顶点
|
|
|
- //exceptPointId表示position对应的pointId(如果有的话)
|
|
|
- checkAngle(position, pointId, exceptPointId) {
|
|
|
- //type:1表示90°,2表示180°
|
|
|
- function ajust(position, point1, point2, type) {
|
|
|
- let line = mathUtil.createLine1(point1, point2);
|
|
|
- let join = null;
|
|
|
- if (type == 1) {
|
|
|
- let vLine = mathUtil.getVerticalLine(line, point1);
|
|
|
- join = mathUtil.getJoinLinePoint(position, vLine);
|
|
|
- } else if (type == 2) {
|
|
|
- join = mathUtil.getJoinLinePoint(position, line);
|
|
|
- }
|
|
|
- return join;
|
|
|
- }
|
|
|
-
|
|
|
- let points = roadService.getNeighPoints(pointId, exceptPointId);
|
|
|
- let point = dataService.getPoint(pointId);
|
|
|
- let newPosition = null;
|
|
|
- for (let i = 0; i < points.length; ++i) {
|
|
|
- let angle = mathUtil.Angle(point, position, points[i]);
|
|
|
- if (Math.abs((angle / Math.PI) * 180 - 90) < 5) {
|
|
|
- newPosition = ajust(position, point, points[i], 1);
|
|
|
- } else if (
|
|
|
- Math.abs((angle / Math.PI) * 180) < 5 ||
|
|
|
- Math.abs((angle / Math.PI) * 180 - 180) < 5
|
|
|
- ) {
|
|
|
- newPosition = ajust(position, point, points[i], 2);
|
|
|
- }
|
|
|
- if (newPosition != null) {
|
|
|
- return newPosition;
|
|
|
- }
|
|
|
- }
|
|
|
- return newPosition;
|
|
|
- }
|
|
|
+ // //pointId是角度的顶点
|
|
|
+ // //exceptPointId表示position对应的pointId(如果有的话)
|
|
|
+ // checkAngle(position, pointId, exceptPointId) {
|
|
|
+ // //type:1表示90°,2表示180°
|
|
|
+ // function ajust(position, point1, point2, type) {
|
|
|
+ // let line = mathUtil.createLine1(point1, point2);
|
|
|
+ // let join = null;
|
|
|
+ // if (type == 1) {
|
|
|
+ // let vLine = mathUtil.getVerticalLine(line, point1);
|
|
|
+ // join = mathUtil.getJoinLinePoint(position, vLine);
|
|
|
+ // } else if (type == 2) {
|
|
|
+ // join = mathUtil.getJoinLinePoint(position, line);
|
|
|
+ // }
|
|
|
+ // return join;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let points = roadService.getNeighPoints(pointId, exceptPointId);
|
|
|
+ // let point = dataService.getPoint(pointId);
|
|
|
+ // let newPosition = null;
|
|
|
+ // for (let i = 0; i < points.length; ++i) {
|
|
|
+ // let angle = mathUtil.Angle(point, position, points[i]);
|
|
|
+ // if (Math.abs((angle / Math.PI) * 180 - 90) < 5) {
|
|
|
+ // newPosition = ajust(position, point, points[i], 1);
|
|
|
+ // } else if (
|
|
|
+ // Math.abs((angle / Math.PI) * 180) < 5 ||
|
|
|
+ // Math.abs((angle / Math.PI) * 180 - 180) < 5
|
|
|
+ // ) {
|
|
|
+ // newPosition = ajust(position, point, points[i], 2);
|
|
|
+ // }
|
|
|
+ // if (newPosition != null) {
|
|
|
+ // return newPosition;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return newPosition;
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
const elementService = new ElementService();
|