12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286 |
- 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";
- import VectorCategory from "./enum/VectorCategory";
- export default class ListenLayer {
- constructor() {
- this.modifyPoint = null;
- }
- //开始监听,exceptVectorIds表示不考虑的元素
- /**
- *
- * @param exceptVectorIds:{
- exceptPointId,
- exceptLineId,
- exceptCurvePointId,
- exceptCurveLineId,
- 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.curvePointInfo = this.isSelectCurvePoint(
- position,
- exceptVectorIds.exceptCurvePointId
- );
- selectInfo.curveLineInfo = this.isSelectCurveLine(
- position,
- exceptVectorIds.exceptCurveLineId
- );
- 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;
- }
- isSelectCurvePoint(position, exceptCurvePointId) {
- let curvePointInfo = {
- curvePointId: null,
- type: null,
- distance: null,
- };
- let seqInfo = {};
- const curvePoints = dataService.getCurvePoints();
- for (const curvePointId in curvePoints) {
- if (curvePointId == exceptCurvePointId) {
- continue;
- }
- const curvePoint = dataService.getCurvePoint(curvePointId);
- const distance = mathUtil.getDistance(position, curvePoint);
- if (distance < Constant.minAdsorbPix) {
- if (curvePointInfo.curvePointId == null) {
- curvePointInfo = {
- curvePointId: curvePointId,
- type: VectorType.CurvePoint,
- distance: distance,
- };
- } else {
- if (distance < curvePointInfo.distance) {
- curvePointInfo = {
- curvePointId: curvePointId,
- type: VectorType.CurvePoint,
- distance: distance,
- };
- }
- }
- } else {
- if (Math.abs(position.x - curvePoint.x) < Constant.minAdsorbPix) {
- seqInfo.linkedCurvePointIdX = curvePointId;
- seqInfo.x = curvePoint.x;
- }
- if (Math.abs(position.y - curvePoint.y) < Constant.minAdsorbPix) {
- seqInfo.linkedPointIdY = curvePointId;
- seqInfo.y = curvePoint.y;
- }
- }
- }
- if (curvePointInfo.curvePointId) {
- curvePointInfo.linkedCurvePointId = curvePointInfo.curvePointId;
- const linkedCurvePoint = dataService.getCurvePoint(
- curvePointInfo.curvePointId
- );
- curvePointInfo.x = linkedCurvePoint.x;
- curvePointInfo.y = linkedCurvePoint.y;
- } else {
- if (seqInfo.hasOwnProperty("linkedCurvePointIdX")) {
- curvePointInfo.linkedCurvePointIdX = seqInfo.linkedCurvePointIdX;
- curvePointInfo.x = seqInfo.x;
- }
- if (seqInfo.hasOwnProperty("linkedCurvePointIdY")) {
- curvePointInfo.linkedCurvePointIdY = seqInfo.linkedCurvePointIdY;
- curvePointInfo.y = seqInfo.y;
- }
- if (
- curvePointInfo.hasOwnProperty("y") &&
- !curvePointInfo.hasOwnProperty("x")
- ) {
- curvePointInfo.x = position.x;
- }
- if (
- curvePointInfo.hasOwnProperty("x") &&
- !curvePointInfo.hasOwnProperty("y")
- ) {
- curvePointInfo.y = position.y;
- }
- }
- return curvePointInfo;
- }
- isSelectCurveLine(position, exceptCurveLineIds) {
- let curveLineInfo = {
- curveLineId: null,
- type: null,
- distance: null,
- };
- const curveLines = dataService.getCurveLines();
- for (const curveLineId in curveLines) {
- if (
- exceptCurveLineIds &&
- exceptCurveLineIds.hasOwnProperty(curveLineId)
- ) {
- continue;
- }
- const curveLine = dataService.getCurveLine(curveLineId);
- let startPoint = dataService.getCurvePoint(curveLine.startId);
- let endPoint = dataService.getCurvePoint(curveLine.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) {
- curveLineInfo = {
- curveLineId: curveLineId,
- type: VectorType.CurveLine,
- distance: distance,
- };
- }
- }
- if (curveLineInfo.curveLineId) {
- const linkedLine = dataService.getLine(lineInfo.curveLineId);
- let startPoint = dataService.getCurvePoint(linkedLine.startId);
- let endPoint = dataService.getCurvePoint(linkedLine.endId);
- const linkedComLine = mathUtil.createLine1(startPoint, endPoint);
- const linkedPosition = mathUtil.getJoinLinePoint(position, linkedComLine);
- curveLineInfo.x = linkedPosition.x;
- curveLineInfo.y = linkedPosition.y;
- return curveLineInfo;
- }
- return curveLineInfo;
- }
- 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);
- if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
- continue;
- }
- 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;
- }
- 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;
- }
- 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);
- if (
- line.getCategory() == VectorCategory.Line.PositionLine ||
- line.getCategory() == VectorCategory.Line.BaseLine
- ) {
- continue;
- }
- 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 &&
- !info.pointInfo.linkedPointIdY
- ) {
- 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 &&
- !info.pointInfo.linkedPointIdX
- ) {
- this.modifyPoint = {};
- this.modifyPoint.linkedPointIdY = info.pointInfo.linkedPointIdY;
- this.modifyPoint.y = info.pointInfo.y;
- this.modifyPoint.x = info.pointInfo.x;
- } else if (
- info &&
- info.pointInfo.linkedPointIdY &&
- info.pointInfo.linkedPointIdX
- ) {
- this.modifyPoint = {};
- this.modifyPoint.linkedPointIdX = info.pointInfo.linkedPointIdX;
- 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 };
|