xushiting 2 anni fa
parent
commit
38281dc0f5

+ 75 - 52
src/graphic/Controls/UIControl.js

@@ -1,38 +1,38 @@
-import { coordinate } from '../Coordinate.js';
-import LayerEvents from '../enum/LayerEvents.js';
-import UIEvents from '../enum/UIEvents.js';
-import RoadTemplate from '../enum/RoadTemplate.js';
-import RoadStructure from '../enum/RoadStructure.js';
-import VectorType from '../enum/VectorType.js';
-import VectorStyle from '../enum/VectorStyle.js';
-import VectorWeight from '../enum/VectorWeight.js';
-import GeoActions from '../enum/GeoActions.js';
-import VectorEvents from '../enum/VectorEvents.js';
-import SVGType from '../enum/SVGType.js';
-import { stateService } from '../Service/StateService.js';
-import { uiService } from '../Service/UIService.js';
-import { dataService } from '../Service/DataService.js';
-import { historyService } from '../Service/HistoryService.js';
-import { elementService } from '../Service/ElementService';
-import { lineService } from '../Service/LineService.js';
-import { circleService } from '../Service/CircleService.js';
-import { textService } from '../Service/TextService.js';
-import { svgService } from '../Service/SVGService.js';
-import { magnifierService } from '../Service/MagnifierService.js';
-import { mathUtil } from '../Util/MathUtil';
-import Constant from '../Constant';
+import { coordinate } from "../Coordinate.js";
+import LayerEvents from "../enum/LayerEvents.js";
+import UIEvents from "../enum/UIEvents.js";
+import RoadTemplate from "../enum/RoadTemplate.js";
+import RoadStructure from "../enum/RoadStructure.js";
+import VectorType from "../enum/VectorType.js";
+import VectorStyle from "../enum/VectorStyle.js";
+import VectorWeight from "../enum/VectorWeight.js";
+import GeoActions from "../enum/GeoActions.js";
+import VectorEvents from "../enum/VectorEvents.js";
+import SVGType from "../enum/SVGType.js";
+import { stateService } from "../Service/StateService.js";
+import { uiService } from "../Service/UIService.js";
+import { dataService } from "../Service/DataService.js";
+import { historyService } from "../Service/HistoryService.js";
+import { elementService } from "../Service/ElementService";
+import { lineService } from "../Service/LineService.js";
+import { circleService } from "../Service/CircleService.js";
+import { textService } from "../Service/TextService.js";
+import { svgService } from "../Service/SVGService.js";
+import { magnifierService } from "../Service/MagnifierService.js";
+import { mathUtil } from "../Util/MathUtil";
+import Constant from "../Constant";
 // import { roomsUtil } from "../Room/RoomsUtil.js";
-import { addRoad } from '../Controls/AddRoad';
-import { addLine } from './AddLine.js';
-import VectorCategory from '../enum/VectorCategory.js';
+import { addRoad } from "../Controls/AddRoad";
+import { addLine } from "./AddLine.js";
+import VectorCategory from "../enum/VectorCategory.js";
 // import { floorplanData } from "../VectorData.js";
