| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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";
- 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.Arrow) {
- this.setLineCategory(VectorCategory.Line.ArrowLine);
- return true;
- } else if (ui == UIEvents.MeasureLine) {
- this.setLineCategory(VectorCategory.Line.MeasureLine);
- return true;
- } else if (ui == UIEvents.Line) {
- this.setLineCategory(VectorCategory.Line.NormalLine);
- return true;
- } else if (ui == UIEvents.BaseLine) {
- this.setLineCategory(VectorCategory.Line.BaseLine);
- return true;
- }
- return false;
- }
- isBelongPoint(ui) {
- if (ui == UIEvents.NormalLocationMode) {
- this.setPointCategory(VectorCategory.Point.TestPoint);
- this.setLocationMode(Constant.normalLocationMode);
- return true;
- } else if (ui == UIEvents.AngleLocationMode) {
- this.setPointCategory(VectorCategory.Point.TestPoint);
- this.setLocationMode(Constant.angleLocationMode);
- return true;
- } else if (ui == UIEvents.AllLocationMode) {
- this.setPointCategory(VectorCategory.Point.TestPoint);
- this.setLocationMode(Constant.allLocationMode);
- return true;
- } else if (ui == UIEvents.BasePoint) {
- this.setPointCategory(VectorCategory.Point.BasePoint);
- this.setLocationMode(null);
- return true;
- }
- return false;
- }
- setWayType(value) {
- Settings.wayType = 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;
- }
- setLineCategory(value) {
- Settings.lineCategory = value;
- }
- setPointCategory(value) {
- Settings.pointCategory = value;
- }
- //设置定位法
- setLocationMode(value) {
- Settings.locationMode = 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;
- }
- }
- const uiService = new UIService();
- export { uiService };
|