import { mathUtil } from "./Util/MathUtil"; import { dataService } from "./Service/DataService.js"; import { stateService } from "./Service/StateService.js"; import { roadService } from "./Service/RoadService.js"; import Constant from "./Constant.js"; import VectorType from "./enum/VectorType.js"; import SelectState from "./enum/SelectState.js"; import bezierUtil from "./Util/bezierUtil.js"; import { elementService } from "./Service/ElementService"; import { coordinate } from "./Coordinate"; import { draw } from "./Renderer/Draw.js"; import { edgeService } from "./Service/EdgeService"; export default class ListenLayer { constructor() { this.modifyPoint = null; } //开始监听,exceptVectorIds表示不考虑的元素 /** * * @param exceptVectorIds:{ exceptPointId, exceptLineId, exceptRoadPointId, exceptRoadIds, exceptCurveRoadPointId, exceptCurveRoadId, exceptCrossCrossPointId, exceptTextId, } * @returns */ start(position, exceptVectorIds) { let flag = false; let selectInfo = {}; if (!exceptVectorIds) { exceptVectorIds = {}; } this.clear(); selectInfo.curveRoadEdgeInfo = this.isSelectCurveRoad( position, exceptVectorIds.exceptCurveRoadId ); //包括edge selectInfo.roadEdgeInfo = this.isSelectRoad( position, exceptVectorIds.exceptRoadIds ); //包括edge selectInfo.curveRoadPointInfo = this.isSelectCurveRoadPoint( position, exceptVectorIds.exceptCurveRoadPointId ); selectInfo.roadPointInfo = this.isSelectRoadPoint( position, exceptVectorIds.exceptRoadPointId ); selectInfo.pointInfo = this.isSelectPoint( position, exceptVectorIds.exceptPointId ); selectInfo.lineInfo = this.isSelectLine( position, exceptVectorIds.exceptLineId ); selectInfo.curveLineInfo = {}; selectInfo.curvePointInfo = {}; selectInfo.circleInfo = this.isSelectCircle( position, exceptVectorIds.exceptCircleId ); //交叉口拐弯处的控制点 selectInfo.crossPointInfo = this.isSelectCrossCrossPoint( position, exceptVectorIds.exceptCrossCrossPointId ); selectInfo.textInfo = this.isSelectText( position, exceptVectorIds.exceptTextId ); selectInfo.magnifierInfo = this.isSelectMagnifier( position, exceptVectorIds.exceptMagnifierId ); this.setModifyPoint(position, selectInfo); flag = this.updateSelectItem(); return flag; } isSelectPoint(position, exceptPointId) { let pointInfo = { pointId: null, type: null, distance: null, }; let seqInfo = {}; const points = dataService.getPoints(); for (const pointId in points) { if (pointId == exceptPointId) { continue; } const point = dataService.getPoint(pointId); const distance = mathUtil.getDistance(position, point); if (distance < Constant.minAdsorbPix) { if (pointInfo.pointId == null) { pointInfo = { pointId: pointId, type: VectorType.Point, distance: distance, }; } else { if (distance < pointInfo.distance) { pointInfo = { pointId: pointId, type: VectorType.Point, distance: distance, }; } } } else { if (Math.abs(position.x - point.x) < Constant.minAdsorbPix) { seqInfo.linkedPointIdX = pointId; seqInfo.x = point.x; } else if (Math.abs(position.y - point.y) < Constant.minAdsorbPix) { seqInfo.linkedPointIdY = pointId; seqInfo.y = point.y; } } } if (pointInfo.pointId) { pointInfo.linkedPointId = pointInfo.pointId; const linkedPoint = dataService.getPoint(pointInfo.pointId); pointInfo.x = linkedPoint.x; pointInfo.y = linkedPoint.y; } else { if (seqInfo.hasOwnProperty("linkedPointIdX")) { pointInfo.linkedPointIdX = seqInfo.linkedPointIdX; pointInfo.x = seqInfo.x; } else if (seqInfo.hasOwnProperty("linkedPointIdY")) { pointInfo.linkedPointIdY = seqInfo.linkedPointIdY; pointInfo.y = seqInfo.y; } if (pointInfo.hasOwnProperty("y") && !pointInfo.hasOwnProperty("x")) { pointInfo.x = position.x; } if (pointInfo.hasOwnProperty("x") && !pointInfo.hasOwnProperty("y")) { pointInfo.y = position.y; } } return pointInfo; } isSelectLine(position, exceptLineIds) { let lineInfo = { lineId: null, type: null, distance: null, }; const lines = dataService.getLines(); for (const lineId in lines) { if (exceptLineIds && exceptLineIds.hasOwnProperty(lineId)) { continue; } const line = dataService.getLine(lineId); let startPoint = dataService.getPoint(line.startId); let endPoint = dataService.getPoint(line.endId); const comLine = mathUtil.createLine1(startPoint, endPoint); const join = mathUtil.getJoinLinePoint(position, comLine); const distance = mathUtil.getDistance(position, join); if (!mathUtil.isContainForSegment(join, startPoint, endPoint)) { continue; } if (distance < Constant.minAdsorbPix / 2) { lineInfo = { lineId: lineId, type: VectorType.Line, distance: distance, }; } } if (lineInfo.lineId) { const linkedLine = dataService.getLine(lineInfo.lineId); let startPoint = dataService.getPoint(linkedLine.startId); let endPoint = dataService.getPoint(linkedLine.endId); const linkedComLine = mathUtil.createLine1(startPoint, endPoint); const linkedPosition = mathUtil.getJoinLinePoint(position, linkedComLine); lineInfo.x = linkedPosition.x; lineInfo.y = linkedPosition.y; return lineInfo; } return lineInfo; } isSelectCircle(position, exceptCircleId) { let circleInfo = { circleId: null, type: null, distance: null, }; const circles = dataService.getCircles(); let distance; for (const circleId in circles) { if (circleId == exceptCircleId) { continue; } const circle = dataService.getCircle(circleId); for (let i = 0; i < circle.points.length; ++i) { distance = mathUtil.getDistance(position, circle.points[i]); if (distance < Constant.minAdsorbPix) { circleInfo = { circleId: circleId, type: VectorType.Circle, distance: distance, x: circle.points[i].x, y: circle.points[i].y, index: i, }; return circleInfo; } } distance = mathUtil.getDistance(position, circle.center); if (distance < circle.radius) { if (circleInfo.circleId == null || distance < circleInfo.distance) { circleInfo = { circleId: circleId, type: VectorType.Circle, distance: distance, x: circle.center.x, y: circle.center.y, index: -1, }; } } } return circleInfo; } // isSelectCurveLine(position, exceptCurveLineId) { // let curveLineInfo = { // curveLineId: null, // type: null, // distance: null, // }; // let seqInfo = {}; // const curveLines = dataService.getCurveLines(); // for (const curveLineId in curveLines) { // if (curveLineId == exceptCurveLineId) { // continue; // } // const curveLine = dataService.getCurveLine(curveLineId); // let joinInfo = this.distanceForBezier( // position, // curveRoad.curves, // Constant.minAdsorbPix / 2 // ); // if ( // mathUtil.isClockwise([curveRoad.points[0], joinInfo.position, position]) // ) { // //选中了路 // if (joinInfo.distance < curveRoad.leftWidth - Constant.minAdsorbPix) { // curveRoadInfo = { // curveRoadId: curveRoadId, // type: VectorType.CurveRoad, // distance: joinInfo.distance, // x: joinInfo.position.x, // y: joinInfo.position.y, // }; // } // //选中了edge // else if ( // joinInfo.distance < // curveRoad.leftWidth + Constant.minAdsorbPix // ) { // const leftCurveEdge = dataService.getCurveRoadEdge( // curveRoad.leftEdgeId // ); // joinInfo = this.distanceForBezier( // position, // leftCurveEdge.curves, // curveRoad.leftWidth // ); // const index = mathUtil.getIndexForCurvesPoints( // joinInfo.position, // curveRoad.points // ); // curveEdgeInfo = { // curveEdgeId: curveRoad.leftEdgeId, // type: VectorType.CurveRoadEdge, // distance: joinInfo.distance, // selectIndex: index, // x: joinInfo.position.x, // y: joinInfo.position.y, // }; // } // } else if ( // !mathUtil.isClockwise([ // curveRoad.points[0], // joinInfo.position, // position, // ]) // ) { // //选中了路 // if (joinInfo.distance < curveRoad.rightWidth - Constant.minAdsorbPix) { // curveRoadInfo = { // curveRoadId: curveRoadId, // type: VectorType.CurveRoad, // distance: joinInfo.distance, // x: joinInfo.position.x, // y: joinInfo.position.y, // }; // } // //选中了edge // else if ( // joinInfo.distance < // curveRoad.rightWidth + Constant.minAdsorbPix // ) { // const rightCurveEdge = dataService.getCurveRoadEdge( // curveRoad.rightEdgeId // ); // joinInfo = this.distanceForBezier( // position, // rightCurveEdge.curves, // curveRoad.rightWidth // ); // const index = mathUtil.getIndexForCurvesPoints( // joinInfo.position, // curveRoad.points // ); // curveEdgeInfo = { // curveEdgeId: curveRoad.rightEdgeId, // type: VectorType.CurveRoadEdge, // distance: joinInfo.distance, // selectIndex: index, // x: joinInfo.position.x, // y: joinInfo.position.y, // }; // } // } // } // if (curveRoadInfo.curveRoadId) { // return curveRoadInfo; // } else if (curveEdgeInfo.curveEdgeId) { // return curveEdgeInfo; // } else { // return { // curveRoadId: null, // curveEdgeId: null, // }; // } // } isSelectRoadPoint(position, exceptRoadPointId) { let roadPointInfo = { roadPointId: null, type: null, distance: null, }; let seqInfo = {}; const roadPoints = dataService.getRoadPoints(); for (const roadPointId in roadPoints) { if (roadPointId == exceptRoadPointId) { continue; } const roadPoint = dataService.getRoadPoint(roadPointId); const distance = mathUtil.getDistance(position, roadPoint); if (distance < Constant.minAdsorbPix) { if (roadPointInfo.roadPointId == null) { roadPointInfo = { roadPointId: roadPointId, type: VectorType.RoadPoint, distance: distance, }; } else if (roadPointInfo.roadPointId != null) { if (distance < roadPointInfo.distance) { roadPointInfo = { roadPointId: roadPointId, type: VectorType.RoadPoint, distance: distance, }; } } } else { if (Math.abs(position.x - roadPoint.x) < Constant.minAdsorbPix) { seqInfo.linkedRoadPointIdX = roadPointId; seqInfo.x = roadPoint.x; } else if (Math.abs(position.y - roadPoint.y) < Constant.minAdsorbPix) { seqInfo.linkedRoadPointIdY = roadPointId; seqInfo.y = roadPoint.y; } } } if (roadPointInfo.roadPointId) { const linkedPoint = dataService.getRoadPoint(roadPointInfo.roadPointId); roadPointInfo.x = linkedPoint.x; roadPointInfo.y = linkedPoint.y; } //因为这种纠正的权限最低 else { if (seqInfo.hasOwnProperty("linkedRoadPointIdX")) { roadPointInfo.linkedRoadPointIdX = seqInfo.linkedRoadPointIdX; roadPointInfo.x = seqInfo.x; } if (seqInfo.hasOwnProperty("linkedRoadPointIdY")) { roadPointInfo.linkedRoadPointIdY = seqInfo.linkedRoadPointIdY; roadPointInfo.y = seqInfo.y; } if ( roadPointInfo.hasOwnProperty("y") && !roadPointInfo.hasOwnProperty("x") ) { roadPointInfo.x = position.x; } if ( roadPointInfo.hasOwnProperty("x") && !roadPointInfo.hasOwnProperty("y") ) { roadPointInfo.y = position.y; } } return roadPointInfo; } isSelectCurveRoadPoint(position, exceptCurveRoadPointId) { let curveRoadPointInfo = { curveRoadPointId: null, type: null, distance: null, }; let seqInfo = {}; const curveRoadPoints = dataService.getCurveRoadPoints(); for (const curveRoadPointId in curveRoadPoints) { if (curveRoadPointId == exceptCurveRoadPointId) { continue; } const curveRoadPoint = dataService.getCurveRoadPoint(curveRoadPointId); const distance = mathUtil.getDistance(position, curveRoadPoint); if (distance < Constant.minAdsorbPix) { if (curveRoadPointInfo.curveRoadPointId == null) { curveRoadPointInfo = { curveRoadPointId: curveRoadPointId, type: VectorType.CurveRoadPoint, distance: distance, }; } else { if (distance < curveRoadPointInfo.distance) { curveRoadPointInfo = { curveRoadPointId: curveRoadPointId, type: VectorType.CurveRoadPoint, distance: distance, }; } } } else { if (Math.abs(position.x - curveRoadPoint.x) < Constant.minAdsorbPix) { seqInfo.linkedCurveRoadPointIdX = curveRoadPointId; seqInfo.x = curveRoadPoint.x; } else if ( Math.abs(position.y - curveRoadPoint.y) < Constant.minAdsorbPix ) { seqInfo.linkedCurveRoadPointIdY = curveRoadPointId; seqInfo.y = curveRoadPoint.y; } } } if (curveRoadPointInfo.curveRoadPointId) { curveRoadPointInfo.linkedCurveRoadPointId = curveRoadPointInfo.curveRoadPointId; const linkedCurvePoint = dataService.getCurveRoadPoint( curveRoadPointInfo.curveRoadPointId ); curveRoadPointInfo.x = linkedCurvePoint.x; curveRoadPointInfo.y = linkedCurvePoint.y; } else { if (seqInfo.hasOwnProperty("linkedCurveRoadPointIdX")) { curveRoadPointInfo.linkedCurveRoadPointIdX = seqInfo.linkedCurveRoadPointIdX; curveRoadPointInfo.x = seqInfo.x; } else if (seqInfo.hasOwnProperty("linkedCurveRoadPointIdY")) { curveRoadPointInfo.linkedCurveRoadPointIdY = seqInfo.linkedCurveRoadPointIdY; curveRoadPointInfo.y = seqInfo.y; } if ( curveRoadPointInfo.hasOwnProperty("y") && !curveRoadPointInfo.hasOwnProperty("x") ) { curveRoadPointInfo.x = position.x; } if ( curveRoadPointInfo.hasOwnProperty("x") && !curveRoadPointInfo.hasOwnProperty("y") ) { curveRoadPointInfo.y = position.y; } } return curveRoadPointInfo; } isSelectRoad(position, exceptRoadIds) { let roadInfo = { roadId: null, type: null, distance: null, }; let edgeInfo = { edgeId: null, type: null, distance: null, dir: null, }; const roads = dataService.getRoads(); for (const roadId in roads) { if (exceptRoadIds != null && exceptRoadIds.hasOwnProperty(roadId)) { continue; } const road = dataService.getRoad(roadId); let startPoint = dataService.getRoadPoint(road.startId); let endPoint = dataService.getRoadPoint(road.endId); const leftEdge = dataService.getRoadEdge(road.leftEdgeId); const rightEdge = dataService.getRoadEdge(road.rightEdgeId); const roadLine = roadService.getMidLine(road); let join = mathUtil.getJoinLinePoint(position, roadLine); let distance = mathUtil.getDistance(position, join); if ( mathUtil.isContainForSegment(join, startPoint, endPoint) && distance < Constant.minAdsorbPix ) { if (!roadInfo.roadId || distance < roadInfo.distance) { roadInfo = { roadId: roadId, type: VectorType.Road, distance: distance, }; } } //检查edge let leftLine = mathUtil.createLine1(leftEdge.start, leftEdge.end); join = mathUtil.getJoinLinePoint(position, leftLine); distance = mathUtil.getDistance(position, join); if ( mathUtil.isContainForSegment(join, leftEdge.start, leftEdge.end) && distance < Constant.minAdsorbPix ) { if (!edgeInfo.edgeId || distance < edgeInfo.distance) { edgeInfo = { edgeId: road.leftEdgeId, type: VectorType.RoadEdge, distance: distance, dir: "left", }; } } let rightLine = mathUtil.createLine1(rightEdge.start, rightEdge.end); join = mathUtil.getJoinLinePoint(position, rightLine); distance = mathUtil.getDistance(position, join); if ( mathUtil.isContainForSegment(join, rightEdge.start, rightEdge.end) && distance < Constant.minAdsorbPix ) { if (!edgeInfo.edgeId || distance < edgeInfo.distance) { edgeInfo = { edgeId: road.rightEdgeId, type: VectorType.RoadEdge, distance: distance, dir: "right", }; } } } if ( roadInfo.roadId && (!edgeInfo.edgeId || roadInfo.distance < edgeInfo.distance) ) { const linkedRoad = dataService.getRoad(roadInfo.roadId); const linkedRoadLine = roadService.getMidLine(linkedRoad); const linkedPosition = mathUtil.getJoinLinePoint( position, linkedRoadLine ); roadInfo.x = linkedPosition.x; roadInfo.y = linkedPosition.y; return roadInfo; } else if (edgeInfo.edgeId) { if (edgeInfo.dir == "left") { const leftEdge = dataService.getRoadEdge(edgeInfo.edgeId); const leftLine = edgeService.getLine(leftEdge); const linkedPosition = mathUtil.getJoinLinePoint(position, leftLine); edgeInfo.x = linkedPosition.x; edgeInfo.y = linkedPosition.y; } else { const rightEdge = dataService.getRoadEdge(edgeInfo.edgeId); const rightLine = edgeService.getLine(rightEdge); const linkedPosition = mathUtil.getJoinLinePoint(position, rightLine); edgeInfo.x = linkedPosition.x; edgeInfo.y = linkedPosition.y; } return edgeInfo; } return { roadId: null, edgeId: null, }; } isSelectCurveRoad(position, exceptCurveRoadId) { let curveRoadInfo = { curveRoadId: null, type: null, distance: null, }; let curveEdgeInfo = { curveEdgeId: null, type: null, distance: null, }; const curveRoads = dataService.getCurveRoads(); for (const curveRoadId in curveRoads) { if (curveRoadId == exceptCurveRoadId) { continue; } const curveRoad = dataService.getCurveRoad(curveRoadId); let joinInfo = this.distanceForBezier( position, curveRoad.curves, Constant.minAdsorbPix ); //选中了路 if (joinInfo.distance < Constant.minAdsorbPix) { curveRoadInfo = { curveRoadId: curveRoadId, type: VectorType.CurveRoad, distance: joinInfo.distance, x: joinInfo.position.x, y: joinInfo.position.y, }; } //检查edge else { const leftCurveEdge = dataService.getCurveRoadEdge( curveRoad.leftEdgeId ); joinInfo = this.distanceForBezier( position, leftCurveEdge.curves, Constant.minAdsorbPix ); if (joinInfo.distance < Constant.minAdsorbPix) { const index = mathUtil.getIndexForCurvesPoints( joinInfo.position, curveRoad.points ); curveEdgeInfo = { curveEdgeId: curveRoad.leftEdgeId, type: VectorType.CurveRoadEdge, distance: joinInfo.distance, selectIndex: index, x: joinInfo.position.x, y: joinInfo.position.y, }; } else { const rightCurveEdge = dataService.getCurveRoadEdge( curveRoad.rightEdgeId ); joinInfo = this.distanceForBezier( position, rightCurveEdge.curves, Constant.minAdsorbPix ); if (joinInfo.distance < Constant.minAdsorbPix) { const index = mathUtil.getIndexForCurvesPoints( joinInfo.position, curveRoad.points ); curveEdgeInfo = { curveEdgeId: curveRoad.rightEdgeId, type: VectorType.CurveRoadEdge, distance: joinInfo.distance, selectIndex: index, x: joinInfo.position.x, y: joinInfo.position.y, }; } } } } if (curveRoadInfo.curveRoadId) { return curveRoadInfo; } else if (curveEdgeInfo.curveEdgeId) { return curveEdgeInfo; } else { return { curveRoadId: null, curveEdgeId: null, }; } } isSelectCrossCrossPoint(position, exceptCrossCrossPointId) { let crossCrossPointInfo = { crossCrossPointId: null, type: null, distance: null, }; const crossPoints = dataService.getCrossPoints(); for (const crossPointId in crossPoints) { if (crossPointId == exceptCrossCrossPointId) { continue; } const crossPoint = dataService.getCrossPoint2(crossPointId); const distance = mathUtil.getDistance(position, crossPoint.extremePoint); if (distance < Constant.minAdsorbPix) { crossCrossPointInfo = { crossCrossPointId: crossPointId, type: VectorType.CrossPoint, distance: distance, x: crossPoint.extremePoint.x, y: crossPoint.extremePoint.y, }; } } return crossCrossPointInfo; } isSelectText(position, exceptTextId) { let textInfo = { textId: null, type: null, distance: null, }; const texts = dataService.getTexts(); for (const textId in texts) { if (textId == exceptTextId) { continue; } const text = dataService.getText(textId); const distance = mathUtil.getDistance(position, text.center); if (distance < Constant.minAdsorbPix) { textInfo = { textId: textId, type: VectorType.Text, distance: distance, x: text.center.x, y: text.center.y, }; } } return textInfo; } isSelectMagnifier(position, exceptMagnifierId) { let magnifierInfo = { magnifierId: null, type: null, distance: null, }; const magnifiers = dataService.getMagnifiers(); for (const magnifierId in magnifiers) { if (magnifierId == exceptMagnifierId) { continue; } const magnifier = dataService.getMagnifier(magnifierId); const distance = mathUtil.getDistance(position, magnifier.position); if (distance < Constant.minAdsorbPix) { magnifierInfo = { magnifierId: magnifierId, type: VectorType.Magnifier, distance: distance, x: magnifier.position.x, y: magnifier.position.y, }; } } return magnifierInfo; } /** * * @param info:{ roadPointInfo, curveRoadPointInfo, roadEdgeInfo, curveRoadEdgeInfo, crossPointInfo, pointInfo, roadPointInfo } */ setModifyPoint(position, info) { //优先级最高 if ( info && (info.roadPointInfo.roadPointId || info.curveRoadPointInfo.curveRoadPointId) ) { this.modifyPoint = {}; if ( info.roadPointInfo.roadPointId && info.curveRoadPointInfo.curveRoadPointId ) { if (info.roadPointInfo.distance < info.curveRoadPointInfo.distance) { this.modifyPoint.linkedRoadPointId = info.roadPointInfo.roadPointId; this.modifyPoint.x = info.roadPointInfo.x; this.modifyPoint.y = info.roadPointInfo.y; } else { this.modifyPoint.linkedCurveRoadPointId = info.curveRoadPointInfo.curveRoadPointId; this.modifyPoint.x = info.curveRoadPointInfo.x; this.modifyPoint.y = info.curveRoadPointInfo.y; } } else if (info.roadPointInfo.roadPointId) { this.modifyPoint.linkedRoadPointId = info.roadPointInfo.roadPointId; this.modifyPoint.x = info.roadPointInfo.x; this.modifyPoint.y = info.roadPointInfo.y; } else if (info.curveRoadPointInfo.curveRoadPointId) { this.modifyPoint.linkedCurveRoadPointId = info.curveRoadPointInfo.curveRoadPointId; this.modifyPoint.x = info.curveRoadPointInfo.x; this.modifyPoint.y = info.curveRoadPointInfo.y; } } else if ( info && (info.pointInfo.pointId || info.curvePointInfo.curvePointId) ) { this.modifyPoint = {}; if (info.pointInfo.pointId && info.curvePointInfo.curvePointId) { if (info.pointInfo.distance < info.curvePointInfo.distance) { this.modifyPoint.linkedPointId = info.pointInfo.pointId; this.modifyPoint.x = info.pointInfo.x; this.modifyPoint.y = info.pointInfo.y; } else { this.modifyPoint.linkedCurvePointId = info.curvePointInfo.curvePointId; this.modifyPoint.x = info.curvePointInfo.x; this.modifyPoint.y = info.curvePointInfo.y; } } else if (info.pointInfo.pointId) { this.modifyPoint.linkedPointId = info.pointInfo.pointId; this.modifyPoint.x = info.pointInfo.x; this.modifyPoint.y = info.pointInfo.y; } else if (info.curvePointInfo.curvePointId) { this.modifyPoint.linkedCurvePointId = info.curvePointInfo.curvePointId; this.modifyPoint.x = info.curvePointInfo.x; this.modifyPoint.y = info.curvePointInfo.y; } } else if ( info && (info.roadEdgeInfo.roadId || info.curveRoadEdgeInfo.curveRoadId) ) { this.modifyPoint = {}; if (info.roadEdgeInfo.roadId && info.curveRoadEdgeInfo.curveRoadId) { if (roadEdgeInfo.distance < info.curveRoadEdgeInfo.distance) { this.modifyPoint.linkedRoadId = info.roadEdgeInfo.roadId; this.modifyPoint.x = info.roadEdgeInfo.x; this.modifyPoint.y = info.roadEdgeInfo.y; } else { this.modifyPoint.linkedCurveRoadId = curveRoadEdgeInfo.curveRoadId; this.modifyPoint.x = info.curveRoadEdgeInfo.x; this.modifyPoint.y = info.curveRoadEdgeInfo.y; } } else if (info.roadEdgeInfo.roadId) { this.modifyPoint.linkedRoadId = info.roadEdgeInfo.roadId; this.modifyPoint.x = info.roadEdgeInfo.x; this.modifyPoint.y = info.roadEdgeInfo.y; } else if (info.curveRoadEdgeInfo.curveRoadId) { this.modifyPoint.linkedCurveRoadId = info.curveRoadEdgeInfo.curveRoadId; this.modifyPoint.x = info.curveRoadEdgeInfo.x; this.modifyPoint.y = info.curveRoadEdgeInfo.y; } } else if (info && info.crossPointInfo.crossCrossPointId) { this.modifyPoint = {}; this.modifyPoint.linkedCrossCrossPointId = info.crossPointInfo.crossCrossPointId; this.modifyPoint.x = info.crossPointInfo.x; this.modifyPoint.y = info.crossPointInfo.y; } else if (info && info.textInfo.textId) { this.modifyPoint = {}; this.modifyPoint.textId = info.textInfo.textId; this.modifyPoint.x = info.textInfo.x; this.modifyPoint.y = info.textInfo.y; } else if (info && info.magnifierInfo.magnifierId) { this.modifyPoint = {}; this.modifyPoint.magnifierId = info.magnifierInfo.magnifierId; this.modifyPoint.x = info.magnifierInfo.x; this.modifyPoint.y = info.magnifierInfo.y; } else if ( info && (info.roadEdgeInfo.edgeId || info.curveRoadEdgeInfo.curveEdgeId) ) { this.modifyPoint = {}; if (info.roadEdgeInfo.edgeId && info.curveRoadEdgeInfo.curveEdgeId) { if (info.roadEdgeInfo.distance < info.curveRoadEdgeInfo.distance) { this.modifyPoint.linkedEdgeId = info.roadEdgeInfo.edgeId; this.modifyPoint.x = info.roadEdgeInfo.x; this.modifyPoint.y = info.roadEdgeInfo.y; } else { this.modifyPoint.linkedCurveEdgeId = info.curveRoadEdgeInfo.curveEdgeId; this.modifyPoint.selectIndex = info.curveRoadEdgeInfo.selectIndex; this.modifyPoint.x = info.curveRoadEdgeInfo.x; this.modifyPoint.y = info.curveRoadEdgeInfo.y; } } else if (info.roadEdgeInfo.edgeId) { this.modifyPoint.linkedEdgeId = info.roadEdgeInfo.edgeId; this.modifyPoint.x = info.roadEdgeInfo.x; this.modifyPoint.y = info.roadEdgeInfo.y; } else if (info.curveRoadEdgeInfo.curveEdgeId) { this.modifyPoint.linkedCurveEdgeId = info.curveRoadEdgeInfo.curveEdgeId; this.modifyPoint.selectIndex = info.curveRoadEdgeInfo.selectIndex; this.modifyPoint.x = info.curveRoadEdgeInfo.x; this.modifyPoint.y = info.curveRoadEdgeInfo.y; } } else if ( info && (info.lineInfo.lineId || info.curveLineInfo.curveLineId) ) { this.modifyPoint = {}; if (info.lineInfo.lineId && info.curveLineInfo.curveLineId) { if (info.lineInfo.distance < info.curveLineInfo.distance) { this.modifyPoint.linkedLineId = info.lineInfo.lineId; this.modifyPoint.x = info.lineInfo.x; this.modifyPoint.y = info.lineInfo.y; } else { this.modifyPoint.linkedCurveLineId = info.curveLineInfo.curveLineId; this.modifyPoint.x = info.curveLineInfo.x; this.modifyPoint.y = info.curveLineInfo.y; } } else if (info.lineInfo.lineId) { this.modifyPoint.linkedLineId = info.lineInfo.lineId; this.modifyPoint.x = info.lineInfo.x; this.modifyPoint.y = info.lineInfo.y; } else if (info.curveLineInfo.curveLineId) { this.modifyPoint.linkedCurveLineId = info.curveLineInfo.curveLineId; this.modifyPoint.x = info.curveLineInfo.x; this.modifyPoint.y = info.curveLineInfo.y; } } else if (info && info.circleInfo.circleId) { this.modifyPoint = {}; this.modifyPoint.linkedCircleId = info.circleInfo.circleId; this.modifyPoint.index = info.circleInfo.index; this.modifyPoint.x = info.circleInfo.x; this.modifyPoint.y = info.circleInfo.y; } else if (info && info.roadPointInfo.linkedRoadPointIdX) { this.modifyPoint = {}; this.modifyPoint.linkedRoadPointIdX = info.roadPointInfo.linkedRoadPointIdX; this.modifyPoint.x = info.roadPointInfo.x; this.modifyPoint.y = info.roadPointInfo.y; } else if (info && info.roadPointInfo.linkedRoadPointIdY) { this.modifyPoint = {}; this.modifyPoint.linkedRoadPointIdY = info.roadPointInfo.linkedRoadPointIdY; this.modifyPoint.y = info.roadPointInfo.y; this.modifyPoint.x = info.roadPointInfo.x; } else if (info && info.curvePointInfo.linkedRoadPointIdX) { this.modifyPoint = {}; this.modifyPoint.linkedRoadPointIdX = info.curvePointInfo.linkedRoadPointIdX; this.modifyPoint.x = info.curvePointInfo.x; this.modifyPoint.y = position.y; } else if (info && info.curvePointInfo.linkedRoadPointIdY) { this.modifyPoint = {}; this.modifyPoint.linkedRoadPointIdY = info.curvePointInfo.linkedRoadPointIdY; this.modifyPoint.y = info.curvePointInfo.y; this.modifyPoint.x = position.x; } else if (info && info.pointInfo.linkedPointIdX) { this.modifyPoint = {}; this.modifyPoint.linkedPointIdX = info.pointInfo.linkedPointIdX; this.modifyPoint.x = info.pointInfo.x; this.modifyPoint.y = info.pointInfo.y; } else if (info && info.pointInfo.linkedPointIdY) { this.modifyPoint = {}; this.modifyPoint.linkedPointIdY = info.pointInfo.linkedPointIdY; this.modifyPoint.y = info.pointInfo.y; this.modifyPoint.x = info.pointInfo.x; } else { this.modifyPoint = null; } } updateSelectItem() { let selectItem = stateService.getSelectItem(); if (this.modifyPoint == null) { if (selectItem != null) { stateService.clearSelectItem(); return true; } else { return false; } } else if (this.modifyPoint.linkedRoadPointId) { stateService.setSelectItem( this.modifyPoint.linkedRoadPointId, VectorType.RoadPoint, SelectState.Select ); } else if (this.modifyPoint.linkedCurveRoadPointId) { stateService.setSelectItem( this.modifyPoint.linkedCurveRoadPointId, VectorType.CurveRoadPoint, SelectState.Select ); } else if (this.modifyPoint.linkedRoadId) { stateService.setSelectItem( this.modifyPoint.linkedRoadId, VectorType.Road, SelectState.Select ); } else if (this.modifyPoint.linkedCurveRoadId) { stateService.setSelectItem( this.modifyPoint.linkedCurveRoadId, VectorType.CurveRoad, SelectState.Select ); } else if (this.modifyPoint.linkedCrossCrossPointId) { stateService.setSelectItem( this.modifyPoint.linkedCrossCrossPointId, VectorType.CrossPoint, SelectState.Select ); } else if (this.modifyPoint.textId) { stateService.setSelectItem( this.modifyPoint.textId, VectorType.Text, SelectState.Select ); } else if (this.modifyPoint.magnifierId) { stateService.setSelectItem( this.modifyPoint.magnifierId, VectorType.Magnifier, SelectState.Select ); } else if (this.modifyPoint.linkedEdgeId) { stateService.setSelectItem( this.modifyPoint.linkedEdgeId, VectorType.RoadEdge, SelectState.Select ); } else if (this.modifyPoint.linkedCurveEdgeId) { stateService.setSelectItem( this.modifyPoint.linkedCurveEdgeId, VectorType.CurveRoadEdge, SelectState.Select ); } else if (this.modifyPoint.linkedPointId) { stateService.setSelectItem( this.modifyPoint.linkedPointId, VectorType.Point, SelectState.Select ); } else if (this.modifyPoint.linkedCurvePointId) { stateService.setSelectItem( this.modifyPoint.linkedCurvePointId, VectorType.CurvePoint, SelectState.Select ); } else if (this.modifyPoint.linkedLineId) { stateService.setSelectItem( this.modifyPoint.linkedLineId, VectorType.Line, SelectState.Select ); } else if (this.modifyPoint.linkedCurveLineId) { stateService.setSelectItem( this.modifyPoint.linkedCurveLineId, VectorType.CurveLine, SelectState.Select ); } else if (this.modifyPoint.linkedCircleId) { stateService.setSelectItem( this.modifyPoint.linkedCircleId, VectorType.Circle, this.modifyPoint.index ); } let newSelectItem = stateService.getSelectItem(); if (selectItem == null && newSelectItem == null) { return false; } else if (selectItem == null && newSelectItem != null) { return true; } else if (selectItem != null && newSelectItem == null) { return true; } else if (selectItem.vectorId == newSelectItem.vectorId) { return false; } else { return true; } } distanceForBezier(position, curves, width) { return mathUtil.getHitInfoForCurves(position, curves, width); } equalAndClone(info1, info2) { let flag = true; for (let key in info1) { if (info1[key] != info2[key]) { flag = false; } info1[key] = info2[key]; } return flag; } clear() { this.modifyPoint = null; } } const listenLayer = new ListenLayer(); export { listenLayer };