-import Message from '@/components/base/components/message/message.vue';
-import { pointService } from '../Service/PointService.js';
-import Settings from '../Settings.js';
-import { addPoint } from './AddPoint.js';
-import { curveRoadPointService } from '../Service/CurveRoadPointService.js';
-import { roadService } from '../Service/RoadService.js';
-import { curveRoadService } from '../Service/CurveRoadService.js';
+import Message from "@/components/base/components/message/message.vue";
+import { pointService } from "../Service/PointService.js";
+import Settings from "../Settings.js";
+import { addPoint } from "./AddPoint.js";
+import { curveRoadPointService } from "../Service/CurveRoadPointService.js";
+import { roadService } from "../Service/RoadService.js";
+import { curveRoadService } from "../Service/CurveRoadService.js";
 
 export default class UIControl {
   constructor(layer, newsletter, graphicStateUI) {
@@ -88,15 +88,17 @@ export default class UIControl {
         }
 
         //执行新的事件
-        if (uiService.isBelongRoad(selectUI) || selectUI == 'road') {
+        if (uiService.isBelongRoad(selectUI) || selectUI == "road") {
           stateService.setEventName(LayerEvents.AddRoad);
         } else if (selectUI == UIEvents.CurveRoad) {
           stateService.setEventName(LayerEvents.AddCurveRoad);
         } else if (uiService.isBelongLine(selectUI)) {
           stateService.setEventName(LayerEvents.AddLine);
-        } else if (selectUI == UIEvents.CurveLine) {
-          stateService.setEventName(LayerEvents.AddCurveLine);
-        } else if (uiService.isBelongPoint(selectUI)) {
+        }
+        //  else if (selectUI == UIEvents.CurveLine) {
+        //   stateService.setEventName(LayerEvents.AddCurveLine);
+        // }
+        else if (uiService.isBelongPoint(selectUI)) {
           stateService.setEventName(LayerEvents.AddPoint);
         } else if (selectUI == UIEvents.Circle) {
           stateService.setEventName(LayerEvents.AddCircle);
@@ -119,7 +121,7 @@ export default class UIControl {
   }
 
   updateVectorForSelectUI(selectUI) {
-    console.log('selectUI', selectUI);
+    console.log("selectUI", selectUI);
     const focusItem = stateService.getFocusItem();
 
     // if (selectUI == VectorStyle.Bold || selectUI == VectorStyle.Thinning) {
@@ -142,9 +144,9 @@ export default class UIControl {
     if (uiService.isBelongRoadEdgeStyle(selectUI)) {
       let key = null;
       if (VectorStyle[selectUI]) {
-        key = 'setStyle';
+        key = "setStyle";
       } else if (VectorWeight[selectUI]) {
-        key = 'setWeight';
+        key = "setWeight";
       }
 
       if (focusItem.type == VectorType.Line) {
@@ -430,18 +432,18 @@ export default class UIControl {
   }
 
   getCadBlob(canvas) {
-    var type = 'jpg';
+    var type = "jpg";
     return new Promise((resolve) => canvas.toBlob(resolve, `${type}/image`));
   }
 
   downloadCadImg(canvas, filename) {
     // 图片导出为 jpg 格式
-    var type = 'jpg';
+    var type = "jpg";
     var imgData = canvas.toDataURL(type, 3);
     canvas.toBlob(`${type}/image`);
 
     // 加工image data,替换mime type
-    imgData = imgData.replace(this._fixType(type), 'image/octet-stream');
+    imgData = imgData.replace(this._fixType(type), "image/octet-stream");
     // 下载后的图片名
     //var filename = 'cad_' + new Date().getTime() + '.' + type
     // download
@@ -449,19 +451,38 @@ export default class UIControl {
   }
 
   saveFile(data, filename) {
-    var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
+    var save_link = document.createElementNS(
+      "http://www.w3.org/1999/xhtml",
+      "a"
+    );
     save_link.href = data;
     save_link.download = filename;
 
-    var event = document.createEvent('MouseEvents');
-    event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+    var event = document.createEvent("MouseEvents");
+    event.initMouseEvent(
+      "click",
+      true,
+      false,
+      window,
+      0,
+      0,
+      0,
+      0,
+      0,
+      false,
+      false,
+      false,
+      false,
+      0,
+      null
+    );
     save_link.dispatchEvent(event);
   }
 
   _fixType(type) {
-    type = type.toLowerCase().replace(/jpg/i, 'jpeg');
+    type = type.toLowerCase().replace(/jpg/i, "jpeg");
     var r = type.match(/png|jpeg|bmp|gif/)[0];
-    return 'image/' + r;
+    return "image/" + r;
   }
   /****************************************************************************针对菜单*******************************************************************************/
 
@@ -520,7 +541,9 @@ export default class UIControl {
   /******************************************************************************************************************************************************************/
 
   prompt(msg) {
-    this._prompts.push(Message.success(typeof msg === 'string' ? { msg } : msg));
+    this._prompts.push(
+      Message.success(typeof msg === "string" ? { msg } : msg)
+    );
   }
 
   // 进入持续添加出确认与取消框
@@ -528,7 +551,7 @@ export default class UIControl {
     this.graphicStateUI.continuedMode = true;
   }
   confirmEntry() {
-    console.log('确认');
+    console.log("确认");
     Settings.selectLocationMode = null;
     this.graphicStateUI.continuedMode = false;
     this.layer.exit();
@@ -539,7 +562,7 @@ export default class UIControl {
     this.layer.renderer.autoRedraw();
   }
   confirmCancel() {
-    console.log('取消');
+    console.log("取消");
     Settings.selectLocationMode = null;
     this.graphicStateUI.continuedMode = false;
     addPoint.deleteTestPoints();
@@ -553,7 +576,7 @@ export default class UIControl {
 
   // 设置默认设置
   setDefaultSetting(setting) {
-    console.log('获得设置', setting);
+    console.log("获得设置", setting);
 
     uiService.setRoadMidDivideWidth(
       // (setting.roadQuarantineWidth / coordinate.res) * coordinate.ratio

+ 16 - 0
src/graphic/History/HistoryUtil.js

@@ -173,6 +173,22 @@ export default class HistoryUtil {
           road1.leftDrivewayCount == road2.leftDrivewayCount &&
           road1.rightDrivewayCount == road2.rightDrivewayCount &&
           road1.midDivide.midDivideWidth == road2.midDivide.midDivideWidth &&
+          mathUtil.clonePoint(
+            road1.midDivide.leftMidDivide.start,
+            road2.midDivide.leftMidDivide.start
+          ) &&
+          mathUtil.clonePoint(
+            road1.midDivide.leftMidDivide.end,
+            road2.midDivide.leftMidDivide.end
+          ) &&
+          mathUtil.clonePoint(
+            road1.midDivide.rightMidDivide.start,
+            road2.midDivide.rightMidDivide.start
+          ) &&
+          mathUtil.clonePoint(
+            road1.midDivide.rightMidDivide.end,
+            road2.midDivide.rightMidDivide.end
+          ) &&
           road1.leftLanes.length == road2.leftLanes.length &&
           road1.rightLanes.length == road2.rightLanes.length
         ) {

+ 41 - 35
src/graphic/Layer.js

@@ -42,6 +42,7 @@ import Constant from "./Constant";
 import { uiService } from "./Service/UIService";
 import { imageService } from "./Service/ImageService";
 import VectorEvents from "./enum/VectorEvents";
+import { lineService } from "./Service/LineService";
 
 const minDragDis = 10;
 const minZoom = 20;
@@ -145,10 +146,10 @@ export default class Layer {
         stateService.setEventName(LayerEvents.AddingLine);
         addLine.setNewLinePoint(position);
         break;
-      case LayerEvents.AddCurveLine:
-        stateService.setEventName(LayerEvents.AddingCurveLine);
-        addLine.setNewLinePoint(position);
-        break;
+      // case LayerEvents.AddCurveLine:
+      //   stateService.setEventName(LayerEvents.AddingCurveLine);
+      //   addLine.setNewLinePoint(position);
+      //   break;
       case LayerEvents.AddPoint:
         stateService.setEventName(LayerEvents.MovePoint);
         const newPoint = addPoint.buildPoint(position);
@@ -161,10 +162,10 @@ export default class Layer {
           this.history.save();
           this.renderer.autoRedraw();
         } else {
-          if(Settings.basePointIds.length>1){
-            this.uiControl.prompt({ msg: '请先选择基准点', time: 1000 });
-          }else{
-            this.uiControl.prompt({ msg: '请先添加基准点', time: 1000 });
+          if (Settings.basePointIds.length > 1) {
+            this.uiControl.prompt({ msg: "请先选择基准点", time: 1000 });
+          } else {
+            this.uiControl.prompt({ msg: "请先添加基准点", time: 1000 });
           }
 
           // this.uiControl.prompt({ msg: '请先选择基准点', time: 1000 });
@@ -284,37 +285,42 @@ export default class Layer {
         break;
       case VectorEvents.AddCrossPoint:
         if (focusItem && focusItem.vectorId) {
-          const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
-          let index = mathUtil.getIndexForCurvesPoints(
-            position,
-            curveRoad.points
-          );
-          if (index != -1) {
-            curveRoadService.addCPoint(curveRoad, position, index);
-          } else {
-            const dis1 = mathUtil.getDistance(curveRoad.points[0], position);
-            const dis2 = mathUtil.getDistance(
-              curveRoad.points[curveRoad.points.length - 1],
-              position
+          if (focusItem.type == VectorType.CurveRoad) {
+            const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
+            let index = mathUtil.getIndexForCurvesPoints(
+              position,
+              curveRoad.points
             );
-            if (dis1 > dis2) {
-              index = curveRoad.points.length - 2;
-              // curveRoadService.addCPoint(
-              //   curveRoad,
-              //   position,
-              //   curveRoad.points.length - 2
-              // );
+            if (index != -1) {
+              curveRoadService.addCPoint(curveRoad, position, index);
             } else {
-              //curveRoadService.addCPoint(curveRoad, position, 1);
-              index = 1;
+              const dis1 = mathUtil.getDistance(curveRoad.points[0], position);
+              const dis2 = mathUtil.getDistance(
+                curveRoad.points[curveRoad.points.length - 1],
+                position
+              );
+              if (dis1 > dis2) {
+                index = curveRoad.points.length - 2;
+              } else {
+                index = 1;
+              }
+              curveRoadService.addCPoint(curveRoad, position, index);
             }
-            curveRoadService.addCPoint(curveRoad, position, index);
+            curveRoadService.updateForMovePoint(
+              curveRoad.points[index + 1].vectorId,
+              position
+            );
+          } else if (focusItem.type == VectorType.Line) {
+            let line = dataService.getLine(focusItem.vectorId);
+            let startPoint = dataService.getPoint(line.startId);
+            let endPoint = dataService.getPoint(line.endId);
+            dataService.deleteLine(focusItem.vectorId);
+            let curveLine = lineService.createCurveLine(startPoint, endPoint);
+            mathUtil.clonePoint(curveLine.points[1], position);
+            curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
+          } else if (focusItem.type == VectorType.CurveLine) {
           }
-          //curveRoadService.setLanes(curveRoad.vectorId);
-          curveRoadService.updateForMovePoint(
-            curveRoad.points[index + 1].vectorId,
-            position
-          );
+
           stateService.clearEventName();
           this.history.save();
           this.renderer.autoRedraw();

+ 3 - 1
src/graphic/Service/LineService.js

@@ -107,12 +107,14 @@ export default class LineService {
     );
 
     startPoint.setPointParent(curveLine.vectorId, "start");
+    startPoint.setIndex(0);
     endPoint.setPointParent(curveLine.vectorId, "end");
+    endPoint.setIndex(2);
     let midPoint = curvePointService.create({
       x: (startPoint.x + endPoint.x) / 2,
       y: (startPoint.y + endPoint.y) / 2,
     });
-
+    midPoint.setIndex(1);
     curveLine.points = [];
     curveLine.points.push(startPoint);
     curveLine.points.push(midPoint);