import VectorType from "../enum/VectorType.js"; import Geometry from "./Geometry.js"; import Settings from "../Settings"; import Constant from "../Constant"; 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 = []; //单向车道 //道路中间隔离栏 ,起点和终点与startId和endId方向一致。但是坐标有区别。因为隔离栏要比start-end短一些 //单向车道没有中间栏 this.midDivide = { leftMidDivide: {}, rightMidDivide: {}, midDivideWidth: Settings.roadMidDivideWidth, }; this.leftDrivewayCount = Settings.roadLeftDrivewayCount; //左边的车道个数 this.rightDrivewayCount = Settings.roadRightDrivewayCount; //右边的车道个数 this.geoType = VectorType.Road; this.leftWidth = Settings.leftRoadWidth; this.rightWidth = Settings.rightRoadWidth; this.singleRoadWidth = Settings.singleRoadWidth; this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount; this.way = Settings.wayType; this.setId(vectorId); } 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; } } } }