123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128 |
- 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 };
|