| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import VectorType from "../enum/VectorType.js";
- import Geometry from "./Geometry.js";
- import Settings from "../Settings";
- import Constant from "../Constant";
- import { mathUtil } from "../Util/MathUtil.js";
- import { coordinate } from "../Coordinate.js";
- import { dataService } from "../Service/DataService.js";
- export default class Road extends Geometry {
- constructor(startId, endId, vectorId) {
- super();
- this.startId = startId;
- this.endId = endId;
- this.leftEdgeId = null;
- this.rightEdgeId = null;
- this.leftLanes = []; //二维数组。第一维表示第几个车道,第二维是一组点
- this.rightLanes = [];
- this.singleLanes = []; //单向车道
- this.roadWidthTipsPos = []; //车道提示位置
- //道路中间隔离栏 ,起点和终点与startId和endId方向一致。但是坐标有区别。因为隔离栏要比start-end短一些
- //单向车道没有中间栏
- this.midDivide = {
- leftMidDivide: {},
- rightMidDivide: {},
- midDivideWidth: Settings.roadMidDivideWidth * window.coordinate.ratio,
- };
- this.leftDrivewayCount = Settings.roadLeftDrivewayCount; //左边的车道个数
- this.rightDrivewayCount = Settings.roadRightDrivewayCount; //右边的车道个数
- this.geoType = VectorType.Road;
- this.leftWidth = Settings.roadLeftDrivewayCount * Settings.singleLaneWidth * window.coordinate.ratio;
- this.rightWidth = Settings.roadRightDrivewayCount * Settings.singleLaneWidth * window.coordinate.ratio;
- this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
- this.singleRoadWidth = Settings.singleRoadDrivewayCount * Settings.singleLaneWidth * window.coordinate.ratio;
- this.way = Settings.wayType;
- this.setId(vectorId);
- }
- setMidDivide(midDivideData) {
- this.midDivide = JSON.parse(JSON.stringify(midDivideData));
- }
- setLeftEdgeId(value) {
- this.leftEdgeId = value;
- }
- setRightEdgeId(value) {
- this.rightEdgeId = value;
- }
- setWidth(value, dir) {
- if (this.way == Constant.twoWay) {
- if (dir == "left") {
- this.leftWidth = value;
- } else if (dir == "right") {
- this.rightWidth = value;
- }
- } else if (this.way == Constant.oneWay) {
- this.singleRoadWidth = value;
- }
- }
- getOtherPointId(pointId) {
- if (this.startId == pointId) {
- return this.endId;
- } else if (this.endId == pointId) {
- return this.startId;
- } else {
- return null;
- }
- }
- getPointId(dir) {
- if (dir == "start") {
- return this.startId;
- } else {
- 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;
- }
- }
- setWay(value) {
- this.way = value;
- }
- getLanesCount(dir) {
- if (this.way == Constant.oneWay) {
- return this.singleRoadDrivewayCount;
- } else if (this.way == Constant.twoWay) {
- if (dir == "left") {
- return this.leftDrivewayCount;
- } else {
- return this.rightDrivewayCount;
- }
- }
- }
- setLeftLanes(leftLanes) {
- this.leftLanes = JSON.parse(JSON.stringify(leftLanes));
- }
- setRightLanes(rightLanes) {
- this.rightLanes = JSON.parse(JSON.stringify(rightLanes));
- }
- setSingleLanes(singleLanes) {
- this.singleLanes = JSON.parse(JSON.stringify(singleLanes));
- }
- }
|