Pan.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. //CLASS:控制平移。
  2. function Pan(layer) {
  3. this.layer = layer;
  4. this.calculateLine = this.layer.calculateLine;
  5. this.calculateElement = this.layer.calculateElement;
  6. this.div = this.layer.div;
  7. this.currentState = this.layer.currentState;
  8. this.previousState = this.layer.previousState;
  9. this.calculateElement = this.layer.calculateElement;
  10. this.active();
  11. //区分双击和单击
  12. this._doubleclick = false;
  13. //拖拽背景
  14. this.f_draggingBackGround = false;
  15. //拖拽墙
  16. this.f_draggingWallLine = false;
  17. //拖拽楼梯面
  18. this.f_draggingStairLine = false;
  19. //拖拽墙角
  20. this.f_draggingWallCorner = false;
  21. //拖拽楼梯角
  22. this.f_draggingStairCorner = false;
  23. //拖拽门或窗等元素
  24. this.f_draggingSymbol = false;
  25. //拖拽symbol的端点
  26. this.f_draggingEndpoint = false;
  27. //拖拽旋转梯角
  28. this.f_draggingSpiralCorner = false;
  29. //拖拽旋转梯
  30. this.f_draggingSpiralPlane = false;
  31. //修建墙
  32. this.f_buildingWall = false;
  33. //修建隔断
  34. this.f_buildingPartition = false;
  35. //修建直梯
  36. this.f_buildingWinderStair = false;
  37. //修建螺旋梯
  38. this.f_buildingSpiral = false;
  39. //添加symbol,比如:门或者窗户等
  40. this.f_buildingSymbol = false;
  41. //用来判断拖拽函数调用了几次,如果少于2次,则弹出编辑框
  42. this.dragging = { count: 0, type: null };
  43. this.build = this.layer.build;
  44. this.select = this.layer.select;
  45. this.data2d = this.layer.data2d;
  46. this.move = this.layer.move;
  47. this.lastPoint = {};
  48. this.diffX = 0;
  49. this.diffY = 0;
  50. this.addNew();
  51. //控制显示编辑wall
  52. this.editwall = null;
  53. this.ajustEndPointForWall = null;
  54. };
  55. Pan.prototype.startPan = (function() {
  56. var strategy = {
  57. //建立墙或隔断
  58. wall: function (args) {
  59. this.layer.div.style.cursor = "crosshair";
  60. if ((this.build.buildwallState == 1 || this.build.buildwallState == 2) &&
  61. this.currentState.selectWallSet != null
  62. ) {
  63. this.build.buildwallState = null;
  64. var point = this.build.adjustPoint(args.point);
  65. this.build.temp_buildwallId != null && (
  66. this.layer.vectors[this.build.temp_buildwallId].geometry.points[1] = args.point
  67. );
  68. this.build.BuildingWall(point);
  69. this.layer.vectors[this.build.buildwallId].geometry.endLines = this.build.getRelaEndLines();
  70. this.ajustEndPointForWall = this.currentState.selectWallSet.id + ";" + this.build.buildwallId;
  71. this.build.finishWall();
  72. } else { //开始画墙
  73. this.build.buildwallState = 2;
  74. this.build.BuildingWall(args.point);
  75. }
  76. this.layer.control.refreshCanvas = true;
  77. },
  78. WinderStair: function (args) {
  79. this.layer.div.style.cursor = "crosshair";
  80. this.f_buildingWinderStair = true;
  81. if (this.build.buildwallState == 1) {
  82. this.build.buildwallState = 2;
  83. }
  84. this.build.BuildingWinderStair(args.point);
  85. },
  86. Spiral: function (args) {
  87. this.layer.div.style.cursor = "crosshair";
  88. this.build.BuildingSpiral(args.point);
  89. this.currentState.startbuild = null;
  90. },
  91. __default: function (args) {
  92. if (this.layer.build.tryAddSymbol == null) {
  93. this.f_draggingBackGround = false;
  94. this.f_draggingSpiralPlane = false;
  95. this.f_draggingWallCorner = false;
  96. this.f_draggingWallLine = false;
  97. this.f_draggingSpiralCorner = false;
  98. this.f_draggingStairLine = false;
  99. this.f_draggingStairCorner = false;
  100. if (this.currentState.selectWallSet != null) {
  101. this.f_draggingWallCorner = this.currentState.selectWallSet.type == 0; // 当前选择墙角
  102. this.f_draggingWallLine = this.currentState.selectWallSet.type == 1; // 当前选择墙面
  103. } else if (this.currentState.selectStairSet == null) {
  104. this.f_draggingBackGround = true;
  105. } else if (this.currentState.selectStairSet.geoType == "Spiral") {
  106. this.f_draggingSpiralCorner = this.currentState.selectStairSet.type == 0;
  107. this.f_draggingSpiralPlane = this.currentState.selectStairSet.type == 1
  108. } else {
  109. this.f_draggingStairCorner = this.currentState.selectStairSet.type == 0; // 当前选择楼梯角
  110. this.f_draggingStairLine = this.currentState.selectStairSet.type == 0; // 当前选择楼梯面
  111. }
  112. // this.f_draggingBackGround = true;
  113. }
  114. console.log(this.currentState.selectWallSet)
  115. //当前选择墙面
  116. if (this.currentState.selectWallSet != null && this.currentState.selectWallSet.type == 1) {
  117. this.f_draggingBackGround = false;
  118. this.f_draggingWallLine = true;
  119. this.f_draggingWallCorner = false;
  120. this.select.f_selectWallLine = true;
  121. if (this.layer.build.tryAddSymbol != null) {
  122. this.select.convertTrue(this.layer.build.tryAddSymbol);
  123. this.layer.build.tryAddSymbol = null;
  124. this.f_draggingWallLine = false;
  125. } else if (this.select.f_selectSymbol) {
  126. this.f_draggingWallLine = false;
  127. this.f_draggingSymbol = true;
  128. this.select.f_selectWallLine = false;
  129. var symbol2d = this.layer.vectors[this.currentState.currentSymbolId];
  130. //编辑门或窗等元素的大小
  131. if (BABYLON.Vector2.Distance(symbol2d.geometry.point1, args.point) < sysmbolCircleR) {
  132. this.select.selectSymbolIds.selectEndPointIndex = 1;
  133. this.select.selectSymbolPoint(symbol2d, args.point);
  134. this.f_draggingEndpoint = true;
  135. } else if (BABYLON.Vector2.Distance(symbol2d.geometry.point2, args.point) < sysmbolCircleR) {
  136. this.select.selectSymbolIds.selectEndPointIndex = 2;
  137. this.select.selectSymbolPoint(symbol2d, args.point);
  138. this.f_draggingEndpoint = true;
  139. }
  140. } else {
  141. this.dragging.type = "wall";
  142. this.dragging.wallid = this.currentState.selectWallSet.id;
  143. this.dragging.index = this.currentState.selectWallSet.index;
  144. }
  145. }
  146. }
  147. }
  148. return function (e) {
  149. for (var key in strategy) {
  150. strategy[key] = strategy[key].bind(this)
  151. }
  152. strategy.partition = strategy.wall
  153. if (this.layer.control.draggingDialog) {
  154. return;
  155. }
  156. document.getElementById('configuratorWindow2').style.display = "none";
  157. this.currentState.addSymbol = null;
  158. //在一开始保存点击的位置。
  159. this.lastX = (e.offsetX || e.layerX);
  160. this.lastY = (e.offsetY || e.layerY);
  161. var point = this.layer.getPositionFromPx({ x: this.lastX, y: this.lastY });
  162. if (this.currentState.startbuild) {
  163. strategy[this.currentState.startbuild]({point: point})
  164. } else {
  165. strategy.__default({ point: point })
  166. }
  167. //设置鼠标样式。
  168. this.layer.div.style.cursor = "move";
  169. this.layer.renderer.autoRedraw();
  170. CanvasSketch.stopEventBubble(e);
  171. };
  172. })();
  173. // 在canvas上移动各个菜单对应发生的事件
  174. Pan.prototype.pan = function () {
  175. var strategy = {
  176. // 拖拽视图
  177. f_draggingBackGround: function (args) {
  178. this.layer.center.x -= args.dx * this.layer.res;
  179. this.layer.center.y += args.dy * this.layer.res;
  180. this.layer.moveTo(this.layer.zoom, this.layer.center);
  181. },
  182. // 拖拽直梯顶点
  183. f_draggingStairCorner: function (args) {
  184. this.move.moveStaircorner(
  185. this.currentState.currentStairId,
  186. this.currentState.currentstartlinePointIndex,
  187. args.point
  188. );
  189. },
  190. // 拖拽直梯中心线
  191. f_draggingStairLine: function (args) {
  192. this.move.moveStairLine(
  193. this.currentState.currentStairId,
  194. args.dx,
  195. args.dy,
  196. this.currentState.currentstartlinePointIndex,
  197. this.currentState.currentendlinePointIndex
  198. );
  199. },
  200. // 拖拽旋转体
  201. f_draggingSpiralCorner: function (args) {
  202. this.move.moveSpiralcorner(
  203. this.currentState.currentStairId,
  204. args.point,
  205. this.currentState.currentstartlinePointIndex
  206. );
  207. },
  208. // 拖拽螺旋体平面位置
  209. f_draggingSpiralPlane: function (args) {
  210. this.move.moveSpiralPlane(
  211. this.currentState.currentStairId,
  212. args.dx,
  213. args.dy
  214. );
  215. },
  216. // 拖拽墙面的角度
  217. f_draggingWallCorner: function (args) {
  218. // console.log()
  219. this.move.moveWallcorner(
  220. this.currentState.selectWallSet.id,
  221. this.currentState.currentstartlinePointIndex,
  222. args.point
  223. );
  224. },
  225. // 拖拽墙面中心线
  226. f_draggingWallLine: function (args) {
  227. this.move.moveWallLine(
  228. args.wallid,
  229. args.dx,
  230. args.dy,
  231. this.currentState.currentstartlinePointIndex,
  232. this.currentState.currentendlinePointIndex
  233. );
  234. this.dragging.count++
  235. },
  236. // 拖拽设置门窗顶点 设置位置
  237. f_draggingSymbol: function (args) {
  238. this.move.moveExistSymbol(
  239. this.lastPoint,
  240. args.point,
  241. this.currentState.currentSymbolId
  242. );
  243. },
  244. // 拖拽设置门窗顶点 设置长度
  245. f_draggingEndpoint: function (args) {
  246. this.move.moveSymbolEndpoint(args.point);
  247. },
  248. // 其余设置都经过
  249. __default: function (args) {
  250. if (this.f_buildingWall || this.f_buildingPartition) { //修墙
  251. this.build.buildwallState = 1;
  252. this.layer.build.BuildingWall(args.point);
  253. } else if (this.f_buildingWinderStair) { //修楼梯
  254. this.build.buildwallState = 1;
  255. this.layer.build.BuildingWinderStair(args.point);
  256. }
  257. this.previousState.save(this.currentState);
  258. this.currentState.selectStairSet = this.calculateElement.stairsContain(args.point); //判断是否在楼梯上
  259. if (this.currentState.selectStairSet != null &&
  260. this.currentState.addSymbol == null) {
  261. var stairid = this.currentState.selectStairSet.id;
  262. this.layer.vectors[stairid].geometry.geoType == "Spiral" ?
  263. strategy.__selectStairSpiral(args) :
  264. strategy.__selectStair(args)
  265. } else if (this.layer.data2d.wallIds.length > 0) {
  266. //当前点是否在墙上
  267. this.currentState.selectWallSet = this.calculateElement.wallsContain(args.point);
  268. this.currentState.selectWallSet && console.log(this.currentState.selectWallSet)
  269. this.currentState.selectWallSet ?
  270. strategy.__selectWallSet(args) :
  271. strategy.__selectNotWallSet(args)
  272. }
  273. },
  274. // 悬停在直梯上
  275. __selectStair: function (args) {
  276. var repeat = this.currentState.isRetain(this.previousState);
  277. if (!repeat) {
  278. this.select.clearSelect();
  279. this.currentState.currentendlinePointIndex = this.currentState.selectStairSet.endindex;
  280. this.currentState.currentStairId = this.currentState.selectStairSet.id;
  281. this.currentState.currentstartlinePointIndex = this.currentState.selectStairSet.index;
  282. }
  283. if (this.currentState.selectStairSet.type == 0) { //当前选择的是楼梯的拐角
  284. //状态变化,选择拐角
  285. repeat || this.select.selectStairCorner(
  286. this.currentState.selectStairSet.id,
  287. this.currentState.selectStairSet.index
  288. );
  289. } else if (this.currentState.selectStairSet.type == 1) { //当前选择的是楼梯面
  290. repeat || (this.select.f_selectStairLine = true)
  291. if (this.select.f_selectStairLine && this.currentState.currentLineId == null) {
  292. this.select.selectStairWallLine(
  293. this.currentState.currentStairId,
  294. this.currentState.currentstartlinePointIndex,
  295. this.currentState.currentendlinePointIndex
  296. );
  297. }
  298. }
  299. },
  300. // 悬停在螺旋梯形上
  301. __selectStairSpiral: function (args) {
  302. var stairid = this.currentState.selectStairSet.id;
  303. var repeat = this.previousState.type == this.currentState.selectStairSet.type &&
  304. this.previousState.currentStairId == stairid;
  305. if (!repeat) {
  306. if (this.currentState.selectStairSet.type == 0) {
  307. this.select.endselectSpiralPlane();
  308. this.select.selectSpiralCorner(
  309. this.currentState.selectStairSet.id,
  310. this.currentState.selectStairSet.index
  311. );
  312. } else {
  313. this.select.endselectSpiralCorner();
  314. this.select.selectSpiralPlane(this.currentState.selectStairSet.id);
  315. }
  316. }
  317. },
  318. // 什么都没选择,在空白区域移动
  319. __selectNotWallSet: function (args) {
  320. if (this.layer.build.tryAddSymbol != null && this.layer.build.tryAddSymbol.attributes.draw) {
  321. var moving = this.layer.move.moveVirtualSymbol2(this.layer.build.tryAddSymbol, args.point);
  322. if (!moving) {
  323. return;
  324. }
  325. } else {
  326. this.select.clearSelect();
  327. }
  328. },
  329. // 移动到墙面上
  330. __selectWallSet: function (args) {
  331. var repeat = !!this.currentState.isRetain(this.previousState);
  332. var r = this.layer.parameter.wallThickness &&
  333. this.layer.parameter.wallThickness / 2;
  334. if (!repeat) {
  335. this.select.clearSelect();
  336. this.currentState.currentendlinePointIndex = this.currentState.selectWallSet.endindex;
  337. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  338. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  339. }
  340. if (this.currentState.addSymbol != null) {
  341. return (
  342. this.layer.build.tryAddSymbol != null &&
  343. this.layer.build.tryAddSymbol.geometry.symbolType != "Stair"
  344. ) && this.layer.move.moveVirtualSymbol1(this.layer.build.tryAddSymbol, args.point) //添加假的元素:门、窗等
  345. }
  346. // 选择的是墙角 角度
  347. if (this.currentState.selectWallSet.type == 0) {
  348. !repeat && this.select.selectWallCorner(
  349. this.currentState.selectWallSet.id,
  350. this.currentState.selectWallSet.index
  351. );
  352. } else if (this.currentState.selectWallSet.type == 1) { //选择墙面
  353. !repeat && (this.select.f_selectWallLine = true);
  354. strategy.__stateChangeWall(args, this.currentState.currentWallId)
  355. }
  356. if (this.select.f_selectWallLine && this.currentState.currentLineId == null) {
  357. this.select.selectStairWallLine(
  358. this.currentState.currentWallId,
  359. this.currentState.currentstartlinePointIndex,
  360. this.currentState.currentendlinePointIndex
  361. );
  362. } else if (!this.select.f_selectWallLine) {
  363. this.select.endSelectWallLine();
  364. }
  365. },
  366. //状态变化,选择墙面
  367. __stateChangeWall: function(args, id) {
  368. //从当前选择的symbol到不选择这个symbol
  369. if (this.currentState.currentSymbolId != null) {
  370. var symbol2d = this.layer.vectors[id].symbol2Ds[this.currentState.currentSymbolId];
  371. var index = Math.min(
  372. symbol2d.attributes.wallstartindex,
  373. symbol2d.attributes.wallendindex
  374. );
  375. var r = this.layer.vectors[id].geometry.wallInfo[index].thick / 2;
  376. if (!this.calculateElement.lineContain(
  377. symbol2d.geometry.point1,
  378. symbol2d.geometry.point2,
  379. args.point, r)
  380. ) {
  381. this.select.endSelectSymbol(
  382. this.select.selectSymbolIds.vectorid,
  383. this.select.selectSymbolIds.selects,
  384. this.select.selectSymbolIds.vectorMeasureid
  385. );
  386. this.select.f_selectSymbol = false;
  387. this.select.f_selectWallLine = true;
  388. }
  389. } else { //当前没有选择symbol
  390. var symbol2d = this.calculateElement.symbolsContain(args.point);
  391. if (symbol2d != null) {
  392. // if
  393. this.select.f_selectWallLine = false;
  394. this.select.drawMeasure(symbol2d);
  395. this.select.selectSymbol(symbol2d);
  396. //选择好symbol的时候,不选择墙面
  397. this.select.f_selectWallLine = false;
  398. }
  399. }
  400. }
  401. }
  402. return function (e) {
  403. for (var key in strategy) {
  404. strategy[key] = strategy[key].bind(this)
  405. }
  406. if (this.layer.control.draggingDialog) {
  407. return
  408. }
  409. var offsetX = (e.offsetX || e.layerX)
  410. var offsetY = (e.offsetY || e.layerY)
  411. var args = {
  412. dx: offsetX - this.lastX, //计算改变的像素值
  413. dy: offsetY - this.lastY,
  414. point: this.layer.getPositionFromPx({ x: offsetX, y: offsetY }), //当前位置
  415. wallid: this.currentState.currentWallId
  416. }
  417. if (args.dx == 0 && args.dy == 0) {
  418. return CanvasSketch.stopEventBubble(e);
  419. }
  420. // 保存最后一次位置
  421. this.lastPoint = this.layer.getPositionFromPx(
  422. { x: this.lastX, y: this.lastY }
  423. );
  424. // 更新位置
  425. this.lastX = offsetX;
  426. this.lastY = offsetY;
  427. for (var i = 0, keys = Object.keys(strategy); i < keys.length; i++) {
  428. if (this[keys[i]]) {
  429. strategy[keys[i]](args);
  430. break;
  431. }
  432. }
  433. (i === keys.length) && strategy.__default(args)
  434. if (this.layer.control.refreshCanvas ||
  435. this.layer.control.refreshBackgroundCanvas ||
  436. this.layer.control.refreshSelectCanvas) {
  437. this.layer.renderer.autoRedraw();
  438. }
  439. CanvasSketch.stopEventBubble(e);
  440. };
  441. }();
  442. Pan.prototype.endPan = function (e) {
  443. if (this.layer.control.draggingDialog) {
  444. return;
  445. }
  446. this.layer.div.style.cursor = "default";
  447. //调整墙的测量线
  448. var flag = false;
  449. if (this.f_draggingWallCorner) {
  450. this.layer.build.adjustEndPoint(this.currentState.currentWallId);
  451. flag = true;
  452. }
  453. else if (this.f_draggingWallLine) {
  454. if (this.dragging.count < 3) {
  455. //弹出编辑框
  456. clearTimeout(this.editwall);
  457. this.editwall = setTimeout("this.layer.menu.showWallDialog()", 800);
  458. this.layer.menu.initEdit2D(this.dragging.wallid, this.dragging.index);
  459. }
  460. else {
  461. this.layer.build.adjustEndPoint(this.currentState.currentWallId);
  462. flag = true;
  463. }
  464. this.dragging.count = 0;
  465. this.f_draggingWallLine = false;
  466. }
  467. else if (this.ajustEndPointForWall != null) {
  468. var ids = this.ajustEndPointForWall.split(";")
  469. this.layer.build.adjustEndPoint2(ids[1], ids[0]);
  470. this.ajustEndPointForWall = null;
  471. flag = true;
  472. }
  473. if (flag) {
  474. this.layer.control.refreshCanvas = true;
  475. this.layer.renderer.autoRedraw();
  476. //调整墙的测量线
  477. }
  478. this.reset();
  479. CanvasSketch.stopEventBubble(e);
  480. };
  481. Pan.prototype.doubleclick = function (e) {
  482. //clearTimeout(this.timeId);
  483. var id = this.currentState.currentWallId;
  484. clearTimeout(this.editwall);
  485. document.getElementById('configuratorWindow2').style.display = "none";
  486. if (this.currentState.currentSymbolId != null) {
  487. return;
  488. }
  489. //建墙
  490. //if(this.currentState.currentLineId==null)
  491. if (this.currentState.startbuild == "wall" || this.currentState.startbuild == "partition") {
  492. this.build.finishWall();
  493. this.layer.control.refreshCanvas = true;
  494. }
  495. else if (this.currentState.startbuild == "WinderStair") {
  496. this.build.buildwallState = null;
  497. this.f_buildingWinderStair = false;
  498. var point = this.layer.getPositionFromPx({ x: (e.offsetX || e.layerX), y: (e.offsetY || e.layerY) });
  499. this.build.BuildingWinderStair(point);
  500. }
  501. //墙面上双击
  502. else if (!this.currentState.startbuild && this.currentState.selectWallSet != null && this.currentState.selectWallSet.type == 1) {
  503. var point = this.layer.getPositionFromPx({ x: (e.offsetX || e.layerX), y: (e.offsetY || e.layerY) });
  504. var line = this.calculateLine.createLine(this.layer.vectors[id].geometry.points[this.currentState.currentstartlinePointIndex], this.layer.vectors[id].geometry.points[this.currentState.currentendlinePointIndex]);
  505. point = this.calculateLine.getJoinLinePoint(point, line);
  506. point = new Point(point.x, point.y);
  507. point.floor = this.layer.vectors[id].geometry.points[this.currentState.currentstartlinePointIndex].floor;
  508. var points = this.layer.vectors[id].geometry.points;
  509. points.splice(this.currentState.currentstartlinePointIndex + 1, 0, point);
  510. var wallInfo = {};
  511. wallInfo.height = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  512. wallInfo.thick = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  513. wallInfo.measuredistance = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].measuredistance;
  514. this.layer.vectors[id].geometry.wallInfo.splice(this.currentState.currentstartlinePointIndex + 1, 0, wallInfo);
  515. this.calculateElement.updateSymbolsWallCornerIndexAdd(id, this.currentState.currentstartlinePointIndex + 1, point);
  516. this.layer.vectors[id].geometry.points = points;
  517. this.layer.drawVector(this.layer.vectors[id]);
  518. var index = this.currentState.currentstartlinePointIndex + 1;
  519. //this.layer.vectors[id].geometry.wallInfo[index].height = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  520. //this.layer.vectors[id].geometry.wallInfo[index].thick = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  521. //this.layer.vectors[id].geometry.wallInfo[index].measuredistance = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  522. this.select.clearSelect();
  523. this.currentState.currentWallId = id;
  524. this.select.selectWallCorner(id, index);
  525. }
  526. this.layer.renderer.autoRedraw();
  527. CanvasSketch.stopEventBubble(e);
  528. };
  529. Pan.prototype.Events = [["mousedown", Pan.prototype.startPan],
  530. ["mousemove", Pan.prototype.pan],
  531. ["mouseup", Pan.prototype.endPan],
  532. ["dblclick", Pan.prototype.doubleclick]];
  533. Pan.prototype.active = function () {
  534. this.div.addEventListener("mousedown", Pan.prototype.startPan.bind(this), true);
  535. this.div.addEventListener("mousemove", Pan.prototype.pan.bind(this), true);
  536. this.div.addEventListener("mouseup", Pan.prototype.endPan.bind(this), true);
  537. var doubleclick = Pan.prototype.doubleclick.bind(this)
  538. var startTime = null
  539. this.div.addEventListener("click", function() {
  540. if (startTime && Date.now() - startTime <= 300) {
  541. doubleclick.apply(this, arguments)
  542. } else {
  543. startTime = Date.now()
  544. }
  545. }, true);
  546. };
  547. Pan.prototype.reset = function () {
  548. this.f_draggingBackGround = false;
  549. this.f_draggingWallLine = false;
  550. this.f_draggingWallCorner = false;
  551. this.f_draggingStairLine = false;
  552. this.f_draggingStairCorner = false;
  553. this.f_draggingSpiralPlane = false;
  554. this.f_draggingSpiralCorner = false;
  555. this.f_draggingSymbol = false;
  556. this.f_draggingEndpoint = false;
  557. //this.f_buildingWall=false;
  558. this.f_buildingSymbol = false;
  559. };
  560. //新建一个空白页
  561. Pan.prototype.addNew = function () {
  562. document.getElementById("toolbarMenu").addEventListener("click", function (e) {
  563. if (e.target.parentElement.parentElement.id == "toolbarNew") {
  564. if (confirm("您确定要重新打开网页?")) {
  565. //如果是true ,那么就把页面刷新
  566. //location.reload();
  567. this.layer.menu.show2D();
  568. for (var vectorId in this.layer.vectors) {
  569. this.layer.deleteVector(vectorId);
  570. this.layer.data2d.wallIds = [];
  571. }
  572. this.layer.clear();
  573. this.select.clearSelect();
  574. if (my3DEngine != null && typeof (my3DEngine) != "undefined") {
  575. my3DEngine.clearAllSymbols();
  576. my3DEngine = null;
  577. }
  578. one3d = true;
  579. this.currentState.currentWallId = null;
  580. addWall();
  581. }
  582. }
  583. else if (e.target.parentElement.parentElement.id == "toolbarSave") {
  584. alert("save");
  585. }
  586. else if (e.target.parentElement.parentElement.id == "toolbarOption") {
  587. var aw = document.getElementById("aboutWindow");
  588. aw.style.display = "block";
  589. //alert("option");
  590. }
  591. else if (e.target.parentElement.parentElement.id == "userOption") {
  592. alert("user");
  593. }
  594. }.bind(this));
  595. function addWall() {
  596. var vectors = [];
  597. var points = [];
  598. var point1 = new Point(wallleftX, wallleftY);
  599. points.push(point1);
  600. var point2 = new Point(wallrightX, wallleftY);
  601. points.push(point2);
  602. var point3 = new Point(wallrightX, wallrightY);
  603. points.push(point3);
  604. var point4 = new Point(wallleftX, wallrightY);
  605. points.push(point4);
  606. var wall = new Wall(points, document.getElementById("imgWall"));
  607. var vector = new Vector(wall, wallStyle);
  608. wallId = vector.id;
  609. vectors.push(vector);
  610. this.layer.addVectors(vectors);
  611. this.layer.data2d.wallIds.push(wallId);
  612. }
  613. };