浏览代码

继续绘图

xushiting 2 年之前
父节点
当前提交
bca2411d44

+ 0 - 7
src/graphic/Geometry/CurveRoad.js

@@ -6,15 +6,8 @@ import Constant from "../Constant";
 export default class CurveRoad extends Road {
   constructor(startId, endId, vectorId) {
     super(startId, endId, vectorId);
-    this.startId = startId;
-    this.endId = endId;
     this.points = []; //中心线上一系列控制点。数组是从start到end。
-    this.leftEdgeId = null;
-    this.rightEdgeId = null;
-    this.leftLanes = []; //二维数组。第一维表示第几个车道,第二维是一组点
-    this.rightLanes = [];
     this.width = Constant.defaultRoadWidth; //默认宽度
-
     this.leftDrivewayCount = 2; //左边的车道个数
     this.rightDrivewayCount = 2; //右边的车道个数
     this.geoType = VectorType.CurveRoad;

+ 25 - 2
src/graphic/Geometry/Road.js

@@ -9,11 +9,12 @@ export default class Road extends Geometry {
     this.endId = endId;
     this.leftEdgeId = null;
     this.rightEdgeId = null;
-    this.width = Constant.defaultRoadWidth; //默认宽度
-
+    this.leftLanes = []; //二维数组。第一维表示第几个车道,第二维是一组点
+    this.rightLanes = [];
     this.leftDrivewayCount = 1; //左边的车道个数
     this.rightDrivewayCount = 1; //右边的车道个数
     this.geoType = VectorType.Road;
+    this.width = Constant.defaultRoadWidth; //默认宽度
     this.setId(vectorId);
   }
 
@@ -34,4 +35,26 @@ export default class Road extends Geometry {
       return this.endId;
     }
   }
+
+  addLeftDrivewayCount() {
+    ++this.leftDrivewayCount;
+  }
+
+  subtractLeftDrivewayCount() {
+    --this.leftDrivewayCount;
+    if (this.leftDrivewayCount < 0) {
+      this.leftDrivewayCount = 0;
+    }
+  }
+
+  addRightDrivewayCount() {
+    ++this.rightDrivewayCount;
+  }
+
+  subtractRightDrivewayCount() {
+    ++this.rightDrivewayCount;
+    if (this.rightDrivewayCount < 0) {
+      this.rightDrivewayCount = 0;
+    }
+  }
 }

+ 44 - 2
src/graphic/Layer.js

@@ -524,7 +524,7 @@ export default class Layer {
         this.history.save();
       }
       //加宽
-      if (e.code == "KeyA") {
+      else if (e.code == "KeyA") {
         const road = dataService.getRoad(focusItem.vectorId);
         road.width += 100;
         edgeService.updateEdgeForMovePoint(road.startId);
@@ -533,7 +533,49 @@ export default class Layer {
         this.history.save();
       }
       //变窄
-      if (e.code == "KeyB") {
+      else if (e.code == "KeyB") {
+        const road = dataService.getRoad(focusItem.vectorId);
+        road.width -= 50;
+        edgeService.updateEdgeForMovePoint(road.startId);
+        edgeService.updateEdgeForMovePoint(road.endId);
+        this.renderer.autoRedraw();
+        this.history.save();
+      }
+      //添加左车道
+      else if (e.code == "KeyQ") {
+        let road = null;
+        if (focusItem.type == VectorType.Road) {
+          road = dataService.getRoad(focusItem.vectorId);
+        } else if (focusItem.type == VectorType.CurveRoad) {
+          road = dataService.getCurveRoad(focusItem.vectorId);
+        }
+
+        if (road) {
+          sd;
+          this.renderer.autoRedraw();
+          this.history.save();
+        }
+      }
+      //减少左车道
+      else if (e.code == "KeyW") {
+        const road = dataService.getRoad(focusItem.vectorId);
+        road.width -= 50;
+        edgeService.updateEdgeForMovePoint(road.startId);
+        edgeService.updateEdgeForMovePoint(road.endId);
+        this.renderer.autoRedraw();
+        this.history.save();
+      }
+      //添加右车道
+      else if (e.code == "KeyE") {
+        const road = dataService.getRoad(focusItem.vectorId);
+        road.width -= 50;
+        edgeService.updateEdgeForMovePoint(road.startId);
+        edgeService.updateEdgeForMovePoint(road.endId);
+        this.renderer.autoRedraw();
+        this.history.save();
+      }
+      //减少右车道
+      else if (e.code == "KeyR") {
         const road = dataService.getRoad(focusItem.vectorId);
         road.width -= 50;
         edgeService.updateEdgeForMovePoint(road.startId);

+ 1 - 1
src/graphic/Renderer/Render.js

@@ -13,7 +13,7 @@ export default class Render {
 
   //绘制户型
   drawGeometry(vector, styleType, flag) {
-    if (draw.context == null) {
+    if (draw.context == null || vector == null) {
       return;
     }
     //console.log(vector)

+ 7 - 2
src/graphic/Service/CurveRoadService.js

@@ -4,9 +4,12 @@ import { curveEdgeService } from "./CurveEdgeService";
 import { mathUtil } from "../Util/MathUtil.js";
 import CurveRoad from "../Geometry/CurveRoad.js";
 import VectorType from "../enum/VectorType";
+import RoadService from "./RoadService";
 
-export default class CurveRoadService {
-  constructor() {}
+export default class CurveRoadService extends RoadService {
+  constructor() {
+    super();
+  }
 
   create(startId, endId, vectorId) {
     let curveRoad = new CurveRoad(startId, endId, vectorId);
@@ -268,6 +271,8 @@ export default class CurveRoadService {
     };
   }
 
+  setLeftLanes(road, leftCount) {}
+
   updateForMovePoint(pointId, position) {
     let curvePoint = dataService.getCurvePoint(pointId);
     let curveRoadId = curvePoint.getParent();