12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691 |
- import Load from "./Load";
- import { stateService } from "./Service/StateService";
- import { elementService } from "./Service/ElementService";
- import { dataService } from "./Service/DataService";
- import { textService } from "./Service/TextService";
- import { historyService } from "./Service/HistoryService";
- import UIControl from "./Controls/UIControl";
- // import { moveRectangle } from "./Controls/MoveRectangle";
- import { moveText } from "./Controls/MoveText";
- import { moveSVG } from "./Controls/MoveSVG";
- import { moveMagnifier } from "./Controls/MoveMagnifier";
- import { addRoad } from "./Controls/AddRoad";
- import { addCrossRoad } from "./Controls/AddCrossRoad";
- import { addLine } from "./Controls/AddLine";
- import { addPoint } from "./Controls/AddPoint";
- import { addCircle } from "./Controls/AddCircle";
- import { addText } from "./Controls/AddText";
- import { addMagnifier } from "./Controls/AddMagnifier";
- import { addSVG } from "./Controls/AddSVG";
- import { moveRoad } from "./Controls/MoveRoad";
- import { moveLine } from "./Controls/MoveLine";
- import { movePoint } from "./Controls/MovePoint";
- import { moveCircle } from "./Controls/MoveCircle";
- import { coordinate } from "./Coordinate";
- import Render from "./Renderer/Render";
- import { draw } from "./Renderer/Draw";
- import { listenLayer } from "./ListenLayer";
- import LayerEvents from "./enum/LayerEvents.js";
- import UIEvents from "./enum/UIEvents.js";
- import SelectState from "./enum/SelectState.js";
- import VectorType from "./enum/VectorType";
- import { mathUtil } from "./Util/MathUtil";
- import History from "./History/History";
- import mitt from "mitt";
- import { roadService } from "./Service/RoadService";
- import { edgeService } from "./Service/EdgeService";
- import { roadPointService } from "./Service/RoadPointService";
- import { curveRoadService } from "./Service/CurveRoadService";
- import VectorCategory from "./enum/VectorCategory";
- import Settings from "./Settings";
- import Constant from "./Constant";
- import { uiService } from "./Service/UIService";
- import { imageService } from "./Service/ImageService";
- import VectorEvents from "./enum/VectorEvents";
- const minDragDis = 10;
- const minZoom = 20;
- const maxZoom = 800;
- export default class Layer {
- constructor(canvas, newsletter, graphicState) {
- this.canvas = canvas;
- this.load = new Load(this);
- this.uiControl = new UIControl(this, newsletter, graphicState);
- this.renderer = new Render(this);
- this.history = new History(this);
- this.mousePosition = null;
- this.dragging = false; // 当前是否正在拖拽
- this.start();
- Object.setPrototypeOf(Object.getPrototypeOf(this), mitt());
- }
- start() {
- if (this.canvas) {
- this.canvas.width = this.canvas.clientWidth;
- this.canvas.height = this.canvas.clientHeight;
- coordinate.init(this.canvas);
- draw.initContext(this.canvas);
- dataService.initVectorData();
- this.bindEvents();
- }
- window.vectorData = dataService.vectorData;
- }
- bindEvents() {
- this.canvas.addEventListener("contextmenu", function (e) {
- e.preventDefault();
- });
- this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
- this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this));
- this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
- this.canvas.addEventListener("touchstart", this.onMouseDown.bind(this));
- this.canvas.addEventListener("touchmove", this.onMouseMove.bind(this));
- this.canvas.addEventListener("touchend", this.onMouseUp.bind(this));
- this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
- this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
- this.canvas.addEventListener("resize", this.reSize.bind(this));
- document.addEventListener("keydown", this.onKeydown.bind(this));
- }
- reSize = function () {
- console.log("resize");
- coordinate.updateForCanvas();
- this.renderer.autoRedraw();
- };
- onMouseDown(e) {
- if (e instanceof TouchEvent) {
- this.startX = e.touches[0].pageX;
- this.startY = e.touches[0].pageY;
- this.lastX = e.touches[0].pageX;
- this.lastY = e.touches[0].pageY;
- } else {
- this.startX = e.offsetX || e.layerX;
- this.startY = e.offsetY || e.layerY;
- this.lastX = e.offsetX || e.layerX;
- this.lastY = e.offsetY || e.layerY;
- }
- let position = coordinate.getXYFromScreen({
- x: this.startX,
- y: this.startY,
- });
- // 右键
- if (e.button == 2) {
- this.stopAddVector();
- return;
- }
- this.dragging = false;
- //用于支持平板电脑
- listenLayer.start(position);
- let selectItem = stateService.getSelectItem();
- let focusItem = stateService.getFocusItem();
- this.setEventName("mouseDown");
- const eventName = stateService.getEventName();
- switch (eventName) {
- case LayerEvents.AddRoad:
- stateService.setEventName(LayerEvents.AddingRoad);
- addRoad.setNewRoadPoint("start", position);
- break;
- case LayerEvents.AddCurveRoad:
- stateService.setEventName(LayerEvents.AddingCurveRoad);
- addRoad.setNewRoadPoint("start", position);
- break;
- case LayerEvents.AddLine:
- stateService.setEventName(LayerEvents.AddingLine);
- addLine.setNewLinePoint(position);
- break;
- case LayerEvents.AddCurveLine:
- stateService.setEventName(LayerEvents.AddingCurveLine);
- addLine.setNewLinePoint(position);
- break;
- case LayerEvents.AddPoint:
- stateService.setEventName(LayerEvents.MovePoint);
- const newPoint = addPoint.buildPoint(position);
- if (newPoint) {
- stateService.setSelectItem(
- newPoint.vectorId,
- VectorType.Point,
- SelectState.Select
- );
- this.history.save();
- this.renderer.autoRedraw();
- } else {
- let points = dataService.vectorData.points;
- let basePoints = []
- for (let key in points) {
- if (points[key].category == VectorCategory.Point.BasePoint) {
- basePoints.push(points[key].vectorId)
- }
- }
- if(basePoints.length==1){
- this.uiControl.prompt({ msg: '请先选择基准点', time: 1000 });
- }else{
- this.uiControl.prompt({ msg: '请先添加基准点', time: 1000 });
- }
- // this.uiControl.prompt({ msg: '请先选择基准点', time: 1000 });
- }
- break;
- case LayerEvents.AddCircle:
- stateService.setEventName(LayerEvents.AddingCircle);
- addCircle.setCenter(position);
- break;
- case LayerEvents.AddText:
- stateService.setEventName(LayerEvents.MoveText);
- addText.buildText(position);
- stateService.setSelectItem(
- addText.newText.vectorId,
- VectorType.Text,
- SelectState.Select
- );
- addText.clear();
- break;
- case LayerEvents.AddSVG:
- stateService.setEventName(LayerEvents.MoveSVG);
- addSVG.buildSVG(position);
- addSVG.newSVG.setType(Settings.selectSVGType);
- stateService.setSelectItem(addSVG.newSVG.vectorId, VectorType.SVG, -1);
- addSVG.clear();
- break;
- case LayerEvents.AddMagnifier:
- stateService.setEventName(LayerEvents.MoveMagnifier);
- addMagnifier.buildMagnifier(position);
- stateService.setSelectItem(
- addMagnifier.newMagnifier.vectorId,
- VectorType.Magnifier,
- SelectState.Select
- );
- addMagnifier.clear();
- break;
- case VectorEvents.AddLane:
- if (selectItem && selectItem.dir && selectItem.vectorId) {
- let road = dataService.getRoad(selectItem.vectorId);
- if (road) {
- let roadLanCount = road.getLanesCount(selectItem.dir);
- if (selectItem.dir == "left") {
- roadService.updateForAddSubtractLanesCount(
- road.vectorId,
- roadLanCount + 1,
- selectItem.dir
- );
- } else {
- roadService.updateForAddSubtractLanesCount(
- road.vectorId,
- roadLanCount + 1,
- selectItem.dir
- );
- }
- } else {
- road = dataService.getCurveRoad(selectItem.vectorId);
- let curveRoadLanCount = road.getLanesCount(selectItem.dir);
- if (selectItem.dir == "left") {
- curveRoadService.updateForAddSubtractLanesCount(
- road.vectorId,
- curveRoadLanCount + 1,
- selectItem.dir
- );
- } else {
- curveRoadService.updateForAddSubtractLanesCount(
- road.vectorId,
- curveRoadLanCount + 1,
- selectItem.dir
- );
- }
- }
- stateService.clearEventName();
- this.history.save();
- this.renderer.autoRedraw();
- }
- break;
- case VectorEvents.DelLane:
- if (selectItem && selectItem.dir && selectItem.vectorId) {
- let road = dataService.getRoad(selectItem.vectorId);
- if (road) {
- let roadLanCount = road.getLanesCount(selectItem.dir);
- if (selectItem.dir == "left") {
- roadService.updateForAddSubtractLanesCount(
- road.vectorId,
- roadLanCount - 1,
- selectItem.dir
- );
- } else {
- roadService.updateForAddSubtractLanesCount(
- road.vectorId,
- roadLanCount - 1,
- selectItem.dir
- );
- }
- } else {
- road = dataService.getCurveRoad(selectItem.vectorId);
- let curveRoadLanCount = road.getLanesCount(selectItem.dir);
- if (selectItem.dir == "left") {
- curveRoadService.updateForAddSubtractLanesCount(
- road.vectorId,
- curveRoadLanCount - 1,
- selectItem.dir
- );
- } else {
- curveRoadService.updateForAddSubtractLanesCount(
- road.vectorId,
- curveRoadLanCount - 1,
- selectItem.dir
- );
- }
- }
- stateService.clearEventName();
- this.history.save();
- this.renderer.autoRedraw();
- }
- break;
- case VectorEvents.AddCrossPoint:
- if (focusItem && focusItem.vectorId) {
- const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
- let index = mathUtil.getIndexForCurvesPoints(
- position,
- curveRoad.points
- );
- if (index != -1) {
- curveRoadService.addCPoint(curveRoad, position, index);
- } else {
- const dis1 = mathUtil.getDistance(curveRoad.points[0], position);
- const dis2 = mathUtil.getDistance(
- curveRoad.points[curveRoad.points.length - 1],
- position
- );
- if (dis1 > dis2) {
- index = curveRoad.points.length - 2;
- // curveRoadService.addCPoint(
- // curveRoad,
- // position,
- // curveRoad.points.length - 2
- // );
- } else {
- //curveRoadService.addCPoint(curveRoad, position, 1);
- index = 1;
- }
- curveRoadService.addCPoint(curveRoad, position, index);
- }
- //curveRoadService.setLanes(curveRoad.vectorId);
- curveRoadService.updateForMovePoint(
- curveRoad.points[index + 1].vectorId,
- position
- );
- stateService.clearEventName();
- this.history.save();
- this.renderer.autoRedraw();
- }
- break;
- case VectorEvents.MinusCrossPoint:
- if (selectItem && selectItem.vectorId) {
- const curvePoint = dataService.getCurveRoadPoint(selectItem.vectorId);
- const curveRoad = dataService.getCurveRoad(curvePoint.parent);
- if (curveRoad.points.length > 3) {
- curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
- curveRoadService.setLanes(curveRoad.vectorId);
- stateService.clearEventName();
- }
- this.history.save();
- this.renderer.autoRedraw();
- }
- break;
- }
- selectItem = stateService.getSelectItem();
- stateService.setDraggingItem(selectItem);
- // 清除上一个状态
- // 设置当前事件名称
- e.preventDefault();
- e.stopPropagation();
- }
- onMouseMove(e) {
- let X = e.offsetX || e.layerX;
- let Y = e.offsetY || e.layerY;
- if (e instanceof TouchEvent) {
- X = e.touches[0].pageX;
- Y = e.touches[0].pageY;
- //切换到缩放
- if (e.touches.length > 1) {
- //记录开始的两个触摸点的坐标
- if (!this.StorePage1 || !this.StorePage2) {
- this.onMouseUp(e);
- this.StorePage1 = { x: e.touches[0].pageX, y: e.touches[0].pageY };
- this.StorePage2 = { x: e.touches[1].pageX, y: e.touches[1].pageY };
- this.StoreMidePage = {
- x: (this.StorePage1.x + this.StorePage2.x) / 2,
- y: (this.StorePage1.y + this.StorePage2.y) / 2,
- };
- return;
- }
- const point1 = {
- x: e.touches[0].pageX,
- y: e.touches[0].pageY,
- };
- const point2 = {
- x: e.touches[1].pageX,
- y: e.touches[1].pageY,
- };
- let dis1 = mathUtil.getDistance(point1, point2) / 100;
- let dis2 = mathUtil.getDistance(this.StorePage1, this.StorePage2) / 100;
- let zoom = (coordinate.zoom * dis1) / dis2;
- this.zoomVector(this.StoreMidePage, zoom);
- mathUtil.clonePoint(this.StorePage1, point1);
- mathUtil.clonePoint(this.StorePage2, point2);
- return;
- }
- }
- let dx = X - this.lastX;
- let dy = Y - this.lastY;
- dx = dx * coordinate.ratio;
- dy = dy * coordinate.ratio;
- let position = coordinate.getXYFromScreen({
- x: X,
- y: Y,
- });
- this.mousePosition = {
- x: position.x,
- y: position.y,
- };
- const eventName = stateService.getEventName();
- if (
- !this.dragging &&
- Math.abs(X - this.startX) < minDragDis &&
- Math.abs(Y - this.startY) < minDragDis
- ) {
- return;
- }
- this.dragging = true;
- if (
- Math.abs(X - this.startX) > minDragDis ||
- Math.abs(Y - this.startY) > minDragDis
- ) {
- // 是否拖拽了
- if (eventName != null) {
- if (
- eventName == LayerEvents.MoveMagnifier &&
- stateService.getSelectItem().state != 0
- ) {
- } else {
- stateService.clearFocusItem();
- this.uiControl.focusVector = null;
- }
- }
- }
- // 是否需要重绘
- let needAutoRedraw = false;
- let point = null;
- this.lastX = X;
- this.lastY = Y;
- const draggingItem = stateService.getDraggingItem();
- switch (eventName) {
- case null:
- //监控
- needAutoRedraw = listenLayer.start(position);
- let seleteItem = stateService.getSelectItem();
- if (seleteItem != null) {
- console.log("选中:" + seleteItem.vectorId);
- } else {
- }
- break;
- case LayerEvents.PanBackGround:
- stateService.clearItems();
- let center = {};
- center.x =
- coordinate.center.x - (dx * coordinate.defaultZoom) / coordinate.zoom;
- center.y =
- coordinate.center.y + (dy * coordinate.defaultZoom) / coordinate.zoom;
- let tempCenter = {};
- mathUtil.clonePoint(tempCenter, coordinate.center);
- mathUtil.clonePoint(coordinate.center, center);
- let inScreen = imageService.backgroundImgVertexsInScreenXY();
- if (!inScreen) {
- dataService.setGridForPan();
- needAutoRedraw = true;
- } else {
- mathUtil.clonePoint(coordinate.center, tempCenter);
- }
- break;
- case LayerEvents.AddRoad:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.hideAll();
- //鼠标样式
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddLine:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddCurveLine:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddCircle:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position);
- break;
- case LayerEvents.AddingRoad:
- needAutoRedraw = true;
- listenLayer.start(position);
- // listenLayer.start(position, {
- // exceptLineId: exceptLineId,
- // exceptPointId: exceptPointId,
- // addRoad.startInfo.linkedRoadId
- // addRoad.startInfo.linkedRoadPointId
- // });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- // console.log(
- // "LayerEvents.AddingRoad:" + JSON.stringify(listenLayer.modifyPoint)
- // );
- }
- elementService.execute(addRoad.startInfo.position, position);
- elementService.setPoint(position);
- elementService.setNewRoad(addRoad.startInfo.position, position);
- elementService.showNewRoad();
- addRoad.setNewRoadPoint("end", position);
- addRoad.canAdd = addRoad.canAddRoadForEnd(position);
- if (!addRoad.canAdd) {
- elementService.setNewRoadState("error");
- } else {
- elementService.setNewRoadState("normal");
- }
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddingLine:
- needAutoRedraw = true;
- let exceptLineId = null;
- let exceptPointId = null;
- if (addLine.newLine != null) {
- exceptLineId = addLine.newLine.vectorId;
- exceptPointId = addLine.newLine.endId;
- }
- listenLayer.start(position, {
- exceptLineId: exceptLineId,
- exceptPointId: exceptPointId,
- });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- // elementService.execute(addLine.startInfo.position, position);
- // elementService.setPoint(position);
- if (addLine.newLine == null) {
- addLine.buildLine(position);
- } else {
- addLine.updateLine(position);
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddingCurveLine:
- needAutoRedraw = true;
- let exceptCurveLineId = null;
- let exceptCurvePointId = null;
- if (addLine.newLine != null) {
- exceptCurveLineId = addLine.newLine.vectorId;
- exceptCurvePointId = addLine.newLine.endId;
- }
- listenLayer.start(position, {
- exceptCurveLineId: exceptCurveLineId,
- exceptCurvePointId: exceptCurvePointId,
- });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- // elementService.execute(addLine.startInfo.position, position);
- // elementService.setPoint(position);
- if (addLine.newLine == null) {
- addLine.buildCurveLine(position);
- } else {
- addLine.updateCurveLine(position);
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddingCircle:
- needAutoRedraw = true;
- let exceptCircleId = null;
- if (addCircle.newCircle != null) {
- exceptCircleId = addCircle.newCircle.vectorId;
- }
- listenLayer.start(position, { exceptCircleId: exceptCircleId });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- if (addCircle.newCircle == null) {
- addCircle.buildCircle(position);
- } else {
- addCircle.updateCircle(position);
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position);
- break;
- case LayerEvents.MoveRoad:
- needAutoRedraw = true;
- //只允许拖拽一条公路
- let road = dataService.getRoad(draggingItem.vectorId);
- let start = dataService.getRoadPoint(road.startId);
- let end = dataService.getRoadPoint(road.endId);
- if (
- Object.keys(start.getParent()).length == 1 &&
- Object.keys(end.getParent()).length == 1
- ) {
- //拖拽的路只有一条
- moveRoad.moveRoad(
- draggingItem.vectorId,
- (dx * coordinate.defaultZoom) / coordinate.zoom,
- (dy * coordinate.defaultZoom) / coordinate.zoom
- );
- }
- break;
- case LayerEvents.MoveRoadPoint:
- point = dataService.getRoadPoint(draggingItem.vectorId);
- listenLayer.start(position, {
- exceptRoadPointId: draggingItem.vectorId,
- exceptRoadIds: point.parent,
- });
- if (
- listenLayer.modifyPoint &&
- (listenLayer.modifyPoint.linkedRoadPointId ||
- listenLayer.modifyPoint.linkedRoadId ||
- listenLayer.modifyPoint.linkedRoadPointIdX ||
- listenLayer.modifyPoint.linkedRoadPointIdY)
- ) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- } else {
- listenLayer.modifyPoint = null;
- }
- let flag = moveRoad.moveingRoadPoint(
- draggingItem.vectorId,
- position,
- listenLayer.modifyPoint
- );
- if (!flag) {
- elementService.hideAll();
- } else {
- this.showElementLine(point, eventName);
- }
- needAutoRedraw = true;
- break;
- case LayerEvents.AddCurveRoad:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.hideAll();
- elementService.setPoint(position);
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.AddingCurveRoad:
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.execute(addRoad.startInfo.position, position);
- elementService.setPoint(position);
- elementService.setNewRoad(addRoad.startInfo.position, position);
- elementService.showNewRoad();
- addRoad.setNewRoadPoint("end", position);
- addRoad.canAdd = addRoad.canAddRoadForEnd(position);
- if (!addRoad.canAdd) {
- elementService.setNewRoadState("error");
- } else {
- elementService.setNewRoadState("normal");
- }
- elementService.showPoint();
- this.showElementLine(position, eventName);
- break;
- case LayerEvents.MoveCurveRoad:
- needAutoRedraw = true;
- moveRoad.moveCurveRoad(
- draggingItem.vectorId,
- (dx * coordinate.defaultZoom) / coordinate.zoom,
- (dy * coordinate.defaultZoom) / coordinate.zoom
- );
- break;
- case LayerEvents.MoveCurveRoadPoint:
- if (!draggingItem || !draggingItem.vectorId) {
- return;
- }
- point = dataService.getCurveRoadPoint(draggingItem.vectorId);
- listenLayer.start(position, {
- exceptRoadPointId: draggingItem.vectorId,
- exceptCurveRoadId: point.parent, //不会融合,所以parent只有一个
- });
- if (
- listenLayer.modifyPoint &&
- (listenLayer.modifyPoint.linkedRoadPointId ||
- listenLayer.modifyPoint.linkedRoadId ||
- listenLayer.modifyPoint.linkedRoadPointIdX ||
- listenLayer.modifyPoint.linkedRoadPointIdY ||
- listenLayer.modifyPoint.linkedCurvePointIdX ||
- listenLayer.modifyPoint.linkedCurvePointIdY ||
- listenLayer.modifyPoint.linkedCurveRoadPointIdX)
- ) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- moveRoad.moveCurveRoadPoint(draggingItem.vectorId, position);
- this.showElementLine(point, eventName);
- needAutoRedraw = true;
- break;
- case LayerEvents.MoveCrossPoint:
- if (!draggingItem || !draggingItem.vectorId) {
- return;
- }
- moveRoad.moveCrossPoint(draggingItem.vectorId, position);
- needAutoRedraw = true;
- break;
- case LayerEvents.MoveEdge:
- moveRoad.moveEdge(draggingItem.vectorId, position);
- needAutoRedraw = true;
- break;
- case LayerEvents.MoveCurveEdge:
- if (listenLayer.modifyPoint) {
- moveRoad.moveCurveEdge(
- draggingItem.vectorId,
- listenLayer.modifyPoint.selectIndex,
- position
- );
- }
- needAutoRedraw = true;
- break;
- case LayerEvents.MoveLine:
- if (draggingItem != null) {
- let flag = moveLine.moveLine(
- draggingItem.vectorId,
- (dx * coordinate.defaultZoom) / coordinate.zoom,
- (dy * coordinate.defaultZoom) / coordinate.zoom
- );
- if (!flag) {
- this.lastX = this.lastX - dx / coordinate.ratio;
- this.lastY = this.lastY - dy / coordinate.ratio;
- }
- needAutoRedraw = true;
- }
- break;
- case LayerEvents.MovePoint:
- if (draggingItem != null) {
- point = dataService.getPoint(draggingItem.vectorId);
- listenLayer.start(position, {
- exceptPointId: draggingItem.vectorId,
- exceptLineId: point.parent,
- });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- movePoint.movePoint(position, draggingItem.vectorId);
- point = dataService.getPoint(draggingItem.vectorId);
- needAutoRedraw = true;
- if (!point) {
- stateService.clearEventName();
- } else {
- this.showElementLine(point, eventName);
- }
- }
- break;
- case LayerEvents.MoveCurvePoint:
- if (draggingItem != null) {
- let curvePoint = dataService.getCurvePoint(draggingItem.vectorId);
- listenLayer.start(position, {
- exceptCurvePointId: draggingItem.vectorId,
- exceptCurveLineId: curvePoint.parent,
- });
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- movePoint.moveCurvePoint(position, draggingItem.vectorId);
- this.showElementLine(curvePoint, eventName);
- needAutoRedraw = true;
- }
- break;
- case LayerEvents.MoveCurveLine:
- if (draggingItem != null) {
- moveLine.moveCurveLine(
- draggingItem.vectorId,
- (dx * coordinate.defaultZoom) / coordinate.zoom,
- (dy * coordinate.defaultZoom) / coordinate.zoom
- );
- needAutoRedraw = true;
- }
- break;
- case LayerEvents.MoveCircle:
- if (draggingItem != null) {
- if (draggingItem.state == -1) {
- moveCircle.moveFull(
- draggingItem.vectorId,
- (dx * coordinate.defaultZoom) / coordinate.zoom,
- (dy * coordinate.defaultZoom) / coordinate.zoom
- );
- } else if (
- draggingItem.state == 0 ||
- draggingItem.state == 1 ||
- draggingItem.state == 2 ||
- draggingItem.state == 3
- ) {
- moveCircle.movePoint(
- position,
- draggingItem.vectorId,
- draggingItem.state
- );
- } else {
- debugger;
- }
- needAutoRedraw = true;
- }
- break;
- case LayerEvents.MoveText:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveText.moveFullText(position, draggingItem.vectorId);
- }
- break;
- case LayerEvents.MoveSVG:
- needAutoRedraw = true;
- if (draggingItem != null) {
- if (draggingItem.state == -1) {
- moveSVG.moveFullSVG(position, draggingItem.vectorId);
- } else {
- moveSVG.movePoint(
- position,
- draggingItem.vectorId,
- draggingItem.state
- );
- }
- }
- break;
- case LayerEvents.MoveMagnifier:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveMagnifier.moveFullMagnifier(
- position,
- draggingItem.vectorId,
- draggingItem.state
- );
- }
- break;
- }
- if (needAutoRedraw) {
- this.renderer.autoRedraw();
- }
- }
- onMouseUp(e) {
- // 右键
- if (e.button == 2) {
- this.dragging = false;
- return;
- }
- let X = e.offsetX || e.layerX;
- let Y = e.offsetY || e.layerY;
- if (e instanceof TouchEvent) {
- X = this.lastX;
- Y = this.lastY;
- this.StorePage1 = null;
- this.StorePage2 = null;
- this.StoreMidePage = null;
- if (e.touches.length > 1) {
- this.dragging = false;
- return;
- }
- }
- let eventName = stateService.getEventName();
- const draggingItem = stateService.getDraggingItem();
- const selectItem = stateService.getSelectItem();
- let focusItem = null;
- if (!this.dragging && selectItem) {
- focusItem = {
- vectorId: selectItem.vectorId,
- type: selectItem.type,
- cursor: { x: this.lastX, y: this.lastY },
- dir: selectItem.dir,
- };
- stateService.setFocusItem(focusItem);
- this.uiControl.focusVector = focusItem;
- stateService.clearDraggingItem();
- } else {
- this.uiControl.focusVector = null;
- }
- this.dragging = false;
- let position = coordinate.getXYFromScreen({
- x: X,
- y: Y,
- });
- let needAutoRedraw = false;
- switch (eventName) {
- case null:
- return;
- case LayerEvents.PanBackGround:
- needAutoRedraw = true;
- stateService.clearFocusItem();
- this.uiControl.focusVector = null;
- this.uiControl.currentUI = null;
- break;
- case LayerEvents.MoveRoadPoint:
- if (!draggingItem || !draggingItem.vectorId) {
- break;
- }
- needAutoRedraw = true;
- elementService.hideAll();
- let point = dataService.getRoadPoint(draggingItem.vectorId);
- if (point) {
- listenLayer.start(point, {
- exceptPointId: draggingItem.vectorId,
- exceptRoadIds: point.parent,
- });
- if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.hasOwnProperty("linkedRoadPointId")
- ) {
- moveRoad.moveTo(
- draggingItem.vectorId,
- listenLayer.modifyPoint.linkedRoadPointId
- );
- } else if (
- listenLayer.modifyPoint &&
- (listenLayer.modifyPoint.linkedRoadPointIdX ||
- listenLayer.modifyPoint.linkedRoadPointIdY)
- ) {
- mathUtil.clonePoint(point, listenLayer.modifyPoint);
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.hasOwnProperty("linkedRoadId")
- ) {
- point = roadPointService.create({
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- });
- roadService.splitRoad(
- listenLayer.modifyPoint.linkedRoadId,
- point.vectorId,
- "start"
- );
- moveRoad.moveTo(draggingItem.vectorId, point.vectorId);
- } else if (moveRoad.splitRoadId != null) {
- roadService.splitRoad(
- moveRoad.splitRoadId,
- draggingItem.vectorId,
- "start"
- );
- }
- //draggingItem.vectorId所在的墙面与其他墙角相交
- moveRoad.updateForAbsorbRoadPoints();
- let parent = point.getParent();
- for (let key in parent) {
- roadService.setLanes(key);
- }
- this.history.save();
- }
- break;
- // case LayerEvents.AddRoad:
- // addRoad.setNewRoadPoint("start", position);
- // break;
- case LayerEvents.AddingRoad:
- needAutoRedraw = true;
- if (addRoad.canAdd) {
- addRoad.buildRoad();
- this.history.save();
- elementService.hideAll();
- }
- break;
- case LayerEvents.AddingLine:
- if (Settings.selectLocationMode == Constant.freeLocationMode) {
- this.uiControl.showConfirm();
- }
- needAutoRedraw = true;
- addLine.finish(position);
- this.updateForLocation();
- addLine.clearVectorData();
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.AddingCurveLine:
- needAutoRedraw = true;
- addLine.finishCurveLine(position);
- addLine.clearVectorData();
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.AddingCircle:
- needAutoRedraw = true;
- addCircle.finish(position);
- addCircle.clear();
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.MoveText:
- needAutoRedraw = true;
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.MoveSVG:
- needAutoRedraw = true;
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.MoveMagnifier:
- needAutoRedraw = true;
- this.history.save();
- elementService.hideAll();
- //拖拽完放大镜后需要重新打开
- // focusItem = {
- // vectorId: selectItem.vectorId,
- // type: selectItem.type,
- // cursor: { x: this.lastX, y: this.lastY },
- // dir: selectItem.dir,
- // };
- // this.uiControl.focusVector = focusItem;
- // stateService.setFocusItem(focusItem);
- break;
- case LayerEvents.MoveSVG:
- needAutoRedraw = true;
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.AddingCurveRoad:
- needAutoRedraw = true;
- if (addRoad.canAdd) {
- addRoad.buildCurveRoad();
- this.history.save();
- elementService.hideAll();
- }
- break;
- case LayerEvents.MoveRoad:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCurveRoad:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCurveRoadPoint:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCrossPoint:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveEdge:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCurveEdge:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveLine:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MovePoint:
- needAutoRedraw = true;
- if (draggingItem && draggingItem.vectorId) {
- movePoint.finish(draggingItem.vectorId);
- uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
- }
- this.history.save();
- elementService.hideAll();
- break;
- case LayerEvents.MoveCurvePoint:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCurveLine:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.MoveCircle:
- needAutoRedraw = true;
- this.history.save();
- break;
- case LayerEvents.AddPoint:
- if (
- (Settings.selectBasePointId != null &&
- (Settings.selectLocationMode == Constant.angleLocationMode ||
- Settings.selectLocationMode == Constant.allLocationMode)) ||
- (Settings.baseLineId != null &&
- Settings.selectLocationMode == Constant.normalLocationMode)
- ) {
- this.uiControl.showConfirm();
- needAutoRedraw = true;
- elementService.hideAll();
- }
- break;
- case LayerEvents.AddRoadTemplate:
- addCrossRoad.build(position);
- this.history.save();
- this.renderer.autoRedraw();
- break;
- }
- this.setEventName("mouseUp");
- stateService.clearDraggingItem();
- if (needAutoRedraw) {
- this.renderer.autoRedraw();
- }
- }
- onWheel(e) {
- e.preventDefault();
- const type = e.type;
- if (type == "DOMMouseScroll" || type == "mousewheel") {
- // 当在canvas用滚轮滚动时
- const delta = e.wheelDelta
- ? (e.wheelDelta / 120) * 20
- : (-(e.detail || 0) / 3) * 20;
- const zoom = coordinate.zoom + delta;
- let X = e.offsetX || e.layerX;
- let Y = e.offsetY || e.layerY;
- this.zoomVector(
- {
- x: X,
- y: Y,
- },
- zoom
- );
- }
- }
- zoomVector(position, zoom) {
- if (zoom < minZoom || zoom > maxZoom) {
- return;
- }
- let tempCenter = {};
- mathUtil.clonePoint(tempCenter, coordinate.center);
- let tempZoom = coordinate.zoom;
- coordinate.updateZoom(position, zoom);
- let inScreen = imageService.backgroundImgVertexsInScreenXY();
- if (!inScreen) {
- dataService.setGridForZoom();
- this.renderer.autoRedraw();
- } else {
- mathUtil.clonePoint(coordinate.center, tempCenter);
- coordinate.zoom = tempZoom;
- }
- }
- //测试用
- onKeydown(e) {
- let focusItem = stateService.getFocusItem();
- let dir = "left";
- if (focusItem) {
- console.log("键盘(foucus有效):" + e.code);
- if (e.code == "Delete") {
- //删除
- const road = dataService.getRoad(focusItem.vectorId);
- roadService.subtraRoadFromIntersect(road.startId, focusItem.vectorId);
- roadService.subtraRoadFromIntersect(road.endId, focusItem.vectorId);
- //dataService.deleteCrossPoint()
- dataService.deleteRoad(focusItem.vectorId);
- this.renderer.autoRedraw();
- this.history.save();
- }
- //加宽
- else if (e.code == "KeyA") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForWidth(road.vectorId, road.leftWidth + 50, dir);
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForWidth(
- road.vectorId,
- road.leftWidth + 50,
- dir
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //变窄
- else if (e.code == "KeyB") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForWidth(road.vectorId, road.leftWidth - 25, dir);
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForWidth(
- road.vectorId,
- road.leftWidth - 25,
- dir
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //添加左车道
- else if (e.code == "KeyQ") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForAddSubtractLanesCount(
- focusItem.vectorId,
- road.leftDrivewayCount + 1,
- "left"
- );
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForAddSubtractLanesCount(
- road,
- road.leftDrivewayCount + 1, //rightDrivewayCount
- "left"
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //减少左车道
- else if (e.code == "KeyW") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForAddSubtractLanesCount(
- focusItem.vectorId,
- road.leftDrivewayCount - 1,
- "left"
- );
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForAddSubtractLanesCount(
- road,
- road.leftDrivewayCount - 1, //rightDrivewayCount
- "left"
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //添加右车道
- else if (e.code == "KeyE") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForAddSubtractLanesCount(
- focusItem.vectorId,
- road.rightDrivewayCount + 1,
- "right"
- );
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForAddSubtractLanesCount(
- road,
- road.rightDrivewayCount + 1, //rightDrivewayCount
- "right"
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //减少右车道
- else if (e.code == "KeyR") {
- let road = dataService.getRoad(focusItem.vectorId);
- if (road) {
- roadService.updateForAddSubtractLanesCount(
- focusItem.vectorId,
- road.rightDrivewayCount - 1,
- "right"
- );
- } else {
- road = dataService.getCurveRoad(focusItem.vectorId);
- curveRoadService.updateForAddSubtractLanesCount(
- road,
- road.rightDrivewayCount - 1, //rightDrivewayCount
- "right"
- );
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //弯路添加控制点
- else if (e.code == "KeyT") {
- const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
- let index = mathUtil.getIndexForCurvesPoints(
- this.mousePosition,
- curveRoad.points
- );
- if (index != -1) {
- curveRoadService.addCPoint(curveRoad, this.mousePosition, index);
- } else {
- const dis1 = mathUtil.getDistance(
- curveRoad.points[0],
- this.mousePosition
- );
- const dis2 = mathUtil.getDistance(
- curveRoad.points[curveRoad.points.length - 1],
- this.mousePosition
- );
- if (dis1 > dis2) {
- curveRoadService.addCPoint(
- curveRoad,
- this.mousePosition,
- curveRoad.points.length - 2
- );
- } else {
- curveRoadService.addCPoint(curveRoad, this.mousePosition, 1);
- }
- }
- this.renderer.autoRedraw();
- this.history.save();
- }
- //弯路删除控制点
- else if (e.code == "KeyY") {
- const curvePoint = dataService.getCurveRoadPoint(focusItem.vectorId);
- const curveRoad = dataService.getCurveRoad(curvePoint.parent);
- curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
- this.renderer.autoRedraw();
- this.history.save();
- }
- } else {
- console.log("键盘(foucus无效):" + e.code);
- }
- }
- setEventName(eventType) {
- let eventName = stateService.getEventName();
- if (eventType == "mouseDown") {
- if (eventName == null) {
- const selectItem = stateService.getSelectItem();
- if (selectItem == null) {
- stateService.setEventName(LayerEvents.PanBackGround);
- } else if (selectItem.type == VectorType.Road) {
- stateService.setEventName(LayerEvents.MoveRoad);
- } else if (selectItem.type == VectorType.RoadPoint) {
- stateService.setEventName(LayerEvents.MoveRoadPoint);
- } else if (selectItem.type == VectorType.CurveRoad) {
- stateService.setEventName(LayerEvents.MoveCurveRoad);
- } else if (selectItem.type == VectorType.CurveRoadPoint) {
- stateService.setEventName(LayerEvents.MoveCurveRoadPoint);
- } else if (selectItem.type == VectorType.CrossPoint) {
- stateService.setEventName(LayerEvents.MoveCrossPoint);
- } else if (selectItem.type == VectorType.RoadEdge) {
- stateService.setEventName(LayerEvents.MoveEdge);
- } else if (selectItem.type == VectorType.CurveRoadEdge) {
- stateService.setEventName(LayerEvents.MoveCurveEdge);
- } else if (selectItem.type == VectorType.Point) {
- stateService.setEventName(LayerEvents.MovePoint);
- } else if (selectItem.type == VectorType.Line) {
- stateService.setEventName(LayerEvents.MoveLine);
- } else if (selectItem.type == VectorType.CurvePoint) {
- stateService.setEventName(LayerEvents.MoveCurvePoint);
- } else if (selectItem.type == VectorType.CurveLine) {
- stateService.setEventName(LayerEvents.MoveCurveLine);
- } else if (selectItem.type == VectorType.Circle) {
- stateService.setEventName(LayerEvents.MoveCircle);
- } else if (selectItem.type == VectorType.Text) {
- stateService.setEventName(LayerEvents.MoveText);
- } else if (selectItem.type == VectorType.Magnifier) {
- stateService.setEventName(LayerEvents.MoveMagnifier);
- } else if (selectItem.type == VectorType.SVG) {
- stateService.setEventName(LayerEvents.MoveSVG);
- }
- }
- } else if (eventType == "mouseUp") {
- if (eventName == LayerEvents.AddingRoad) {
- if (Settings.isMobile) {
- stateService.clearEventName();
- this.exit();
- } else {
- stateService.setEventName(LayerEvents.AddRoad);
- }
- } else if (eventName == LayerEvents.AddingLine) {
- if (Settings.isMobile) {
- if (Settings.selectLocationMode == Constant.freeLocationMode) {
- stateService.setEventName(LayerEvents.AddLine);
- } else {
- stateService.clearEventName();
- this.exit();
- uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
- }
- } else {
- stateService.setEventName(LayerEvents.AddLine);
- }
- } else if (eventName == LayerEvents.AddingCurveRoad) {
- if (Settings.isMobile) {
- stateService.clearEventName();
- this.exit();
- } else {
- stateService.setEventName(LayerEvents.AddCurveRoad);
- }
- } else if (eventName == LayerEvents.AddLine) {
- stateService.setEventName(LayerEvents.AddingLine);
- } else if (
- (eventName == LayerEvents.AddPoint &&
- Settings.selectBasePointId != null &&
- (Settings.selectLocationMode == Constant.angleLocationMode ||
- Settings.selectLocationMode == Constant.allLocationMode)) ||
- (eventName == LayerEvents.AddPoint &&
- Settings.baseLineId != null &&
- Settings.selectLocationMode == Constant.normalLocationMode)
- ) {
- } else {
- stateService.clearEventName();
- }
- }
- }
- exit() {
- stateService.clear();
- this.uiControl.clearUI();
- this.uiControl.focusVector = null;
- this.uiControl.currentUI = null;
- }
- stopAddVector() {
- let eventName = stateService.getEventName();
- if (
- eventName != LayerEvents.AddingRoad &&
- eventName != LayerEvents.AddingLine
- ) {
- stateService.clearEventName();
- } else if (eventName == LayerEvents.AddingRoad) {
- stateService.setEventName(LayerEvents.AddRoad);
- } else if (eventName == LayerEvents.AddingLine) {
- stateService.setEventName(LayerEvents.AddLine);
- }
- addLine.clear(); //之前会保留category
- this.uiControl.clearUI();
- elementService.hideAll();
- this.renderer.autoRedraw();
- }
- initLocation() {
- Settings.baseLineId = null;
- this.uiControl.graphicStateUI.canAngleLocationMode = false;
- this.uiControl.graphicStateUI.canAllLocationMode = false;
- this.uiControl.graphicStateUI.canVerticalMeasure = false;
- this.uiControl.graphicStateUI.existsBaseLine = false;
- }
- //更新定位信息
- updateForLocation() {
- if (Settings.baseLineId) {
- this.uiControl.graphicStateUI.canAngleLocationMode = true;
- this.uiControl.graphicStateUI.canAllLocationMode = true;
- this.uiControl.graphicStateUI.existsBaseLine = true;
- this.uiControl.graphicStateUI.canVerticalMeasure = true;
- } else {
- this.uiControl.graphicStateUI.canAngleLocationMode = false;
- this.uiControl.graphicStateUI.canAllLocationMode = false;
- this.uiControl.graphicStateUI.existsBaseLine = false;
- this.uiControl.graphicStateUI.canVerticalMeasure = false;
- }
- }
- // showElementLine(point, eventName) {
- // let otherPoint1 = null;
- // let otherPoint2 = null;
- // if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedRoadPointIdX &&
- // (eventName == LayerEvents.AddingRoad ||
- // eventName == LayerEvents.MoveRoadPoint ||
- // eventName == LayerEvents.AddRoad)
- // ) {
- // otherPoint1 = dataService.getRoadPoint(
- // listenLayer.modifyPoint.linkedRoadPointIdX
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedCurveRoadPointIdX &&
- // (eventName == LayerEvents.AddingCurveRoad ||
- // eventName == LayerEvents.MoveCurveRoadPoint ||
- // eventName == LayerEvents.AddCurveRoad)
- // ) {
- // otherPoint1 = dataService.getCurveRoadPoint(
- // listenLayer.modifyPoint.linkedCurvePointIdX
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedPointIdX &&
- // (eventName == LayerEvents.AddLine || eventName == LayerEvents.MovePoint)
- // ) {
- // otherPoint1 = dataService.getPoint(
- // listenLayer.modifyPoint.linkedPointIdX
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedCurvePointIdX &&
- // (eventName == LayerEvents.AddCurveLine ||
- // eventName == LayerEvents.MoveCurvePoint)
- // ) {
- // otherPoint1 = dataService.getCurvePoint(
- // listenLayer.modifyPoint.linkedCurvePointIdX
- // );
- // }
- // if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedRoadPointIdY &&
- // (eventName == LayerEvents.AddingRoad ||
- // eventName == LayerEvents.MoveRoadPoint ||
- // eventName == LayerEvents.AddRoad)
- // ) {
- // otherPoint2 = dataService.getRoadPoint(
- // listenLayer.modifyPoint.linkedRoadPointIdY
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedCurvePointIdY &&
- // (eventName == LayerEvents.AddingCurveRoad ||
- // eventName == LayerEvents.MoveCurveRoadPoint ||
- // eventName == LayerEvents.AddCurveRoad)
- // ) {
- // otherPoint2 = dataService.getCurveRoadPoint(
- // listenLayer.modifyPoint.linkedCurvePointIdY
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedPointIdY &&
- // (eventName == LayerEvents.AddLine || eventName == LayerEvents.MovePoint)
- // ) {
- // otherPoint2 = dataService.getPoint(
- // listenLayer.modifyPoint.linkedPointIdY
- // );
- // } else if (
- // listenLayer.modifyPoint &&
- // listenLayer.modifyPoint.linkedCurvePointIdY &&
- // (eventName == LayerEvents.AddCurveLine ||
- // eventName == LayerEvents.MoveCurvePoint)
- // ) {
- // otherPoint2 = dataService.getCurvePoint(
- // listenLayer.modifyPoint.linkedCurvePointIdY
- // );
- // }
- // let otherPoint = {};
- // if (otherPoint1) {
- // otherPoint.x = otherPoint1.x;
- // otherPoint.y = otherPoint1.y;
- // }
- // if (otherPoint2) {
- // otherPoint.y = otherPoint2.y;
- // if (!otherPoint.hasOwnProperty("x")) {
- // otherPoint.x = otherPoint2.x;
- // }
- // }
- // if (otherPoint.hasOwnProperty("x") && otherPoint.hasOwnProperty("y")) {
- // elementService.execute(otherPoint, point);
- // } else {
- // elementService.hideAll();
- // }
- // }
- showElementLine(point) {
- let otherPoint1 = null;
- let otherPoint2 = null;
- if (listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdX) {
- otherPoint1 = dataService.getRoadPoint(
- listenLayer.modifyPoint.linkedRoadPointIdX
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedCurveRoadPointIdX
- ) {
- otherPoint1 = dataService.getCurveRoadPoint(
- listenLayer.modifyPoint.linkedCurvePointIdX
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedPointIdX
- ) {
- otherPoint1 = dataService.getPoint(
- listenLayer.modifyPoint.linkedPointIdX
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedCurvePointIdX
- ) {
- otherPoint1 = dataService.getCurvePoint(
- listenLayer.modifyPoint.linkedCurvePointIdX
- );
- }
- if (listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdY) {
- otherPoint2 = dataService.getRoadPoint(
- listenLayer.modifyPoint.linkedRoadPointIdY
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedCurvePointIdY
- ) {
- otherPoint2 = dataService.getCurveRoadPoint(
- listenLayer.modifyPoint.linkedCurvePointIdY
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedPointIdY
- ) {
- otherPoint2 = dataService.getPoint(
- listenLayer.modifyPoint.linkedPointIdY
- );
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedCurvePointIdY
- ) {
- otherPoint2 = dataService.getCurvePoint(
- listenLayer.modifyPoint.linkedCurvePointIdY
- );
- }
- let otherPoint = {};
- if (otherPoint1) {
- otherPoint.x = otherPoint1.x;
- otherPoint.y = otherPoint1.y;
- }
- if (otherPoint2) {
- otherPoint.y = otherPoint2.y;
- if (!otherPoint.hasOwnProperty("x")) {
- otherPoint.x = otherPoint2.x;
- }
- }
- elementService.execute(otherPoint, point);
- }
- }
|