Layer.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. import Load from "./Load";
  2. import { stateService } from "./Service/StateService";
  3. import { elementService } from "./Service/ElementService";
  4. import { dataService } from "./Service/DataService";
  5. import { textService } from "./Service/TextService";
  6. import { historyService } from "./Service/HistoryService";
  7. import UIControl from "./Controls/UIControl";
  8. import { locationModeControl } from "./Controls/LocationModeControl";
  9. import { moveText } from "./Controls/MoveText";
  10. import { moveSVG } from "./Controls/MoveSVG";
  11. import { moveMagnifier } from "./Controls/MoveMagnifier";
  12. import { addRoad } from "./Controls/AddRoad";
  13. import { addCrossRoad } from "./Controls/AddCrossRoad";
  14. import { addLine } from "./Controls/AddLine";
  15. import { addPoint } from "./Controls/AddPoint";
  16. import { addCircle } from "./Controls/AddCircle";
  17. import { addText } from "./Controls/AddText";
  18. import { addMagnifier } from "./Controls/AddMagnifier";
  19. import { addSVG } from "./Controls/AddSVG";
  20. import { moveRoad } from "./Controls/MoveRoad";
  21. import { moveLine } from "./Controls/MoveLine";
  22. import { movePoint } from "./Controls/MovePoint";
  23. import { moveCircle } from "./Controls/MoveCircle";
  24. import { coordinate } from "./Coordinate";
  25. import Render from "./Renderer/Render";
  26. import { draw } from "./Renderer/Draw";
  27. import { listenLayer } from "./ListenLayer";
  28. import LayerEvents from "./enum/LayerEvents.js";
  29. import UIEvents from "./enum/UIEvents.js";
  30. import SelectState from "./enum/SelectState.js";
  31. import VectorType from "./enum/VectorType";
  32. import { mathUtil } from "./Util/MathUtil";
  33. import History from "./History/History";
  34. import mitt from "mitt";
  35. import { roadService } from "./Service/RoadService";
  36. import { edgeService } from "./Service/EdgeService";
  37. import { roadPointService } from "./Service/RoadPointService";
  38. import { curveRoadService } from "./Service/CurveRoadService";
  39. import { curveRoadPointService } from "./Service/CurveRoadPointService";
  40. import VectorCategory from "./enum/VectorCategory";
  41. import Settings from "./Settings";
  42. import Constant from "./Constant";
  43. import { uiService } from "./Service/UIService";
  44. import { imageService } from "./Service/ImageService";
  45. import VectorEvents from "./enum/VectorEvents";
  46. import { lineService } from "./Service/LineService";
  47. const minDragDis = 10;
  48. const minZoom = 20;
  49. const maxZoom = 800;
  50. export default class Layer {
  51. constructor(canvas, newsletter, graphicState) {
  52. this.canvas = canvas;
  53. this.load = new Load(this);
  54. this.uiControl = new UIControl(this, newsletter, graphicState);
  55. this.renderer = new Render(this);
  56. this.history = new History(this);
  57. this.coordinate = coordinate;
  58. this.mousePosition = null;
  59. this.dragging = false; // 当前是否正在拖拽
  60. this.start();
  61. Object.setPrototypeOf(Object.getPrototypeOf(this), mitt());
  62. }
  63. start() {
  64. if (this.canvas) {
  65. this.canvas.width = this.canvas.clientWidth;
  66. this.canvas.height = this.canvas.clientHeight;
  67. coordinate.init(this.canvas);
  68. draw.initContext(this.canvas);
  69. dataService.initVectorData();
  70. this.bindEvents();
  71. }
  72. window.vectorData = dataService.vectorData;
  73. }
  74. bindEvents() {
  75. this.canvas.addEventListener("contextmenu", function (e) {
  76. e.preventDefault();
  77. });
  78. this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
  79. this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this));
  80. this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
  81. this.canvas.addEventListener("touchstart", this.onMouseDown.bind(this));
  82. this.canvas.addEventListener("touchmove", this.onMouseMove.bind(this));
  83. this.canvas.addEventListener("touchend", this.onMouseUp.bind(this));
  84. this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
  85. this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
  86. this.canvas.addEventListener("resize", this.reSize.bind(this));
  87. document.addEventListener("keydown", this.onKeydown.bind(this));
  88. }
  89. reSize = function () {
  90. console.log("resize");
  91. coordinate.updateForCanvas();
  92. this.renderer.autoRedraw();
  93. };
  94. onMouseDown(e) {
  95. if (e instanceof TouchEvent) {
  96. this.startX = e.touches[0].pageX;
  97. this.startY = e.touches[0].pageY;
  98. this.lastX = e.touches[0].pageX;
  99. this.lastY = e.touches[0].pageY;
  100. } else {
  101. this.startX = e.offsetX || e.layerX;
  102. this.startY = e.offsetY || e.layerY;
  103. this.lastX = e.offsetX || e.layerX;
  104. this.lastY = e.offsetY || e.layerY;
  105. }
  106. let position = coordinate.getXYFromScreen({
  107. x: this.startX,
  108. y: this.startY,
  109. });
  110. // 右键
  111. if (e.button == 2) {
  112. this.stopAddVector();
  113. return;
  114. }
  115. this.dragging = false;
  116. //用于支持平板电脑
  117. listenLayer.start(position);
  118. let selectItem = stateService.getSelectItem();
  119. let focusItem = stateService.getFocusItem();
  120. this.setEventName("mouseDown");
  121. const eventName = stateService.getEventName();
  122. switch (eventName) {
  123. case LayerEvents.AddRoad:
  124. stateService.setEventName(LayerEvents.AddingRoad);
  125. addRoad.setNewRoadPoint("start", position);
  126. break;
  127. case LayerEvents.AddCurveRoad:
  128. stateService.setEventName(LayerEvents.AddingCurveRoad);
  129. addRoad.setNewRoadPoint("start", position);
  130. break;
  131. case LayerEvents.AddLine:
  132. stateService.setEventName(LayerEvents.AddingLine);
  133. addLine.setNewLinePoint(position);
  134. break;
  135. // case LayerEvents.AddCurveLine:
  136. // stateService.setEventName(LayerEvents.AddingCurveLine);
  137. // addLine.setNewLinePoint(position);
  138. // break;
  139. case LayerEvents.AddPoint:
  140. stateService.setEventName(LayerEvents.MovePoint);
  141. const newPoint = addPoint.buildPoint2(position);
  142. if (newPoint) {
  143. stateService.setSelectItem(
  144. newPoint.vectorId,
  145. VectorType.Point,
  146. SelectState.Select
  147. );
  148. this.history.save();
  149. this.renderer.autoRedraw();
  150. } else {
  151. if (Settings.basePointIds.length > 1) {
  152. this.uiControl.prompt({ msg: "请先选择基准点", time: 1000 });
  153. } else {
  154. this.uiControl.prompt({ msg: "请先添加基准点", time: 1000 });
  155. }
  156. // this.uiControl.prompt({ msg: '请先选择基准点', time: 1000 });
  157. }
  158. break;
  159. case LayerEvents.AddCircle:
  160. stateService.setEventName(LayerEvents.AddingCircle);
  161. addCircle.setCenter(position);
  162. break;
  163. case LayerEvents.AddText:
  164. stateService.setEventName(LayerEvents.MoveText);
  165. addText.buildText(position);
  166. stateService.setSelectItem(
  167. addText.newText.vectorId,
  168. VectorType.Text,
  169. SelectState.Select
  170. );
  171. addText.clear();
  172. break;
  173. case LayerEvents.AddSVG:
  174. stateService.setEventName(LayerEvents.MoveSVG);
  175. addSVG.buildSVG(position);
  176. addSVG.newSVG.setType(Settings.selectSVGType);
  177. stateService.setSelectItem(addSVG.newSVG.vectorId, VectorType.SVG, -1);
  178. addSVG.clear();
  179. break;
  180. case LayerEvents.AddMagnifier:
  181. stateService.setEventName(LayerEvents.MoveMagnifier);
  182. addMagnifier.buildMagnifier(position);
  183. stateService.setSelectItem(
  184. addMagnifier.newMagnifier.vectorId,
  185. VectorType.Magnifier,
  186. SelectState.Select
  187. );
  188. addMagnifier.clear();
  189. break;
  190. case VectorEvents.AddLane:
  191. if (selectItem && selectItem.dir && selectItem.vectorId) {
  192. let road = dataService.getRoad(selectItem.vectorId);
  193. if (road) {
  194. let roadLanCount = road.getLanesCount(selectItem.dir);
  195. if (selectItem.dir == "left") {
  196. roadService.updateForAddSubtractLanesCount(
  197. road.vectorId,
  198. roadLanCount + 1,
  199. selectItem.dir
  200. );
  201. } else {
  202. roadService.updateForAddSubtractLanesCount(
  203. road.vectorId,
  204. roadLanCount + 1,
  205. selectItem.dir
  206. );
  207. }
  208. } else {
  209. road = dataService.getCurveRoad(selectItem.vectorId);
  210. let curveRoadLanCount = road.getLanesCount(selectItem.dir);
  211. if (selectItem.dir == "left") {
  212. curveRoadService.updateForAddSubtractLanesCount(
  213. road.vectorId,
  214. curveRoadLanCount + 1,
  215. selectItem.dir
  216. );
  217. } else {
  218. curveRoadService.updateForAddSubtractLanesCount(
  219. road.vectorId,
  220. curveRoadLanCount + 1,
  221. selectItem.dir
  222. );
  223. }
  224. }
  225. stateService.clearEventName();
  226. this.history.save();
  227. this.renderer.autoRedraw();
  228. }
  229. break;
  230. case VectorEvents.DelLane:
  231. if (selectItem && selectItem.dir && selectItem.vectorId) {
  232. let road = dataService.getRoad(selectItem.vectorId);
  233. if (road) {
  234. let roadLanCount = road.getLanesCount(selectItem.dir);
  235. if (selectItem.dir == "left") {
  236. roadService.updateForAddSubtractLanesCount(
  237. road.vectorId,
  238. roadLanCount - 1,
  239. selectItem.dir
  240. );
  241. } else {
  242. roadService.updateForAddSubtractLanesCount(
  243. road.vectorId,
  244. roadLanCount - 1,
  245. selectItem.dir
  246. );
  247. }
  248. } else {
  249. road = dataService.getCurveRoad(selectItem.vectorId);
  250. let curveRoadLanCount = road.getLanesCount(selectItem.dir);
  251. if (selectItem.dir == "left") {
  252. curveRoadService.updateForAddSubtractLanesCount(
  253. road.vectorId,
  254. curveRoadLanCount - 1,
  255. selectItem.dir
  256. );
  257. } else {
  258. curveRoadService.updateForAddSubtractLanesCount(
  259. road.vectorId,
  260. curveRoadLanCount - 1,
  261. selectItem.dir
  262. );
  263. }
  264. }
  265. stateService.clearEventName();
  266. this.history.save();
  267. this.renderer.autoRedraw();
  268. }
  269. break;
  270. case VectorEvents.AddCrossPoint:
  271. if (focusItem && focusItem.vectorId) {
  272. if (focusItem.type == VectorType.CurveRoad) {
  273. const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
  274. let index = mathUtil.getIndexForCurvesPoints(
  275. position,
  276. curveRoad.points
  277. );
  278. if (index != -1) {
  279. curveRoadService.addCPoint(curveRoad, position, index);
  280. } else {
  281. const dis1 = mathUtil.getDistance(curveRoad.points[0], position);
  282. const dis2 = mathUtil.getDistance(
  283. curveRoad.points[curveRoad.points.length - 1],
  284. position
  285. );
  286. if (dis1 > dis2) {
  287. index = curveRoad.points.length - 2;
  288. } else {
  289. index = 1;
  290. }
  291. curveRoadService.addCPoint(curveRoad, position, index);
  292. }
  293. curveRoadService.setLanes(curveRoad.vectorId);
  294. // curveRoadService.updateForMovePoint(
  295. // curveRoad.points[index + 1].vectorId,
  296. // position
  297. // );
  298. } else if (focusItem.type == VectorType.Line) {
  299. let line = dataService.getLine(focusItem.vectorId);
  300. const weight = line.getWeight();
  301. let startPoint = dataService.getPoint(line.startId);
  302. let endPoint = dataService.getPoint(line.endId);
  303. dataService.deleteLine(focusItem.vectorId);
  304. let curveLine = lineService.createCurveLine(startPoint, endPoint);
  305. mathUtil.clonePoint(curveLine.points[1], position);
  306. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  307. curveLine.setWeight(weight);
  308. const style = line.getStyle();
  309. curveLine.setStyle(style);
  310. } else if (focusItem.type == VectorType.CurveLine) {
  311. let curveLine = dataService.getCurveLine(focusItem.vectorId);
  312. let index = mathUtil.getIndexForCurvesPoints(
  313. position,
  314. curveLine.points
  315. );
  316. if (index != -1) {
  317. lineService.addCPoint(position, index, focusItem.vectorId);
  318. } else {
  319. const dis1 = mathUtil.getDistance(curveLine.points[0], position);
  320. const dis2 = mathUtil.getDistance(
  321. curveLine.points[curveLine.points.length - 1],
  322. position
  323. );
  324. if (dis1 > dis2) {
  325. index = curveLine.points.length - 2;
  326. } else {
  327. index = 1;
  328. }
  329. lineService.addCPoint(position, index, focusItem.vectorId);
  330. }
  331. }
  332. stateService.clearEventName();
  333. this.history.save();
  334. this.renderer.autoRedraw();
  335. }
  336. break;
  337. case VectorEvents.MinusCrossPoint:
  338. if (selectItem && selectItem.vectorId) {
  339. const curvePoint = dataService.getCurveRoadPoint(selectItem.vectorId);
  340. if (curvePoint) {
  341. const curveRoad = dataService.getCurveRoad(curvePoint.parent);
  342. if (curveRoad.points.length > 3) {
  343. curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
  344. curveRoadService.setLanes(curveRoad.vectorId);
  345. stateService.clearEventName();
  346. }
  347. this.history.save();
  348. this.renderer.autoRedraw();
  349. }
  350. }
  351. break;
  352. }
  353. selectItem = stateService.getSelectItem();
  354. stateService.setDraggingItem(selectItem);
  355. stateService.clearFocusItem();
  356. this.uiControl.focusVector = null;
  357. // 清除上一个状态
  358. // 设置当前事件名称
  359. e.preventDefault();
  360. e.stopPropagation();
  361. }
  362. onMouseMove(e) {
  363. let X = e.offsetX || e.layerX;
  364. let Y = e.offsetY || e.layerY;
  365. if (e instanceof TouchEvent) {
  366. X = e.touches[0].pageX;
  367. Y = e.touches[0].pageY;
  368. //切换到缩放
  369. if (e.touches.length > 1) {
  370. //记录开始的两个触摸点的坐标
  371. if (!this.StorePage1 || !this.StorePage2) {
  372. this.onMouseUp(e);
  373. this.StorePage1 = { x: e.touches[0].pageX, y: e.touches[0].pageY };
  374. this.StorePage2 = { x: e.touches[1].pageX, y: e.touches[1].pageY };
  375. this.StoreMidePage = {
  376. x: (this.StorePage1.x + this.StorePage2.x) / 2,
  377. y: (this.StorePage1.y + this.StorePage2.y) / 2,
  378. };
  379. return;
  380. }
  381. const point1 = {
  382. x: e.touches[0].pageX,
  383. y: e.touches[0].pageY,
  384. };
  385. const point2 = {
  386. x: e.touches[1].pageX,
  387. y: e.touches[1].pageY,
  388. };
  389. let dis1 = mathUtil.getDistance(point1, point2) / 100;
  390. let dis2 = mathUtil.getDistance(this.StorePage1, this.StorePage2) / 100;
  391. let zoom = (coordinate.zoom * dis1) / dis2;
  392. this.zoomVector(this.StoreMidePage, zoom);
  393. mathUtil.clonePoint(this.StorePage1, point1);
  394. mathUtil.clonePoint(this.StorePage2, point2);
  395. return;
  396. }
  397. }
  398. let dx = X - this.lastX;
  399. let dy = Y - this.lastY;
  400. dx = dx * coordinate.ratio;
  401. dy = dy * coordinate.ratio;
  402. let position = coordinate.getXYFromScreen({
  403. x: X,
  404. y: Y,
  405. });
  406. this.mousePosition = {
  407. x: position.x,
  408. y: position.y,
  409. };
  410. const eventName = stateService.getEventName();
  411. if (
  412. !this.dragging &&
  413. Math.abs(X - this.startX) < minDragDis &&
  414. Math.abs(Y - this.startY) < minDragDis
  415. ) {
  416. return;
  417. }
  418. this.dragging = true;
  419. if (
  420. Math.abs(X - this.startX) > minDragDis ||
  421. Math.abs(Y - this.startY) > minDragDis
  422. ) {
  423. // 是否拖拽了
  424. if (eventName != null) {
  425. if (
  426. eventName == LayerEvents.MoveMagnifier &&
  427. stateService.getSelectItem().state != 0
  428. ) {
  429. } else {
  430. stateService.clearFocusItem();
  431. this.uiControl.focusVector = null;
  432. }
  433. }
  434. }
  435. // 是否需要重绘
  436. let needAutoRedraw = false;
  437. let point = null;
  438. this.lastX = X;
  439. this.lastY = Y;
  440. const draggingItem = stateService.getDraggingItem();
  441. switch (eventName) {
  442. case null:
  443. //监控
  444. needAutoRedraw = listenLayer.start(position);
  445. let seleteItem = stateService.getSelectItem();
  446. if (seleteItem != null) {
  447. console.log("选中:" + seleteItem.vectorId);
  448. } else {
  449. }
  450. break;
  451. case LayerEvents.PanBackGround:
  452. stateService.clearItems();
  453. let center = {};
  454. center.x =
  455. coordinate.center.x - (dx * coordinate.defaultZoom) / coordinate.zoom;
  456. center.y =
  457. coordinate.center.y + (dy * coordinate.defaultZoom) / coordinate.zoom;
  458. let tempCenter = {};
  459. mathUtil.clonePoint(tempCenter, coordinate.center);
  460. mathUtil.clonePoint(coordinate.center, center);
  461. let inScreen = imageService.backgroundImgVertexsInScreenXY();
  462. if (!inScreen) {
  463. dataService.setGridForPan();
  464. needAutoRedraw = true;
  465. } else {
  466. mathUtil.clonePoint(coordinate.center, tempCenter);
  467. }
  468. break;
  469. case LayerEvents.AddRoad:
  470. needAutoRedraw = true;
  471. listenLayer.start(position);
  472. if (listenLayer.modifyPoint) {
  473. position = {
  474. x: listenLayer.modifyPoint.x,
  475. y: listenLayer.modifyPoint.y,
  476. };
  477. }
  478. elementService.hideAll();
  479. //鼠标样式
  480. elementService.setPoint(position);
  481. elementService.showPoint();
  482. this.showElementLine(position, eventName);
  483. break;
  484. case LayerEvents.AddLine:
  485. needAutoRedraw = true;
  486. listenLayer.start(position);
  487. if (listenLayer.modifyPoint) {
  488. position = {
  489. x: listenLayer.modifyPoint.x,
  490. y: listenLayer.modifyPoint.y,
  491. };
  492. }
  493. elementService.hideAll();
  494. elementService.setPoint(position);
  495. elementService.showPoint();
  496. this.showElementLine(position, eventName);
  497. break;
  498. case LayerEvents.AddCurveLine:
  499. needAutoRedraw = true;
  500. listenLayer.start(position);
  501. if (listenLayer.modifyPoint) {
  502. position = {
  503. x: listenLayer.modifyPoint.x,
  504. y: listenLayer.modifyPoint.y,
  505. };
  506. }
  507. elementService.hideAll();
  508. elementService.setPoint(position);
  509. elementService.showPoint();
  510. this.showElementLine(position, eventName);
  511. break;
  512. case LayerEvents.AddCircle:
  513. needAutoRedraw = true;
  514. listenLayer.start(position);
  515. if (listenLayer.modifyPoint) {
  516. position = {
  517. x: listenLayer.modifyPoint.x,
  518. y: listenLayer.modifyPoint.y,
  519. };
  520. }
  521. elementService.hideAll();
  522. elementService.setPoint(position);
  523. elementService.showPoint();
  524. this.showElementLine(position);
  525. break;
  526. case LayerEvents.AddingRoad:
  527. needAutoRedraw = true;
  528. listenLayer.start(position);
  529. // listenLayer.start(position, {
  530. // exceptLineId: exceptLineId,
  531. // exceptPointId: exceptPointId,
  532. // addRoad.startInfo.linkedRoadId
  533. // addRoad.startInfo.linkedRoadPointId
  534. // });
  535. if (listenLayer.modifyPoint) {
  536. position = {
  537. x: listenLayer.modifyPoint.x,
  538. y: listenLayer.modifyPoint.y,
  539. };
  540. // console.log(
  541. // "LayerEvents.AddingRoad:" + JSON.stringify(listenLayer.modifyPoint)
  542. // );
  543. }
  544. elementService.execute(addRoad.startInfo.position, position);
  545. elementService.setPoint(position);
  546. elementService.setNewRoad(addRoad.startInfo.position, position);
  547. elementService.showNewRoad();
  548. addRoad.setNewRoadPoint("end", position);
  549. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  550. if (!addRoad.canAdd) {
  551. elementService.setNewRoadState("error");
  552. } else {
  553. elementService.setNewRoadState("normal");
  554. }
  555. elementService.showPoint();
  556. this.showElementLine(position, eventName);
  557. break;
  558. case LayerEvents.AddingLine:
  559. needAutoRedraw = true;
  560. let exceptLineId = null;
  561. let exceptPointId = null;
  562. if (addLine.newLine != null) {
  563. exceptLineId = addLine.newLine.vectorId;
  564. exceptPointId = addLine.newLine.endId;
  565. }
  566. listenLayer.start(position, {
  567. exceptLineId: exceptLineId,
  568. exceptPointId: exceptPointId,
  569. });
  570. if (listenLayer.modifyPoint) {
  571. position = {
  572. x: listenLayer.modifyPoint.x,
  573. y: listenLayer.modifyPoint.y,
  574. };
  575. }
  576. // elementService.execute(addLine.startInfo.position, position);
  577. // elementService.setPoint(position);
  578. if (addLine.newLine == null) {
  579. addLine.buildLine(position);
  580. } else {
  581. addLine.updateLine(position);
  582. }
  583. elementService.hideAll();
  584. elementService.setPoint(position);
  585. elementService.showPoint();
  586. this.showElementLine(position, eventName);
  587. break;
  588. case LayerEvents.AddingCurveLine:
  589. needAutoRedraw = true;
  590. let exceptCurveLineId = null;
  591. let exceptCurvePointId = null;
  592. if (addLine.newLine != null) {
  593. exceptCurveLineId = addLine.newLine.vectorId;
  594. exceptCurvePointId = addLine.newLine.endId;
  595. }
  596. listenLayer.start(position, {
  597. exceptCurveLineId: exceptCurveLineId,
  598. exceptCurvePointId: exceptCurvePointId,
  599. });
  600. if (listenLayer.modifyPoint) {
  601. position = {
  602. x: listenLayer.modifyPoint.x,
  603. y: listenLayer.modifyPoint.y,
  604. };
  605. }
  606. // elementService.execute(addLine.startInfo.position, position);
  607. // elementService.setPoint(position);
  608. if (addLine.newLine == null) {
  609. addLine.buildCurveLine(position);
  610. } else {
  611. addLine.updateCurveLine(position);
  612. }
  613. elementService.hideAll();
  614. elementService.setPoint(position);
  615. elementService.showPoint();
  616. this.showElementLine(position, eventName);
  617. break;
  618. case LayerEvents.AddingCircle:
  619. needAutoRedraw = true;
  620. let exceptCircleId = null;
  621. if (addCircle.newCircle != null) {
  622. exceptCircleId = addCircle.newCircle.vectorId;
  623. }
  624. listenLayer.start(position, { exceptCircleId: exceptCircleId });
  625. if (listenLayer.modifyPoint) {
  626. position = {
  627. x: listenLayer.modifyPoint.x,
  628. y: listenLayer.modifyPoint.y,
  629. };
  630. }
  631. if (addCircle.newCircle == null) {
  632. addCircle.buildCircle(position);
  633. } else {
  634. addCircle.updateCircle(position);
  635. }
  636. elementService.hideAll();
  637. elementService.setPoint(position);
  638. elementService.showPoint();
  639. this.showElementLine(position);
  640. break;
  641. case LayerEvents.MoveRoad:
  642. needAutoRedraw = true;
  643. //只允许拖拽一条公路
  644. let road = dataService.getRoad(draggingItem.vectorId);
  645. let start = dataService.getRoadPoint(road.startId);
  646. let end = dataService.getRoadPoint(road.endId);
  647. if (
  648. Object.keys(start.getParent()).length == 1 &&
  649. Object.keys(end.getParent()).length == 1
  650. ) {
  651. //拖拽的路只有一条
  652. moveRoad.moveRoad(
  653. draggingItem.vectorId,
  654. (dx * coordinate.defaultZoom) / coordinate.zoom,
  655. (dy * coordinate.defaultZoom) / coordinate.zoom
  656. );
  657. }
  658. break;
  659. case LayerEvents.MoveRoadPoint:
  660. point = dataService.getRoadPoint(draggingItem.vectorId);
  661. listenLayer.start(position, {
  662. exceptRoadPointId: draggingItem.vectorId,
  663. exceptRoadIds: point.parent,
  664. });
  665. if (
  666. listenLayer.modifyPoint &&
  667. (listenLayer.modifyPoint.linkedRoadPointId ||
  668. listenLayer.modifyPoint.linkedRoadId ||
  669. listenLayer.modifyPoint.linkedRoadPointIdX ||
  670. listenLayer.modifyPoint.linkedRoadPointIdY)
  671. ) {
  672. position = {
  673. x: listenLayer.modifyPoint.x,
  674. y: listenLayer.modifyPoint.y,
  675. };
  676. } else {
  677. listenLayer.modifyPoint = null;
  678. }
  679. let flag = moveRoad.moveingRoadPoint(
  680. draggingItem.vectorId,
  681. position,
  682. listenLayer.modifyPoint
  683. );
  684. if (!flag) {
  685. elementService.hideAll();
  686. } else {
  687. this.showElementLine(point, eventName);
  688. }
  689. needAutoRedraw = true;
  690. break;
  691. case LayerEvents.AddCurveRoad:
  692. needAutoRedraw = true;
  693. listenLayer.start(position);
  694. if (listenLayer.modifyPoint) {
  695. position = {
  696. x: listenLayer.modifyPoint.x,
  697. y: listenLayer.modifyPoint.y,
  698. };
  699. }
  700. elementService.hideAll();
  701. elementService.setPoint(position);
  702. elementService.showPoint();
  703. this.showElementLine(position, eventName);
  704. break;
  705. case LayerEvents.AddingCurveRoad:
  706. needAutoRedraw = true;
  707. listenLayer.start(position);
  708. if (listenLayer.modifyPoint) {
  709. position = {
  710. x: listenLayer.modifyPoint.x,
  711. y: listenLayer.modifyPoint.y,
  712. };
  713. }
  714. elementService.execute(addRoad.startInfo.position, position);
  715. elementService.setPoint(position);
  716. elementService.setNewRoad(addRoad.startInfo.position, position);
  717. elementService.showNewRoad();
  718. addRoad.setNewRoadPoint("end", position);
  719. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  720. if (!addRoad.canAdd) {
  721. elementService.setNewRoadState("error");
  722. } else {
  723. elementService.setNewRoadState("normal");
  724. }
  725. elementService.showPoint();
  726. this.showElementLine(position, eventName);
  727. break;
  728. case LayerEvents.MoveCurveRoad:
  729. needAutoRedraw = true;
  730. moveRoad.moveCurveRoad(
  731. draggingItem.vectorId,
  732. (dx * coordinate.defaultZoom) / coordinate.zoom,
  733. (dy * coordinate.defaultZoom) / coordinate.zoom
  734. );
  735. break;
  736. case LayerEvents.MoveCurveRoadPoint:
  737. if (!draggingItem || !draggingItem.vectorId) {
  738. return;
  739. }
  740. point = dataService.getCurveRoadPoint(draggingItem.vectorId);
  741. listenLayer.start(position, {
  742. exceptCurveRoadPointId: draggingItem.vectorId,
  743. exceptCurveRoadId: point.parent, //不会融合,所以parent只有一个
  744. });
  745. if (
  746. listenLayer.modifyPoint &&
  747. (listenLayer.modifyPoint.linkedCurveRoadPointId ||
  748. listenLayer.modifyPoint.linkedRoadPointId ||
  749. listenLayer.modifyPoint.linkedRoadId ||
  750. listenLayer.modifyPoint.linkedRoadPointIdX ||
  751. listenLayer.modifyPoint.linkedRoadPointIdY ||
  752. listenLayer.modifyPoint.linkedCurvePointIdX ||
  753. listenLayer.modifyPoint.linkedCurvePointIdY ||
  754. listenLayer.modifyPoint.linkedCurveRoadPointIdX)
  755. ) {
  756. position = {
  757. x: listenLayer.modifyPoint.x,
  758. y: listenLayer.modifyPoint.y,
  759. };
  760. }
  761. moveRoad.moveCurveRoadPoint(draggingItem.vectorId, position);
  762. this.showElementLine(point, eventName);
  763. needAutoRedraw = true;
  764. break;
  765. case LayerEvents.MoveCrossPoint:
  766. if (!draggingItem || !draggingItem.vectorId) {
  767. return;
  768. }
  769. moveRoad.moveCrossPoint(draggingItem.vectorId, position);
  770. needAutoRedraw = true;
  771. break;
  772. case LayerEvents.MoveEdge:
  773. moveRoad.moveEdge(draggingItem.vectorId, position);
  774. needAutoRedraw = true;
  775. break;
  776. case LayerEvents.MoveCurveEdge:
  777. if (listenLayer.modifyPoint) {
  778. moveRoad.moveCurveEdge(
  779. draggingItem.vectorId,
  780. listenLayer.modifyPoint.selectIndex,
  781. position
  782. );
  783. }
  784. needAutoRedraw = true;
  785. break;
  786. case LayerEvents.MoveLine:
  787. if (draggingItem != null) {
  788. let flag = moveLine.moveLine(
  789. draggingItem.vectorId,
  790. (dx * coordinate.defaultZoom) / coordinate.zoom,
  791. (dy * coordinate.defaultZoom) / coordinate.zoom
  792. );
  793. if (!flag) {
  794. this.lastX = this.lastX - dx / coordinate.ratio;
  795. this.lastY = this.lastY - dy / coordinate.ratio;
  796. }
  797. needAutoRedraw = true;
  798. }
  799. break;
  800. case LayerEvents.MovePoint:
  801. if (draggingItem != null) {
  802. point = dataService.getPoint(draggingItem.vectorId);
  803. listenLayer.start(position, {
  804. exceptPointId: draggingItem.vectorId,
  805. exceptLineIds: point.parent,
  806. });
  807. // if (listenLayer.modifyPoint) { //原本是这样的,不知用途,下面修改为了修复拖动点经过放大镜导致NaN或者错位
  808. if (
  809. listenLayer.modifyPoint &&
  810. listenLayer.modifyPoint.x &&
  811. listenLayer.modifyPoint.y
  812. ) {
  813. position = {
  814. x: listenLayer.modifyPoint.x,
  815. y: listenLayer.modifyPoint.y,
  816. };
  817. }
  818. movePoint.movePoint(position, draggingItem.vectorId);
  819. point = dataService.getPoint(draggingItem.vectorId);
  820. if (point.getCategory() == VectorCategory.Point.FixPoint) {
  821. moveText.moveFullText(position, point.linkedTextId);
  822. }
  823. needAutoRedraw = true;
  824. if (!point) {
  825. stateService.clearEventName();
  826. } else {
  827. this.showElementLine(point, eventName);
  828. }
  829. }
  830. break;
  831. case LayerEvents.MoveCurvePoint:
  832. if (draggingItem != null) {
  833. let curvePoint = dataService.getCurvePoint(draggingItem.vectorId);
  834. listenLayer.start(position, {
  835. exceptCurvePointId: draggingItem.vectorId,
  836. exceptCurveLineId: curvePoint.parent,
  837. });
  838. if (listenLayer.modifyPoint) {
  839. position = {
  840. x: listenLayer.modifyPoint.x,
  841. y: listenLayer.modifyPoint.y,
  842. };
  843. }
  844. movePoint.moveCurvePoint(position, draggingItem.vectorId);
  845. let curveLine = dataService.getCurveLine(curvePoint.getParent());
  846. this.showElementLine(curvePoint, eventName);
  847. needAutoRedraw = true;
  848. }
  849. break;
  850. case LayerEvents.MoveCurveLine:
  851. if (draggingItem != null) {
  852. moveLine.moveCurveLine(
  853. draggingItem.vectorId,
  854. (dx * coordinate.defaultZoom) / coordinate.zoom,
  855. (dy * coordinate.defaultZoom) / coordinate.zoom
  856. );
  857. needAutoRedraw = true;
  858. }
  859. break;
  860. case LayerEvents.MoveCircle:
  861. if (draggingItem != null) {
  862. if (draggingItem.state == -1) {
  863. moveCircle.moveFull(
  864. draggingItem.vectorId,
  865. (dx * coordinate.defaultZoom) / coordinate.zoom,
  866. (dy * coordinate.defaultZoom) / coordinate.zoom
  867. );
  868. } else if (
  869. draggingItem.state == 0 ||
  870. draggingItem.state == 1 ||
  871. draggingItem.state == 2 ||
  872. draggingItem.state == 3
  873. ) {
  874. moveCircle.movePoint(
  875. position,
  876. draggingItem.vectorId,
  877. draggingItem.state
  878. );
  879. } else {
  880. debugger;
  881. }
  882. needAutoRedraw = true;
  883. }
  884. break;
  885. case LayerEvents.MoveText:
  886. needAutoRedraw = true;
  887. if (draggingItem != null) {
  888. moveText.moveFullText(position, draggingItem.vectorId);
  889. }
  890. break;
  891. case LayerEvents.MoveSVG:
  892. needAutoRedraw = true;
  893. if (draggingItem != null) {
  894. if (draggingItem.state == -1) {
  895. moveSVG.moveFullSVG(position, draggingItem.vectorId);
  896. } else {
  897. moveSVG.movePoint(
  898. position,
  899. draggingItem.vectorId,
  900. draggingItem.state
  901. );
  902. }
  903. }
  904. break;
  905. case LayerEvents.MoveMagnifier:
  906. needAutoRedraw = true;
  907. if (draggingItem != null) {
  908. moveMagnifier.moveFullMagnifier(
  909. position,
  910. draggingItem.vectorId,
  911. draggingItem.state
  912. );
  913. }
  914. break;
  915. }
  916. if (needAutoRedraw) {
  917. this.renderer.autoRedraw();
  918. }
  919. }
  920. onMouseUp(e) {
  921. // 右键
  922. if (e.button == 2) {
  923. this.dragging = false;
  924. return;
  925. }
  926. let X = e.offsetX || e.layerX;
  927. let Y = e.offsetY || e.layerY;
  928. if (e instanceof TouchEvent) {
  929. X = this.lastX;
  930. Y = this.lastY;
  931. this.StorePage1 = null;
  932. this.StorePage2 = null;
  933. this.StoreMidePage = null;
  934. if (e.touches.length > 1) {
  935. this.dragging = false;
  936. return;
  937. }
  938. }
  939. let eventName = stateService.getEventName();
  940. const draggingItem = stateService.getDraggingItem();
  941. const selectItem = stateService.getSelectItem();
  942. let focusItem = null;
  943. if (!this.dragging && selectItem) {
  944. focusItem = {
  945. vectorId: selectItem.vectorId,
  946. type: selectItem.type,
  947. cursor: { x: this.lastX, y: this.lastY },
  948. dir: selectItem.dir,
  949. };
  950. stateService.setFocusItem(focusItem);
  951. this.uiControl.focusVector = focusItem;
  952. stateService.clearDraggingItem();
  953. } else {
  954. this.uiControl.focusVector = null;
  955. }
  956. this.dragging = false;
  957. let position = coordinate.getXYFromScreen({
  958. x: X,
  959. y: Y,
  960. });
  961. let needAutoRedraw = false;
  962. switch (eventName) {
  963. case null:
  964. if (e instanceof TouchEvent) {
  965. stateService.clearSelectItem();
  966. stateService.clearDraggingItem();
  967. this.uiControl.focusVector = null;
  968. this.renderer.autoRedraw();
  969. }
  970. return;
  971. case LayerEvents.PanBackGround:
  972. needAutoRedraw = true;
  973. stateService.clearFocusItem();
  974. this.uiControl.focusVector = null;
  975. this.uiControl.currentUI = null;
  976. Settings.selectBasePointId = null;
  977. break;
  978. case LayerEvents.MoveRoadPoint:
  979. if (!draggingItem || !draggingItem.vectorId) {
  980. break;
  981. }
  982. needAutoRedraw = true;
  983. elementService.hideAll();
  984. let point = dataService.getRoadPoint(draggingItem.vectorId);
  985. if (point) {
  986. listenLayer.start(point, {
  987. exceptRoadPointId: draggingItem.vectorId,
  988. exceptRoadIds: point.parent,
  989. });
  990. if (
  991. listenLayer.modifyPoint &&
  992. listenLayer.modifyPoint.hasOwnProperty("linkedRoadPointId")
  993. ) {
  994. moveRoad.moveTo(
  995. draggingItem.vectorId,
  996. listenLayer.modifyPoint.linkedRoadPointId
  997. );
  998. } else if (
  999. listenLayer.modifyPoint &&
  1000. (listenLayer.modifyPoint.linkedRoadPointIdX ||
  1001. listenLayer.modifyPoint.linkedRoadPointIdY)
  1002. ) {
  1003. mathUtil.clonePoint(point, listenLayer.modifyPoint);
  1004. } else if (
  1005. listenLayer.modifyPoint &&
  1006. listenLayer.modifyPoint.hasOwnProperty("linkedRoadId")
  1007. ) {
  1008. point = roadPointService.create({
  1009. x: listenLayer.modifyPoint.x,
  1010. y: listenLayer.modifyPoint.y,
  1011. });
  1012. roadService.splitRoad(
  1013. listenLayer.modifyPoint.linkedRoadId,
  1014. point.vectorId,
  1015. "start"
  1016. );
  1017. moveRoad.moveTo(draggingItem.vectorId, point.vectorId);
  1018. } else if (moveRoad.splitRoadId != null) {
  1019. roadService.splitRoad(
  1020. moveRoad.splitRoadId,
  1021. draggingItem.vectorId,
  1022. "start"
  1023. );
  1024. }
  1025. //draggingItem.vectorId所在的墙面与其他墙角相交
  1026. moveRoad.updateForAbsorbRoadPoints();
  1027. let parent = point.getParent();
  1028. for (let key in parent) {
  1029. roadService.setLanes(key);
  1030. }
  1031. this.history.save();
  1032. }
  1033. break;
  1034. // case LayerEvents.AddRoad:
  1035. // addRoad.setNewRoadPoint("start", position);
  1036. // break;
  1037. case LayerEvents.AddingRoad:
  1038. needAutoRedraw = true;
  1039. if (addRoad.canAdd) {
  1040. addRoad.buildRoad();
  1041. this.history.save();
  1042. elementService.hideAll();
  1043. }
  1044. break;
  1045. case LayerEvents.AddingLine:
  1046. if (Settings.selectLocationMode == Constant.freeLocationMode) {
  1047. this.uiControl.showConfirm();
  1048. }
  1049. needAutoRedraw = true;
  1050. addLine.finish(position);
  1051. this.updateForLocation();
  1052. addLine.clearVectorData();
  1053. this.history.save();
  1054. elementService.hideAll();
  1055. break;
  1056. case LayerEvents.AddingCurveLine:
  1057. needAutoRedraw = true;
  1058. addLine.finishCurveLine(position);
  1059. addLine.clearVectorData();
  1060. this.history.save();
  1061. elementService.hideAll();
  1062. break;
  1063. case LayerEvents.AddingCircle:
  1064. needAutoRedraw = true;
  1065. addCircle.finish(position);
  1066. addCircle.clear();
  1067. this.history.save();
  1068. elementService.hideAll();
  1069. break;
  1070. case LayerEvents.MoveText:
  1071. needAutoRedraw = true;
  1072. this.history.save();
  1073. elementService.hideAll();
  1074. break;
  1075. case LayerEvents.MoveSVG:
  1076. needAutoRedraw = true;
  1077. this.history.save();
  1078. elementService.hideAll();
  1079. break;
  1080. case LayerEvents.MoveMagnifier:
  1081. needAutoRedraw = true;
  1082. this.history.save();
  1083. elementService.hideAll();
  1084. //拖拽完放大镜后需要重新打开
  1085. // focusItem = {
  1086. // vectorId: selectItem.vectorId,
  1087. // type: selectItem.type,
  1088. // cursor: { x: this.lastX, y: this.lastY },
  1089. // dir: selectItem.dir,
  1090. // };
  1091. // this.uiControl.focusVector = focusItem;
  1092. // stateService.setFocusItem(focusItem);
  1093. break;
  1094. case LayerEvents.MoveSVG:
  1095. needAutoRedraw = true;
  1096. this.history.save();
  1097. elementService.hideAll();
  1098. break;
  1099. case LayerEvents.AddingCurveRoad:
  1100. needAutoRedraw = true;
  1101. if (addRoad.canAdd) {
  1102. addRoad.buildCurveRoad();
  1103. this.history.save();
  1104. elementService.hideAll();
  1105. }
  1106. break;
  1107. case LayerEvents.MoveRoad:
  1108. needAutoRedraw = true;
  1109. this.history.save();
  1110. break;
  1111. case LayerEvents.MoveCurveRoad:
  1112. needAutoRedraw = true;
  1113. this.history.save();
  1114. break;
  1115. case LayerEvents.MoveCurveRoadPoint:
  1116. needAutoRedraw = true;
  1117. if (
  1118. listenLayer.modifyPoint &&
  1119. listenLayer.modifyPoint.linkedCurveRoadPointId
  1120. ) {
  1121. let curveRoadPoint1 = dataService.getCurveRoadPoint(
  1122. listenLayer.modifyPoint.linkedCurveRoadPointId
  1123. );
  1124. let curveRoadPoint2 = dataService.getCurveRoadPoint(
  1125. draggingItem.vectorId
  1126. );
  1127. if (
  1128. listenLayer.modifyPoint.linkedCurveRoadPointId !=
  1129. draggingItem.vectorId &&
  1130. curveRoadPoint1.getParent() == curveRoadPoint2.getParent()
  1131. ) {
  1132. curveRoadPointService.deleteCurveRoadPoint(
  1133. listenLayer.modifyPoint.linkedCurveRoadPointId
  1134. );
  1135. }
  1136. }
  1137. this.history.save();
  1138. break;
  1139. case LayerEvents.MoveCrossPoint:
  1140. needAutoRedraw = true;
  1141. this.history.save();
  1142. break;
  1143. case LayerEvents.MoveEdge:
  1144. needAutoRedraw = true;
  1145. this.history.save();
  1146. break;
  1147. case LayerEvents.MoveCurveEdge:
  1148. needAutoRedraw = true;
  1149. this.history.save();
  1150. break;
  1151. case LayerEvents.MoveLine:
  1152. needAutoRedraw = true;
  1153. this.history.save();
  1154. break;
  1155. case LayerEvents.MovePoint:
  1156. needAutoRedraw = true;
  1157. if (draggingItem && draggingItem.vectorId) {
  1158. movePoint.finish(draggingItem.vectorId);
  1159. uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
  1160. }
  1161. this.history.save();
  1162. elementService.hideAll();
  1163. break;
  1164. case LayerEvents.MoveCurvePoint:
  1165. needAutoRedraw = true;
  1166. if (
  1167. listenLayer.modifyPoint &&
  1168. listenLayer.modifyPoint.linkedCurvePointId
  1169. ) {
  1170. let curvePoint1 = dataService.getCurvePoint(
  1171. listenLayer.modifyPoint.linkedCurvePointId
  1172. );
  1173. let curvePoint2 = dataService.getCurvePoint(draggingItem.vectorId);
  1174. if (
  1175. listenLayer.modifyPoint.linkedCurvePointId !=
  1176. draggingItem.vectorId &&
  1177. curvePoint1.getParent() == curvePoint2.getParent()
  1178. ) {
  1179. lineService.deleteCrossPointForCurveLine(
  1180. listenLayer.modifyPoint.linkedCurvePointId,
  1181. curvePoint1.getParent()
  1182. );
  1183. }
  1184. }
  1185. this.history.save();
  1186. break;
  1187. case LayerEvents.MoveCurveLine:
  1188. needAutoRedraw = true;
  1189. this.history.save();
  1190. break;
  1191. case LayerEvents.MoveCircle:
  1192. needAutoRedraw = true;
  1193. this.history.save();
  1194. break;
  1195. case LayerEvents.AddPoint:
  1196. if (
  1197. (Settings.selectBasePointId != null &&
  1198. (Settings.selectLocationMode == Constant.angleLocationMode ||
  1199. Settings.selectLocationMode == Constant.allLocationMode)) ||
  1200. (Settings.baseLineId != null &&
  1201. Settings.selectLocationMode == Constant.normalLocationMode)
  1202. ) {
  1203. this.uiControl.showConfirm();
  1204. needAutoRedraw = true;
  1205. elementService.hideAll();
  1206. }
  1207. break;
  1208. case LayerEvents.AddRoadTemplate:
  1209. addCrossRoad.build(position);
  1210. this.history.save();
  1211. this.renderer.autoRedraw();
  1212. break;
  1213. }
  1214. this.setEventName("mouseUp");
  1215. stateService.clearDraggingItem();
  1216. if (needAutoRedraw) {
  1217. this.renderer.autoRedraw();
  1218. }
  1219. }
  1220. onWheel(e) {
  1221. e.preventDefault();
  1222. const type = e.type;
  1223. if (type == "DOMMouseScroll" || type == "mousewheel") {
  1224. // 当在canvas用滚轮滚动时
  1225. const delta = e.wheelDelta
  1226. ? (e.wheelDelta / 120) * 20
  1227. : (-(e.detail || 0) / 3) * 20;
  1228. const zoom = coordinate.zoom + delta;
  1229. let X = e.offsetX || e.layerX;
  1230. let Y = e.offsetY || e.layerY;
  1231. this.zoomVector(
  1232. {
  1233. x: X,
  1234. y: Y,
  1235. },
  1236. zoom
  1237. );
  1238. }
  1239. }
  1240. zoomVector(position, zoom) {
  1241. if (zoom < minZoom || zoom > maxZoom) {
  1242. return;
  1243. }
  1244. let tempCenter = {};
  1245. mathUtil.clonePoint(tempCenter, coordinate.center);
  1246. let tempZoom = coordinate.zoom;
  1247. coordinate.updateZoom(position, zoom);
  1248. let inScreen = imageService.backgroundImgVertexsInScreenXY();
  1249. if (!inScreen) {
  1250. dataService.setGridForZoom();
  1251. this.renderer.autoRedraw();
  1252. } else {
  1253. mathUtil.clonePoint(coordinate.center, tempCenter);
  1254. coordinate.zoom = tempZoom;
  1255. }
  1256. }
  1257. setEventName(eventType) {
  1258. let eventName = stateService.getEventName();
  1259. if (eventType == "mouseDown") {
  1260. if (eventName == null) {
  1261. const selectItem = stateService.getSelectItem();
  1262. if (selectItem == null) {
  1263. stateService.setEventName(LayerEvents.PanBackGround);
  1264. } else if (selectItem.type == VectorType.Road) {
  1265. stateService.setEventName(LayerEvents.MoveRoad);
  1266. } else if (selectItem.type == VectorType.RoadPoint) {
  1267. stateService.setEventName(LayerEvents.MoveRoadPoint);
  1268. } else if (selectItem.type == VectorType.CurveRoad) {
  1269. stateService.setEventName(LayerEvents.MoveCurveRoad);
  1270. } else if (selectItem.type == VectorType.CurveRoadPoint) {
  1271. stateService.setEventName(LayerEvents.MoveCurveRoadPoint);
  1272. } else if (selectItem.type == VectorType.CrossPoint) {
  1273. stateService.setEventName(LayerEvents.MoveCrossPoint);
  1274. } else if (selectItem.type == VectorType.RoadEdge) {
  1275. stateService.setEventName(LayerEvents.MoveEdge);
  1276. } else if (selectItem.type == VectorType.CurveRoadEdge) {
  1277. stateService.setEventName(LayerEvents.MoveCurveEdge);
  1278. } else if (selectItem.type == VectorType.Point) {
  1279. stateService.setEventName(LayerEvents.MovePoint);
  1280. } else if (selectItem.type == VectorType.Line) {
  1281. stateService.setEventName(LayerEvents.MoveLine);
  1282. } else if (selectItem.type == VectorType.CurvePoint) {
  1283. stateService.setEventName(LayerEvents.MoveCurvePoint);
  1284. } else if (selectItem.type == VectorType.CurveLine) {
  1285. stateService.setEventName(LayerEvents.MoveCurveLine);
  1286. } else if (selectItem.type == VectorType.Circle) {
  1287. stateService.setEventName(LayerEvents.MoveCircle);
  1288. } else if (selectItem.type == VectorType.Text) {
  1289. stateService.setEventName(LayerEvents.MoveText);
  1290. } else if (selectItem.type == VectorType.Magnifier) {
  1291. stateService.setEventName(LayerEvents.MoveMagnifier);
  1292. } else if (selectItem.type == VectorType.SVG) {
  1293. stateService.setEventName(LayerEvents.MoveSVG);
  1294. }
  1295. }
  1296. } else if (eventType == "mouseUp") {
  1297. if (eventName == LayerEvents.AddingRoad) {
  1298. if (Settings.isMobile) {
  1299. stateService.clearEventName();
  1300. this.exit();
  1301. } else {
  1302. stateService.setEventName(LayerEvents.AddRoad);
  1303. }
  1304. } else if (eventName == LayerEvents.AddingLine) {
  1305. if (Settings.isMobile) {
  1306. if (Settings.selectLocationMode == Constant.freeLocationMode) {
  1307. stateService.setEventName(LayerEvents.AddLine);
  1308. } else {
  1309. stateService.clearEventName();
  1310. this.exit();
  1311. uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
  1312. }
  1313. } else {
  1314. stateService.setEventName(LayerEvents.AddLine);
  1315. }
  1316. } else if (eventName == LayerEvents.AddingCurveRoad) {
  1317. if (Settings.isMobile) {
  1318. stateService.clearEventName();
  1319. this.exit();
  1320. } else {
  1321. stateService.setEventName(LayerEvents.AddCurveRoad);
  1322. }
  1323. } else if (eventName == LayerEvents.AddLine) {
  1324. stateService.setEventName(LayerEvents.AddingLine);
  1325. } else if (
  1326. (eventName == LayerEvents.AddPoint &&
  1327. Settings.selectBasePointId != null &&
  1328. (Settings.selectLocationMode == Constant.angleLocationMode ||
  1329. Settings.selectLocationMode == Constant.allLocationMode)) ||
  1330. (eventName == LayerEvents.AddPoint &&
  1331. Settings.baseLineId != null &&
  1332. Settings.selectLocationMode == Constant.normalLocationMode)
  1333. ) {
  1334. } else {
  1335. stateService.clearEventName();
  1336. }
  1337. }
  1338. }
  1339. exit() {
  1340. stateService.clear();
  1341. this.uiControl.clearUI();
  1342. this.uiControl.focusVector = null;
  1343. this.uiControl.currentUI = null;
  1344. }
  1345. stopAddVector() {
  1346. let eventName = stateService.getEventName();
  1347. if (
  1348. eventName != LayerEvents.AddingRoad &&
  1349. eventName != LayerEvents.AddingLine
  1350. ) {
  1351. stateService.clearEventName();
  1352. } else if (eventName == LayerEvents.AddingRoad) {
  1353. stateService.setEventName(LayerEvents.AddRoad);
  1354. } else if (eventName == LayerEvents.AddingLine) {
  1355. stateService.setEventName(LayerEvents.AddLine);
  1356. }
  1357. addLine.clear(); //之前会保留category
  1358. this.uiControl.clearUI();
  1359. elementService.hideAll();
  1360. this.renderer.autoRedraw();
  1361. }
  1362. initLocation() {
  1363. Settings.baseLineId = null;
  1364. this.uiControl.graphicStateUI.canAngleLocationMode = false;
  1365. this.uiControl.graphicStateUI.canAllLocationMode = false;
  1366. this.uiControl.graphicStateUI.canVerticalMeasure = false;
  1367. this.uiControl.graphicStateUI.existsBaseLine = false;
  1368. }
  1369. //更新定位信息
  1370. updateForLocation() {
  1371. if (Settings.baseLineId) {
  1372. this.uiControl.graphicStateUI.canAngleLocationMode = true;
  1373. this.uiControl.graphicStateUI.canAllLocationMode = true;
  1374. this.uiControl.graphicStateUI.existsBaseLine = true;
  1375. this.uiControl.graphicStateUI.canVerticalMeasure = true;
  1376. } else {
  1377. this.uiControl.graphicStateUI.canAngleLocationMode = false;
  1378. this.uiControl.graphicStateUI.canAllLocationMode = false;
  1379. this.uiControl.graphicStateUI.existsBaseLine = false;
  1380. this.uiControl.graphicStateUI.canVerticalMeasure = false;
  1381. }
  1382. }
  1383. // showElementLine(point, eventName) {
  1384. // let otherPoint1 = null;
  1385. // let otherPoint2 = null;
  1386. // if (
  1387. // listenLayer.modifyPoint &&
  1388. // listenLayer.modifyPoint.linkedRoadPointIdX &&
  1389. // (eventName == LayerEvents.AddingRoad ||
  1390. // eventName == LayerEvents.MoveRoadPoint ||
  1391. // eventName == LayerEvents.AddRoad)
  1392. // ) {
  1393. // otherPoint1 = dataService.getRoadPoint(
  1394. // listenLayer.modifyPoint.linkedRoadPointIdX
  1395. // );
  1396. // } else if (
  1397. // listenLayer.modifyPoint &&
  1398. // listenLayer.modifyPoint.linkedCurveRoadPointIdX &&
  1399. // (eventName == LayerEvents.AddingCurveRoad ||
  1400. // eventName == LayerEvents.MoveCurveRoadPoint ||
  1401. // eventName == LayerEvents.AddCurveRoad)
  1402. // ) {
  1403. // otherPoint1 = dataService.getCurveRoadPoint(
  1404. // listenLayer.modifyPoint.linkedCurvePointIdX
  1405. // );
  1406. // } else if (
  1407. // listenLayer.modifyPoint &&
  1408. // listenLayer.modifyPoint.linkedPointIdX &&
  1409. // (eventName == LayerEvents.AddLine || eventName == LayerEvents.MovePoint)
  1410. // ) {
  1411. // otherPoint1 = dataService.getPoint(
  1412. // listenLayer.modifyPoint.linkedPointIdX
  1413. // );
  1414. // } else if (
  1415. // listenLayer.modifyPoint &&
  1416. // listenLayer.modifyPoint.linkedCurvePointIdX &&
  1417. // (eventName == LayerEvents.AddCurveLine ||
  1418. // eventName == LayerEvents.MoveCurvePoint)
  1419. // ) {
  1420. // otherPoint1 = dataService.getCurvePoint(
  1421. // listenLayer.modifyPoint.linkedCurvePointIdX
  1422. // );
  1423. // }
  1424. // if (
  1425. // listenLayer.modifyPoint &&
  1426. // listenLayer.modifyPoint.linkedRoadPointIdY &&
  1427. // (eventName == LayerEvents.AddingRoad ||
  1428. // eventName == LayerEvents.MoveRoadPoint ||
  1429. // eventName == LayerEvents.AddRoad)
  1430. // ) {
  1431. // otherPoint2 = dataService.getRoadPoint(
  1432. // listenLayer.modifyPoint.linkedRoadPointIdY
  1433. // );
  1434. // } else if (
  1435. // listenLayer.modifyPoint &&
  1436. // listenLayer.modifyPoint.linkedCurvePointIdY &&
  1437. // (eventName == LayerEvents.AddingCurveRoad ||
  1438. // eventName == LayerEvents.MoveCurveRoadPoint ||
  1439. // eventName == LayerEvents.AddCurveRoad)
  1440. // ) {
  1441. // otherPoint2 = dataService.getCurveRoadPoint(
  1442. // listenLayer.modifyPoint.linkedCurvePointIdY
  1443. // );
  1444. // } else if (
  1445. // listenLayer.modifyPoint &&
  1446. // listenLayer.modifyPoint.linkedPointIdY &&
  1447. // (eventName == LayerEvents.AddLine || eventName == LayerEvents.MovePoint)
  1448. // ) {
  1449. // otherPoint2 = dataService.getPoint(
  1450. // listenLayer.modifyPoint.linkedPointIdY
  1451. // );
  1452. // } else if (
  1453. // listenLayer.modifyPoint &&
  1454. // listenLayer.modifyPoint.linkedCurvePointIdY &&
  1455. // (eventName == LayerEvents.AddCurveLine ||
  1456. // eventName == LayerEvents.MoveCurvePoint)
  1457. // ) {
  1458. // otherPoint2 = dataService.getCurvePoint(
  1459. // listenLayer.modifyPoint.linkedCurvePointIdY
  1460. // );
  1461. // }
  1462. // let otherPoint = {};
  1463. // if (otherPoint1) {
  1464. // otherPoint.x = otherPoint1.x;
  1465. // otherPoint.y = otherPoint1.y;
  1466. // }
  1467. // if (otherPoint2) {
  1468. // otherPoint.y = otherPoint2.y;
  1469. // if (!otherPoint.hasOwnProperty("x")) {
  1470. // otherPoint.x = otherPoint2.x;
  1471. // }
  1472. // }
  1473. // if (otherPoint.hasOwnProperty("x") && otherPoint.hasOwnProperty("y")) {
  1474. // elementService.execute(otherPoint, point);
  1475. // } else {
  1476. // elementService.hideAll();
  1477. // }
  1478. // }
  1479. showElementLine(point) {
  1480. let otherPoint1 = null;
  1481. let otherPoint2 = null;
  1482. if (listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdX) {
  1483. otherPoint1 = dataService.getRoadPoint(
  1484. listenLayer.modifyPoint.linkedRoadPointIdX
  1485. );
  1486. } else if (
  1487. listenLayer.modifyPoint &&
  1488. listenLayer.modifyPoint.linkedCurveRoadPointIdX
  1489. ) {
  1490. otherPoint1 = dataService.getCurveRoadPoint(
  1491. listenLayer.modifyPoint.linkedCurvePointIdX
  1492. );
  1493. } else if (
  1494. listenLayer.modifyPoint &&
  1495. listenLayer.modifyPoint.linkedPointIdX
  1496. ) {
  1497. otherPoint1 = dataService.getPoint(
  1498. listenLayer.modifyPoint.linkedPointIdX
  1499. );
  1500. } else if (
  1501. listenLayer.modifyPoint &&
  1502. listenLayer.modifyPoint.linkedCurvePointIdX
  1503. ) {
  1504. otherPoint1 = dataService.getCurvePoint(
  1505. listenLayer.modifyPoint.linkedCurvePointIdX
  1506. );
  1507. }
  1508. if (listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdY) {
  1509. otherPoint2 = dataService.getRoadPoint(
  1510. listenLayer.modifyPoint.linkedRoadPointIdY
  1511. );
  1512. } else if (
  1513. listenLayer.modifyPoint &&
  1514. listenLayer.modifyPoint.linkedCurvePointIdY
  1515. ) {
  1516. otherPoint2 = dataService.getCurveRoadPoint(
  1517. listenLayer.modifyPoint.linkedCurvePointIdY
  1518. );
  1519. } else if (
  1520. listenLayer.modifyPoint &&
  1521. listenLayer.modifyPoint.linkedPointIdY
  1522. ) {
  1523. otherPoint2 = dataService.getPoint(
  1524. listenLayer.modifyPoint.linkedPointIdY
  1525. );
  1526. } else if (
  1527. listenLayer.modifyPoint &&
  1528. listenLayer.modifyPoint.linkedCurvePointIdY
  1529. ) {
  1530. otherPoint2 = dataService.getCurvePoint(
  1531. listenLayer.modifyPoint.linkedCurvePointIdY
  1532. );
  1533. }
  1534. let otherPoint = {};
  1535. if (otherPoint1) {
  1536. otherPoint.x = otherPoint1.x;
  1537. otherPoint.y = otherPoint1.y;
  1538. }
  1539. if (otherPoint2) {
  1540. otherPoint.y = otherPoint2.y;
  1541. if (!otherPoint.hasOwnProperty("x")) {
  1542. otherPoint.x = otherPoint2.x;
  1543. }
  1544. }
  1545. elementService.execute(otherPoint, point);
  1546. }
  1547. //测试用
  1548. onKeydown(e) {
  1549. let focusItem = stateService.getFocusItem();
  1550. if (focusItem) {
  1551. console.log("键盘(foucus有效):" + e.code);
  1552. //添加固定点
  1553. if (e.code == "KeyQ") {
  1554. uiService.setSelectPointCategory(VectorCategory.Point.FixPoint);
  1555. stateService.setEventName(LayerEvents.AddPoint);
  1556. }
  1557. //一键测量
  1558. if (e.code == "KeyA") {
  1559. locationModeControl.setAngle();
  1560. this.renderer.autoRedraw();
  1561. this.history.save();
  1562. }
  1563. }
  1564. }
  1565. }