import Text from "../Geometry/Text.js"; import { dataService } from "./DataService.js"; import { mathUtil } from "../Util/MathUtil.js"; import Settings from "../Settings"; import { coordinate } from "../Coordinate.js"; import UIEvents from "../enum/UIEvents.js"; import VectorCategory from "../enum/VectorCategory.js"; import Constant from "../Constant.js"; import VectorStyle from "../enum/VectorStyle.js"; import VectorWeight from "../enum/VectorWeight.js"; import RoadTemplate from "../enum/RoadTemplate.js"; import RoadStructure from "../enum/RoadStructure.js"; import Message from "@/components/base/components/message/message.vue"; export default class UIService { constructor() {} isBelongRoad(ui) { if (ui == UIEvents.OneEdgeOneLanRoad) { this.setWayType(Constant.oneWay); this.setSingleRoadDrivewayCount(1); this.setSingleRoadWidth(Settings.singleLaneWidth); return true; } else if (ui == UIEvents.OneEdgeTwoLanRoad) { this.setWayType(Constant.oneWay); this.setSingleRoadDrivewayCount(2); this.setSingleRoadWidth(Settings.singleLaneWidth * 2); return true; } else if (ui == UIEvents.OneEdgeThreeLanRoad) { this.setWayType(Constant.oneWay); this.setSingleRoadDrivewayCount(3); this.setSingleRoadWidth(Settings.singleLaneWidth * 3); return true; } else if (ui == UIEvents.TwoEdgeOneLanRoad) { this.setWayType(Constant.twoWay); this.setRoadLeftDrivewayCount(1); this.setRoadRightDrivewayCount(1); this.setLeftRoadWidth(Settings.singleLaneWidth); this.setRightRoadWidth(Settings.singleLaneWidth); return true; } else if (ui == UIEvents.TwoEdgeTwoLanRoad) { this.setWayType(Constant.twoWay); this.setRoadLeftDrivewayCount(2); this.setRoadRightDrivewayCount(2); this.setLeftRoadWidth(Settings.singleLaneWidth * 2); this.setRightRoadWidth(Settings.singleLaneWidth * 2); return true; } else if (ui == UIEvents.TwoEdgeThreeLanRoad) { this.setWayType(Constant.twoWay); this.setRoadLeftDrivewayCount(3); this.setRoadRightDrivewayCount(3); this.setLeftRoadWidth(Settings.singleLaneWidth * 3); this.setRightRoadWidth(Settings.singleLaneWidth * 3); return true; } return false; } isBelongCurveRoad(ui) { if (ui == "SBend") { this.setRoadLeftDrivewayCount(0); this.setRoadRightDrivewayCount(0); return true; } else if (ui == UIEvents.OneEdgeOneLanRoad) { this.setRoadLeftDrivewayCount(0); this.setRoadRightDrivewayCount(0); return true; } } isBelongLine(ui) { if (ui == UIEvents.SingleArrow) { this.setSelectLineCategory(VectorCategory.Line.SingleArrowLine); return true; } else if (ui == UIEvents.DoubleArrow) { this.setSelectLineCategory(VectorCategory.Line.DoubleArrowLine); return true; } else if (ui == UIEvents.MeasureLine) { this.setSelectLineCategory(VectorCategory.Line.MeasureLine); return true; } else if (ui == UIEvents.Line) { this.setSelectLineCategory(VectorCategory.Line.NormalLine); return true; } else if (ui == UIEvents.FreeMeasureLine) { this.setSelectLineCategory(VectorCategory.Line.FreeMeasureLine); return true; } else if (ui == UIEvents.BaseLine) { this.setSelectLineCategory(VectorCategory.Line.BaseLine); return true; } return false; } isBelongPoint(ui) { if (ui == UIEvents.BasePoint) { this.setSelectPointCategory(VectorCategory.Point.BasePoint); return true; } else if (ui == UIEvents.FixPoint) { this.setSelectPointCategory(VectorCategory.Point.FixPoint); return true; } return false; } isBelongRoadEdgeStyle(ui) { if (ui == VectorStyle.SingleSolidLine) { return true; } else if (ui == VectorStyle.SingleDashedLine) { return true; } else if (ui == VectorStyle.DoubleSolidLine) { return true; } else if (ui == VectorStyle.DoubleDashedLine) { return true; } else if (ui == VectorStyle.BrokenLine) { return true; } else if (ui == VectorStyle.PointDrawLine) { return true; } else if (ui == VectorStyle.Greenbelt) { return true; } else if (ui == VectorWeight.Bold) { return true; } else if (ui == VectorWeight.Thinning) { return true; } else { return false; } } isBelongRoadTemplate(ui) { if (RoadTemplate[ui]) { this.setSelectRoadTemplate(ui); return true; } else { return false; } } isBelongRoadStructure(ui) { if (RoadStructure[ui]) { this.setSelectRoadStructure(ui); return true; } else { return false; } } setWayType(value) { Settings.wayType = value; } setSelectBasePointId(value) { Settings.selectBasePointId = value; } setSingleRoadDrivewayCount(value) { Settings.singleRoadDrivewayCount = value; } setRoadLeftDrivewayCount(value) { Settings.roadLeftDrivewayCount = value; } setRoadRightDrivewayCount(value) { Settings.roadRightDrivewayCount = value; } setCurveRoadLeftDrivewayCount(value) { Settings.curveRoadLeftDrivewayCount = value; } setCurveRoadRightDrivewayCount(value) { Settings.curveRoadRightDrivewayCount = value; } setSingleRoadWidth(value) { Settings.singleRoadWidth = value; } setLeftRoadWidth(value) { Settings.leftRoadWidth = value; } setRightRoadWidth(value) { Settings.rightRoadWidth = value; } setCurveRoadLeftDrivewayCount(value) { Settings.curveRoadLeftDrivewayCount = value; } setCurveRoadRightDrivewayCount(value) { Settings.curveRoadRightDrivewayCount = value; } setLeftCurveRoadWidth(value) { Settings.leftCurveRoadWidth = value; } setRightCurveRoadWidth(value) { Settings.rightCurveRoadWidth = value; } setSelectLineCategory(value) { Settings.selectLineCategory = value; } setSelectPointCategory(value) { Settings.selectPointCategory = value; } //设置定位法 setSelectLocationMode(value) { Settings.selectLocationMode = value; } getSelectLocationMode() { return Settings.selectLocationMode; } setSelectSVGType(value) { Settings.selectSVGType = value; } getSelectRoadTemplate() { return Settings.selectRoadTemplate; } setSelectRoadTemplate(value) { Settings.selectRoadTemplate = value; } setSelectRoadStructure(value) { Settings.selectRoadStructure = value; } getSelectRoadStructure() { return Settings.selectRoadStructure; } //Constant.defaultMidDivideWidth是真实宽度,现在赋值的时候要转换成像素 setRoadMidDivideWidth(value) { Settings.roadMidDivideWidth = value; } //Constant.defaultMidDivideWidth是真实宽度,现在赋值的时候要转换成像素 setCurveRoadMidDivideWidth(value) { Settings.curveRoadMidDivideWidth = value; } //Constant.defaultSingleLaneWidth是真实宽度,现在赋值的时候要转换成像素 setSingleLaneWidth(value) { Settings.singleLaneWidth = value; } getSingleLaneWidth() { return Settings.singleLaneWidth; } getRoadMidDivideWidth() { return Settings.roadMidDivideWidth; } getLineWidth() { return Settings.lineWidth; } setLineWidth(value) { Settings.lineWidth = value; } //如果position在屏幕左上角,返回的就朝向右下角,如果是右下角,则返回的是左上角。其他情况以此类推 getNewPositionForPop(position) { const offset = 50; const center = coordinate.getXYFromScreen({ x: coordinate.width / 2, y: coordinate.height / 2, }); let newPosition = {}; mathUtil.clonePoint(newPosition, position); if (position.x > center.x) { newPosition.x -= offset; } else if (position.x < center.x) { newPosition.x += offset; } if (position.y > center.y) { newPosition.y -= offset; } else if (position.y < center.y) { newPosition.y += offset; } return newPosition; } currentShowMsgs = []; prompt(msg) { const config = typeof msg === "string" ? { msg, time: 1000 } : msg; if (this.currentShowMsgs.includes(config.msg)) { return; } this.currentShowMsgs.push(config.msg); setTimeout(() => { this.currentShowMsgs = this.currentShowMsgs.filter( (msg) => msg !== config.msg ); }, config.time); Message.success(config); } } const uiService = new UIService(); export { uiService };