Move.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. function Move(layer) {
  2. this.layer = layer;
  3. this.moveType = null;
  4. this.currentState = this.layer.currentState;
  5. this.calculateLine = this.layer.calculateLine;
  6. this.calculateElement = this.layer.calculateElement;
  7. //拖拽门或者窗户 等元素
  8. this.draggingSymbol2d = null;
  9. //拖拽门或者窗户的顶点
  10. this.draggingSymbol2dPoint = null;
  11. //移动墙角的时候保存移动点的信息
  12. //this.moveCornerPoint=null;
  13. };
  14. //移动楼梯角
  15. Move.prototype.moveStaircorner = function (stairid, index, newdragPoint) {
  16. if (stairid == null) {
  17. return;
  18. }
  19. this.layer.vectors[stairid].geometry.points[index].x = newdragPoint.x;
  20. this.layer.vectors[stairid].geometry.points[index].y = newdragPoint.y;
  21. var pt = this.layer.vectors[stairid].geometry.points[this.currentState.currentstartlinePointIndex];
  22. this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x;
  23. this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y;
  24. this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex;
  25. var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[stairid].geometry.points);
  26. this.layer.vectors[stairid].geometry.linkedpoints = allpoints.vertical;
  27. this.layer.vectors[stairid].geometry.borderpoints.border1 = allpoints.border1;
  28. this.layer.vectors[stairid].geometry.borderpoints.border2 = allpoints.border2;
  29. this.layer.vectors[stairid].geometry.arrowpoints.arrows1 = allpoints.arrows1;
  30. this.layer.vectors[stairid].geometry.arrowpoints.arrows2 = allpoints.arrows2;
  31. this.layer.control.refreshCanvas = true;
  32. this.layer.control.refreshSelectCanvas = true;
  33. };
  34. Move.prototype.moveSpiralcorner = function (stairId, point, index) {
  35. var center = this.layer.vectors[stairId].geometry.point;
  36. var r = this.layer.parameter.spiralR1;
  37. var line = this.calculateLine.createLine(point, center);
  38. var newpoint = {};
  39. var angle = null;
  40. if (line.hasOwnProperty('x')) {
  41. newpoint.x = center.x;
  42. if (point.y > center.y) {
  43. newpoint.y = center.y + r;
  44. angle = 1.5 * Math.PI;
  45. } else {
  46. newpoint.y = center.y - r;
  47. angle = Math.PI / 2;
  48. }
  49. } else if (line.hasOwnProperty('y')) {
  50. newpoint.y = center.y;
  51. if (point.x > center.x) {
  52. newpoint.x = center.x + r;
  53. angle = 0;
  54. } else {
  55. newpoint.x = center.x - r;
  56. angle = Math.PI;
  57. }
  58. } else {
  59. var verticalLine1 = {};
  60. var verticalLine2 = {};
  61. verticalLine1.a = -1 / line.a;
  62. verticalLine2.a = -1 / line.a;
  63. var b = center.y - verticalLine1.a * center.x;
  64. verticalLine1.b = b + this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1);
  65. verticalLine2.b = b - this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1);
  66. var join1 = this.calculateLine.getIntersectionPoint(verticalLine1, line);
  67. var join2 = this.calculateLine.getIntersectionPoint(verticalLine2, line);
  68. if (this.calculateLine.containPoint(center, join1, point) || this.calculateLine.containPoint(center, point, join1)) {
  69. newpoint = join1;
  70. } else {
  71. newpoint = join2;
  72. }
  73. var dx = newpoint.x - center.x;
  74. var dy = newpoint.y - center.y;
  75. if (dx > 0 && dy > 0 || dx < 0 && dy > 0) {
  76. if (line.a > 0) {
  77. angle = 2 * Math.PI - Math.atan(line.a);
  78. } else {
  79. angle = Math.PI + Math.abs(Math.atan(line.a));
  80. }
  81. } else {
  82. if (line.a > 0) {
  83. angle = Math.PI - Math.atan(line.a);
  84. } else {
  85. angle = Math.abs(Math.atan(line.a));
  86. }
  87. }
  88. }
  89. if (index == 1) {
  90. this.layer.vectors[stairId].geometry.sAngle = angle;
  91. this.layer.vectors[stairId].geometry.point1 = newpoint;
  92. } else {
  93. this.layer.vectors[stairId].geometry.eAngle = angle;
  94. this.layer.vectors[stairId].geometry.point2 = newpoint;
  95. }
  96. this.layer.vectors[this.currentState.currentPointId].geometry.x = newpoint.x;
  97. this.layer.vectors[this.currentState.currentCircleId].geometry.x = newpoint.x;
  98. this.layer.vectors[this.currentState.currentPointId].geometry.y = newpoint.y;
  99. this.layer.vectors[this.currentState.currentCircleId].geometry.y = newpoint.y;
  100. this.layer.control.refreshCanvas = true;
  101. this.layer.control.refreshSelectCanvas = true;
  102. };
  103. Move.prototype.moveSpiralPlane = function (stairId, dx, dy) {
  104. var point = {};
  105. point.x = this.layer.vectors[stairId].geometry.point.x + dx;
  106. point.y = this.layer.vectors[stairId].geometry.point.y - dy;
  107. var points = this.calculateElement.GetSpiralpoints(point);
  108. this.layer.vectors[stairId].geometry.point = point;
  109. this.layer.vectors[stairId].geometry.points = points;
  110. this.layer.vectors[stairId].geometry.point1.x += dx;
  111. this.layer.vectors[stairId].geometry.point1.y -= dy;
  112. this.layer.vectors[stairId].geometry.point2.x += dx;
  113. this.layer.vectors[stairId].geometry.point2.y -= dy;
  114. this.layer.control.refreshCanvas = true;
  115. };
  116. //
  117. Move.prototype.endmoveWall = function (newdragPoint) {
  118. };
  119. //移动墙角
  120. //index表示选择的墙角所在的位置
  121. Move.prototype.moveWallcorner = function (wallid, index, newdragPoint) {
  122. if (wallid == null) {
  123. return;
  124. }
  125. var interval = this.layer.parameter.wallThickness;
  126. var len = this.layer.vectors[wallid].geometry.points.length;
  127. delete this.layer.vectors[wallid].geometry.firstLines;
  128. delete this.layer.vectors[wallid].geometry.endLines;
  129. //移动的点与相邻的点是否重合
  130. var flag = false;
  131. for (var i = 0; i < len; ++i) {
  132. if (i != index) {
  133. if (BABYLON.Vector2.Distance(newdragPoint, this.layer.vectors[wallid].geometry.points[i]) < interval) {
  134. flag = true;
  135. //修改data2d的nodes
  136. var index1 = this.calculateElement.getPreIndex(this.layer.vectors[wallid].geometry.points, index);
  137. var index2 = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, index);
  138. if (index1 == i) {
  139. this.layer.data2d.deleteNode({
  140. wallId: wallid,
  141. startIndex: index,
  142. endIndex: -1
  143. }, index1);
  144. this.layer.data2d.moveNodeForWall({
  145. wallId: wallid,
  146. startIndex: index,
  147. endIndex: -1
  148. });
  149. } else if (index2 == i) {
  150. this.layer.data2d.deleteNode({
  151. wallId: wallid,
  152. startIndex: index,
  153. endIndex: -1
  154. }, index2);
  155. this.layer.data2d.moveNodeForWall({
  156. wallId: wallid,
  157. startIndex: index,
  158. endIndex: -1
  159. });
  160. }
  161. this.calculateElement.updateSymbolsWallCornerIndexDelete(wallid, i, index)
  162. if (index > i && (index - i) != len - 1) {
  163. this.layer.vectors[wallid].geometry.wallInfo[i].thick = this.layer.vectors[wallid].geometry.wallInfo[index].thick;
  164. this.layer.vectors[wallid].geometry.wallInfo[i].height = this.layer.vectors[wallid].geometry.wallInfo[index].height;
  165. }
  166. this.layer.vectors[wallid].geometry.points.splice(index, 1);
  167. this.layer.vectors[wallid].geometry.wallInfo.splice(index, 1);
  168. if (Math.abs(index - i) == len - 1) {
  169. this.layer.vectors[wallid].geometry.state = 0;
  170. }
  171. if (this.layer.vectors[wallid].geometry.points.length == 1) {
  172. this.layer.data2d.deleteWallid(this.currentState.currentWallId);
  173. this.layer.deleteVector(wallid);
  174. this.layer.select.clearSelect();
  175. this.currentState.selectWallSet = null;
  176. this.currentState.currentWallId = null;
  177. this.layer.control.refreshCanvas = true;
  178. this.layer.pan.f_draggingWallCorner = false;
  179. return;
  180. } else if (this.layer.vectors[wallid].geometry.points.length < 3) {
  181. this.layer.vectors[wallid].geometry.state = 1;
  182. }
  183. if (index > i) {
  184. index = i;
  185. } else if (index == 0 && (i == len - 1)) {
  186. //删除了一个点
  187. index = len - 2;
  188. }
  189. this.currentState.currentstartlinePointIndex = index;
  190. break;
  191. }
  192. }
  193. }
  194. if (!flag) {
  195. }
  196. this.layer.vectors[wallid].geometry.points[index].x = newdragPoint.x;
  197. this.layer.vectors[wallid].geometry.points[index].y = newdragPoint.y;
  198. //this.layer.data2d.moveNodeForWall({wallId:wallid,startIndex:index,endIndex:-1});
  199. //处理墙上的门、窗等元素
  200. if (this.layer.vectors[wallid].symbol2dsCount > 0) {
  201. this.moveSymbolsWithWallCorner(wallid, index);
  202. }
  203. //处理选中的图形
  204. this.changeCorner();
  205. this.layer.control.refreshCanvas = true;
  206. this.layer.control.refreshSelectCanvas = true;
  207. };
  208. //改变扇形、圆、点
  209. Move.prototype.changeCorner = function () {
  210. //改变样式:扇形、圆圈等
  211. var pt = this.layer.vectors[this.currentState.currentWallId].geometry.points[this.currentState.currentstartlinePointIndex];
  212. this.layer.vectors[this.currentState.currentPointId].geometry.x = pt.x;
  213. this.layer.vectors[this.currentState.currentPointId].geometry.y = pt.y;
  214. this.layer.vectors[this.currentState.currentPointId].geometry.contextIndex = this.layer.select.contextIndex;
  215. this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x;
  216. this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y;
  217. this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex;
  218. var sector = this.layer.select.editSector(this.currentState.currentstartlinePointIndex);
  219. if (sector != null) {
  220. if (this.currentState.currentSecotrId != null) {
  221. this.layer.vectors[this.currentState.currentSecotrId].geometry.x = sector.x;
  222. this.layer.vectors[this.currentState.currentSecotrId].geometry.y = sector.y;
  223. this.layer.vectors[this.currentState.currentSecotrId].geometry.startAngle = sector.start;
  224. this.layer.vectors[this.currentState.currentSecotrId].geometry.endAngle = sector.end;
  225. this.layer.vectors[this.currentState.currentSecotrId].geometry.contextIndex = this.layer.select.contextIndex;
  226. } else {
  227. //添加扇形
  228. var addsector = new Sector(sector.x, sector.y, Sector_r, sector.start, sector.end);
  229. var vector = new Vector(addsector, sectorStyle);
  230. this.currentState.currentSecotrId = vector.id;
  231. vector.geometry.contextIndex = this.layer.select.contextIndex;
  232. this.layer.drawSingleVector(vector);
  233. }
  234. } else {
  235. this.layer.deleteVector(this.currentState.currentSecotrId);
  236. this.currentState.currentSecotrId = null;
  237. }
  238. this.layer.control.refreshSelectCanvas = true;
  239. };
  240. Move.prototype.moveStairLine = function (id, dx, dy, startIndex, endIndex) {
  241. this.layer.vectors[id].geometry.points[startIndex].x += dx * this.layer.res;
  242. this.layer.vectors[id].geometry.points[startIndex].y -= dy * this.layer.res;
  243. this.layer.vectors[id].geometry.points[endIndex].x += dx * this.layer.res;
  244. this.layer.vectors[id].geometry.points[endIndex].y -= dy * this.layer.res;
  245. //移动选中的点和线
  246. if (this.currentState.currentLineId != null) {
  247. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x += dx * this.layer.res;
  248. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x += dx * this.layer.res;
  249. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y -= dy * this.layer.res;
  250. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y -= dy * this.layer.res;
  251. }
  252. if (this.currentState.currentLinePoint1Id != null) {
  253. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x += dx * this.layer.res;
  254. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y -= dy * this.layer.res;
  255. }
  256. if (this.currentState.currentLinePoint2Id != null) {
  257. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x += dx * this.layer.res;
  258. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y -= dy * this.layer.res;
  259. }
  260. var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[id].geometry.points);
  261. this.layer.vectors[id].geometry.linkedpoints = allpoints.vertical;
  262. this.layer.vectors[id].geometry.borderpoints.border1 = allpoints.border1;
  263. this.layer.vectors[id].geometry.borderpoints.border2 = allpoints.border2;
  264. this.layer.vectors[id].geometry.arrowpoints.arrows1 = allpoints.arrows1;
  265. this.layer.vectors[id].geometry.arrowpoints.arrows2 = allpoints.arrows2;
  266. this.layer.control.refreshSelectCanvas = true;
  267. this.layer.control.refreshCanvas = true;
  268. this.layer.renderer.autoRedraw();
  269. };
  270. /*
  271. //移动楼梯面
  272. Move.prototype.moveStairLine=function(id,dx,dy,startIndex,endIndex)
  273. {
  274. if(id==null||startIndex==null||endIndex==null)
  275. {
  276. return;
  277. }
  278. var r=this.layer.parameter.stairWidth;
  279. var len=this.layer.vectors[id].geometry.points.length;
  280. if(len==2)
  281. {
  282. for(var i=0;i<this.layer.vectors[id].geometry.points.length;++i)
  283. {
  284. var x=this.layer.vectors[id].geometry.points[i].x+dx * this.layer.res;
  285. var y=this.layer.vectors[id].geometry.points[i].y-dy * this.layer.res;
  286. this.layer.vectors[id].geometry.points[i]={x:x,y:y};
  287. }
  288. //移动选中的点和线
  289. if(this.currentState.currentLineId!=null)
  290. {
  291. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x+=dx * this.layer.res;
  292. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x+=dx * this.layer.res;
  293. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y-=dy * this.layer.res;
  294. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y-=dy * this.layer.res;
  295. }
  296. if(this.currentState.currentLinePoint1Id!=null)
  297. {
  298. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x+=dx * this.layer.res;
  299. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y-=dy * this.layer.res;
  300. }
  301. if(this.currentState.currentLinePoint2Id!=null)
  302. {
  303. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x+=dx * this.layer.res;
  304. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y-=dy * this.layer.res;
  305. }
  306. }
  307. else
  308. {
  309. var newdragline=[];
  310. var currentPoint1={};
  311. currentPoint1.x=this.layer.vectors[id].geometry.points[startIndex].x;
  312. currentPoint1.y=this.layer.vectors[id].geometry.points[startIndex].y;
  313. var currentPoint2={};
  314. currentPoint2.x=this.layer.vectors[id].geometry.points[endIndex].x;
  315. currentPoint2.y=this.layer.vectors[id].geometry.points[endIndex].y;
  316. //不考虑周围的墙,鼠标移动后,选中的墙本应该在的位置
  317. newdragline.push({x:currentPoint1.x+ dx * this.layer.res,y:currentPoint1.y- dy * this.layer.res});
  318. newdragline.push({x:currentPoint2.x+ dx * this.layer.res,y:currentPoint2.y- dy * this.layer.res});
  319. var origin=this.layer.calculateElement.getOrginLine(len,id,startIndex,endIndex);
  320. //得到挨着startIndex但不是newdragline的墙的线段
  321. var orginLine1=origin.line1;
  322. //线段的另一个端点
  323. var orginPoint1=this.layer.vectors[id].geometry.points[origin.point1];
  324. //得到挨着endIndex但不是newdragline的墙的线段
  325. var orginLine2=origin.line2;
  326. //线段的另一个端点
  327. var orginPoint2=this.layer.vectors[id].geometry.points[origin.point2];
  328. var newline=this.calculateLine.createLine(newdragline[0],newdragline[1]);
  329. var point1=this.layer.vectors[id].geometry.points[orginLine1[0]];
  330. var point2=this.layer.vectors[id].geometry.points[orginLine1[1]];
  331. //拖拽的墙与挨着的墙的交点
  332. var line1=this.calculateLine.createLine(point1,point2);
  333. var newWallPoint1=this.calculateLine.getIntersectionPoint(line1,newline);
  334. var point3=this.layer.vectors[id].geometry.points[orginLine2[0]];
  335. var point4=this.layer.vectors[id].geometry.points[orginLine2[1]];
  336. //拖拽的墙与另一堵挨着的墙的交点
  337. var line2=this.calculateLine.createLine(point3,point4);
  338. var newWallPoint2=this.calculateLine.getIntersectionPoint(line2,newline);
  339. this.layer.vectors[id].geometry.points[startIndex].x=newWallPoint1.x;
  340. this.layer.vectors[id].geometry.points[startIndex].y=newWallPoint1.y;
  341. this.layer.vectors[id].geometry.points[endIndex].x=newWallPoint2.x;
  342. this.layer.vectors[id].geometry.points[endIndex].y=newWallPoint2.y;
  343. this.currentState.currentstartlinePointIndex=startIndex;
  344. this.currentState.currentendlinePointIndex=endIndex;
  345. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x=newWallPoint1.x;
  346. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y=newWallPoint1.y;
  347. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x=newWallPoint2.x;
  348. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y=newWallPoint2.y;
  349. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x=this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x;
  350. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y=this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y;
  351. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x=this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x;
  352. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y=this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y;
  353. }
  354. var allpoints=this.calculateElement.getAllPointsFromStair(this.layer.vectors[id].geometry.points);
  355. this.layer.vectors[id].geometry.linkedpoints=allpoints.vertical;
  356. this.layer.vectors[id].geometry.borderpoints.border1=allpoints.border1;
  357. this.layer.vectors[id].geometry.borderpoints.border2=allpoints.border2;
  358. this.layer.control.refreshSelectCanvas=true;
  359. this.layer.control.refreshCanvas=true;
  360. this.layer.renderer.autoRedraw();
  361. };
  362. */
  363. //移动整面墙
  364. //startIndex,endIndex表示墙的两个端点
  365. //id表示当前移动墙的id
  366. //dx,dy表示偏移量
  367. Move.prototype.moveWallLine = function (id, dx, dy, startIndex, endIndex) {
  368. if (id == null || startIndex == null || endIndex == null) {
  369. return;
  370. }
  371. var r;
  372. if (this.layer.vectors[id].geometry.wallType == 1) {
  373. r = wallThickness / 2
  374. } else {
  375. r = partitionThickness / 2
  376. }
  377. var len = this.layer.vectors[id].geometry.points.length;
  378. var newdragline = [];
  379. var currentPoint1 = {};
  380. currentPoint1.x = this.layer.vectors[id].geometry.points[startIndex].x;
  381. currentPoint1.y = this.layer.vectors[id].geometry.points[startIndex].y;
  382. var currentPoint2 = {};
  383. currentPoint2.x = this.layer.vectors[id].geometry.points[endIndex].x;
  384. currentPoint2.y = this.layer.vectors[id].geometry.points[endIndex].y;
  385. //不考虑周围的墙,鼠标移动后,选中的墙本应该在的位置
  386. newdragline.push({
  387. x: currentPoint1.x + dx * this.layer.res,
  388. y: currentPoint1.y - dy * this.layer.res
  389. });
  390. newdragline.push({
  391. x: currentPoint2.x + dx * this.layer.res,
  392. y: currentPoint2.y - dy * this.layer.res
  393. });
  394. //如果墙不是闭合的,就拖拽vector就行
  395. if (this.layer.vectors[id].geometry.state == 1) {
  396. for (var i = 0; i < this.layer.vectors[id].geometry.points.length; ++i) {
  397. var x = this.layer.vectors[id].geometry.points[i].x + dx * this.layer.res;
  398. var y = this.layer.vectors[id].geometry.points[i].y - dy * this.layer.res;
  399. this.layer.vectors[id].geometry.points[i] = {
  400. x: x,
  401. y: y
  402. };
  403. }
  404. //移动选中的点和线
  405. if (this.currentState.currentLineId != null) {
  406. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x += dx * this.layer.res;
  407. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x += dx * this.layer.res;
  408. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y -= dy * this.layer.res;
  409. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y -= dy * this.layer.res;
  410. }
  411. if (this.currentState.currentLinePoint1Id != null) {
  412. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x += dx * this.layer.res;
  413. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y -= dy * this.layer.res;
  414. }
  415. if (this.currentState.currentLinePoint2Id != null) {
  416. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x += dx * this.layer.res;
  417. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y -= dy * this.layer.res;
  418. }
  419. //移动墙上所有的symbols
  420. for (var key in this.layer.vectors[id].symbol2Ds) {
  421. if (this.layer.vectors[id].symbol2Ds[key].geometry.geoType != "OpenDoor" && this.layer.vectors[id].symbol2Ds[key].geometry.geoType != "OpenWindow") {
  422. for (var i = 0; i < this.layer.vectors[id].symbol2Ds[key].geometry.points.length; ++i) {
  423. this.layer.vectors[id].symbol2Ds[key].geometry.points[i].x += dx * this.layer.res;
  424. this.layer.vectors[id].symbol2Ds[key].geometry.points[i].y -= dy * this.layer.res;
  425. }
  426. }
  427. this.layer.vectors[id].symbol2Ds[key].geometry.point1.x += dx * this.layer.res;
  428. this.layer.vectors[id].symbol2Ds[key].geometry.point1.y -= dy * this.layer.res;
  429. this.layer.vectors[id].symbol2Ds[key].geometry.point2.x += dx * this.layer.res;
  430. this.layer.vectors[id].symbol2Ds[key].geometry.point2.y -= dy * this.layer.res;
  431. }
  432. this.layer.control.refreshSelectCanvas = true;
  433. this.layer.control.refreshCanvas = true;
  434. this.layer.renderer.autoRedraw();
  435. return;
  436. }
  437. //判断墙中的点有没有合并
  438. var symbolFlag = false;
  439. var flag = false;
  440. var orginLine = [];
  441. var origin = this.layer.calculateElement.getOrginLine(len, id, startIndex, endIndex);
  442. //得到挨着startIndex但不是newdragline的墙的线段
  443. var orginLine1 = origin.line1;
  444. //线段的另一个端点
  445. var orginPoint1 = this.layer.vectors[id].geometry.points[origin.point1];
  446. //得到挨着endIndex但不是newdragline的墙的线段
  447. var orginLine2 = origin.line2;
  448. //线段的另一个端点
  449. var orginPoint2 = this.layer.vectors[id].geometry.points[origin.point2];
  450. var newline = this.calculateLine.createLine(newdragline[0], newdragline[1]);
  451. var point1 = this.layer.vectors[id].geometry.points[orginLine1[0]];
  452. var point2 = this.layer.vectors[id].geometry.points[orginLine1[1]];
  453. //拖拽的墙与挨着的墙的交点
  454. var line1 = this.calculateLine.createLine(point1, point2);
  455. var newWallPoint1 = this.calculateLine.getIntersectionPoint(line1, newline);
  456. var point3 = this.layer.vectors[id].geometry.points[orginLine2[0]];
  457. var point4 = this.layer.vectors[id].geometry.points[orginLine2[1]];
  458. //拖拽的墙与另一堵挨着的墙的交点
  459. var line2 = this.calculateLine.createLine(point3, point4);
  460. var newWallPoint2 = this.calculateLine.getIntersectionPoint(line2, newline);
  461. this.layer.vectors[id].geometry.points[startIndex].x = newWallPoint1.x;
  462. this.layer.vectors[id].geometry.points[startIndex].y = newWallPoint1.y;
  463. this.layer.vectors[id].geometry.points[endIndex].x = newWallPoint2.x;
  464. this.layer.vectors[id].geometry.points[endIndex].y = newWallPoint2.y;
  465. this.currentState.currentstartlinePointIndex = startIndex;
  466. this.currentState.currentendlinePointIndex = endIndex;
  467. this.layer.control.refreshCanvas = true;
  468. if (BABYLON.Vector2.Distance(orginPoint1, newWallPoint1) < 2 * r) {
  469. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x = orginPoint1.x;
  470. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y = orginPoint1.y;
  471. newWallPoint1.x = orginPoint1.x;
  472. newWallPoint1.y = orginPoint1.y;
  473. var indexs = this.calculateElement.updateSelectWallLineIndex(id, startIndex, endIndex, origin.point1);
  474. if (this.calculateElement.isNeighbor(len, origin.point1, startIndex)) {
  475. if (startIndex > origin.point1 && (startIndex - origin.point1) != len - 1) {
  476. this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick;
  477. this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height;
  478. }
  479. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  480. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  481. origin.point1 = Math.min(origin.point1, startIndex);
  482. } else {
  483. if (endIndex > origin.point1 && (endIndex - origin.point1) != len - 1) {
  484. this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick;
  485. this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height;
  486. }
  487. this.layer.vectors[id].geometry.points.splice(endIndex, 1);
  488. this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1);
  489. origin.point1 = Math.min(origin.point1, endIndex);
  490. }
  491. startIndex = indexs.wallindex1;
  492. endIndex = indexs.wallindex2;
  493. this.currentState.currentstartlinePointIndex = startIndex;
  494. this.currentState.currentendlinePointIndex = endIndex;
  495. if (this.layer.vectors[id].geometry.points.length < 3) {
  496. this.layer.vectors[id].geometry.state = 1;
  497. }
  498. symbolFlag = true;
  499. } else if (this.currentState.currentLinePoint1Id != null) {
  500. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x = newWallPoint1.x;
  501. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y = newWallPoint1.y;
  502. }
  503. if (BABYLON.Vector2.Distance(orginPoint2, newWallPoint2) < 2 * r) {
  504. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = orginPoint2.x;
  505. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = orginPoint2.y;
  506. newWallPoint2.x = orginPoint2.x;
  507. newWallPoint2.y = orginPoint2.y;
  508. var indexs = this.calculateElement.updateSelectWallLineIndex(id, startIndex, endIndex, origin.point2);
  509. if (this.calculateElement.isNeighbor(len, origin.point2, startIndex)) {
  510. if (startIndex > origin.point2 && (startIndex - origin.point2) != len - 1) {
  511. this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick;
  512. this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height;
  513. }
  514. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  515. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  516. origin.point2 = Math.min(origin.point1, startIndex);
  517. } else {
  518. if (endIndex > origin.point2 && (endIndex - origin.point2) != len - 1) {
  519. this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick;
  520. this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height;
  521. }
  522. this.layer.vectors[id].geometry.points.splice(endIndex, 1);
  523. this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1);
  524. origin.point2 = Math.min(origin.point1, endIndex);
  525. }
  526. startIndex = indexs.wallindex1;
  527. endIndex = indexs.wallindex2;
  528. this.currentState.currentstartlinePointIndex = startIndex;
  529. this.currentState.currentendlinePointIndex = endIndex;
  530. if (this.layer.vectors[id].geometry.points.length < 3) {
  531. this.layer.vectors[id].geometry.state = 1;
  532. }
  533. symbolFlag = true;
  534. } else if (this.currentState.currentLinePoint2Id != null) {
  535. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = newWallPoint2.x;
  536. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = newWallPoint2.y;
  537. }
  538. if (this.layer.vectors[id].geometry.points.length == 1) {
  539. this.layer.data2d.deleteWallid(this.currentState.currentWallId);
  540. this.layer.deleteVector(id);
  541. this.layer.select.clearSelect();
  542. this.currentState.selectWallSet = null;
  543. this.currentState.currentWallId = null;
  544. this.layer.control.refreshCanvas = true;
  545. this.layer.pan.f_draggingWallLine = false;
  546. return;
  547. }
  548. if (this.layer.vectors[id].geometry.points.length == 1 || BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) {
  549. this.layer.select.clearSelect();
  550. this.layer.select.endSelectWallLine();
  551. this.layer.pan.f_draggingWallLine = false;
  552. this.layer.pan.f_draggingWallCorner = true;
  553. var index = startIndex;
  554. if (this.layer.vectors[id].geometry.points.length != 1) {
  555. if (index == this.layer.vectors[id].geometry.points.length - 1) {
  556. index = 0;
  557. }
  558. this.calculateElement.updateSymbolsWallCornerIndexDelete(id, startIndex, endIndex);
  559. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  560. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  561. this.layer.select.selectWallCorner(id, index);
  562. } else {
  563. index = 0;
  564. this.layer.deleteVector(id);
  565. this.currentState.currentWallId = null;
  566. }
  567. }
  568. if (this.currentState.currentLineId != null) {
  569. if (BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) {
  570. this.layer.select.clearSelect();
  571. this.layer.select.selectWallCorner(id, startIndex);
  572. } else {
  573. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x;
  574. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y;
  575. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x;
  576. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y;
  577. }
  578. }
  579. this.layer.control.refreshSelectCanvas = true;
  580. //计算改变的像素值
  581. dx = ((newWallPoint1.x - currentPoint1.x) + (newWallPoint2.x - currentPoint2.x)) / 2;
  582. dy = ((newWallPoint1.y - currentPoint1.y) + (newWallPoint2.y - currentPoint2.y)) / 2;
  583. this.moveSymbolsWithWallLine(id, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, dx, dy, symbolFlag);
  584. this.layer.control.refreshCanvas = true;
  585. this.layer.renderer.autoRedraw();
  586. };
  587. //拖拽虚拟的Symbol,point在墙内
  588. Move.prototype.moveVirtualSymbol1 = function (symbol, point) {
  589. var len = symbol.getSymbolLen();
  590. symbol.geometry.r = len;
  591. var wallid = this.currentState.currentWallId;
  592. //获取symbol端点
  593. var endpoint = this.calculateElement.getSymbolEndPoint(point, wallid, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, len);
  594. //选择canvas
  595. symbol.geometry.contextIndex = this.layer.parameter.selectcontext;
  596. symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  597. //更新端点
  598. if (endpoint != null) {
  599. symbol.geometry.point1 = endpoint.newpoint1;
  600. symbol.geometry.point2 = endpoint.newpoint2;
  601. }
  602. if (symbol.geometry.point1 != null & symbol.geometry.point2 != null) {
  603. symbol.update(this.layer, this.currentState.currentWallId, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, point);
  604. if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") {
  605. this.layer.select.selectSymbol(symbol);
  606. }
  607. //更新选中的线和两个圆圈的坐标
  608. else {
  609. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x;
  610. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y;
  611. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x;
  612. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y;
  613. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1;
  614. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2;
  615. }
  616. this.layer.control.refreshSelectCanvas = true;
  617. }
  618. };
  619. //拖拽虚拟的Symbol,point在墙外
  620. Move.prototype.moveVirtualSymbol2 = function (symbol, point) {
  621. var len = symbol.getSymbolLen();
  622. symbol.geometry.thick = this.layer.vectors[symbol.attributes.wallId].geometry.wallInfo[symbol.attributes.wallstartindex].thick;
  623. var endpoint = this.calculateElement.getSymbolEndPoint2(point, symbol.attributes.wallId, symbol.attributes.wallstartindex, symbol.attributes.wallendindex, len);
  624. if (endpoint == null) {
  625. return false;
  626. } else {
  627. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  628. //更新端点
  629. symbol.geometry.point1 = endpoint.newpoint1;
  630. symbol.geometry.point2 = endpoint.newpoint2;
  631. var newPoint = {
  632. x: (endpoint.newpoint1.x + endpoint.newpoint2.x) / 2,
  633. y: (endpoint.newpoint1.y + endpoint.newpoint2.y) / 2
  634. };
  635. symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType;
  636. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point);
  637. symbol.geometry.points = this.calculateElement.getSymbolPoints(endpoint.newpoint1, endpoint.newpoint2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  638. this.layer.control.refreshCanvas = true;
  639. }
  640. if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") {
  641. this.layer.select.selectSymbol(symbol);
  642. }
  643. //更新选中的线和两个圆圈的坐标
  644. else {
  645. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x;
  646. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y;
  647. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x;
  648. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y;
  649. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1;
  650. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2;
  651. }
  652. this.layer.control.refreshSelectCanvas = true;
  653. return true;
  654. };
  655. //拖拽已经存在的Symbol
  656. Move.prototype.moveExistSymbol = function (lastpoint, point, id) {
  657. var symbol = this.layer.vectors[id];
  658. var wallid = symbol.attributes.wallId;
  659. var startIndex = this.currentState.currentstartlinePointIndex;
  660. var endIndex = this.currentState.currentendlinePointIndex;
  661. symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  662. var point1, point2;
  663. var joinpoint = null;
  664. point1 = this.layer.vectors[wallid].geometry.points[startIndex];
  665. if (endIndex != null && typeof (endIndex) != undefined) {
  666. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  667. } else {
  668. endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state);
  669. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  670. }
  671. this.currentState.selectWallSet = this.calculateElement.wallsContain(point);
  672. if (this.currentState.selectWallSet != null) {
  673. //当前点在墙角
  674. if (this.currentState.selectWallSet.type == 0) {
  675. if (wallid != this.currentState.currentWallId) {
  676. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  677. this.currentState.currentendlinePointIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, this.currentState.selectWallSet.index, this.layer.vectors[wallid].geometry.state);
  678. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  679. wallid = this.currentState.currentWallId;
  680. startIndex = this.currentState.currentstartlinePointIndex;
  681. endIndex = this.currentState.currentendlinePointIndex;
  682. point1 = this.layer.vectors[wallid].geometry.points[startIndex];
  683. if (endIndex) {
  684. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  685. } else {
  686. endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state);
  687. }
  688. }
  689. //同一组墙,但是墙角不属于当前墙面
  690. else if (this.currentState.selectWallSet.index != endIndex && this.currentState.selectWallSet.index != startIndex) {
  691. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  692. this.currentState.currentendlinePointIndex = endIndex;
  693. }
  694. }
  695. //当前点在墙面
  696. else if (this.currentState.selectWallSet.type == 1) {
  697. this.currentState.currentendlinePointIndex = this.currentState.selectWallSet.endindex;
  698. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  699. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  700. wallid = this.currentState.currentWallId;
  701. startIndex = this.currentState.currentstartlinePointIndex;
  702. endIndex = this.currentState.currentendlinePointIndex;
  703. point1 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.index];
  704. point2 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.endindex];
  705. } else {
  706. alert("Move:618");
  707. }
  708. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point);
  709. } else {
  710. var line = this.calculateLine.createLine(point1, point2);
  711. joinpoint = {
  712. x: point.x,
  713. y: point.y
  714. };
  715. point = this.calculateLine.getJoinLinePoint(point, line);
  716. if (!this.calculateElement.lineContain(point1, point2, point, 1)) {
  717. return;
  718. }
  719. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, joinpoint);
  720. }
  721. var symbolLength = symbol.getSymbolLen();
  722. if (BABYLON.Vector2.Distance(point1, point) < symbolLength / 2 || BABYLON.Vector2.Distance(point2, point) < symbolLength / 2) {
  723. return;
  724. }
  725. var sp1 = {
  726. x: symbol.geometry.point1.x,
  727. y: symbol.geometry.point1.y
  728. };
  729. var sp2 = {
  730. x: symbol.geometry.point2.x,
  731. y: symbol.geometry.point2.y
  732. };
  733. this.calculateElement.updateSymbolEndPoint(symbol, point, wallid, startIndex, endIndex);
  734. var dx1 = symbol.geometry.point1.x - sp1.x;
  735. var dy1 = symbol.geometry.point1.y - sp1.y;
  736. var dx2 = symbol.geometry.point2.x - sp2.x;
  737. var dy2 = symbol.geometry.point2.y - sp2.y;
  738. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].x += dx1;
  739. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].y += dy1;
  740. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].x += dx2;
  741. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].y += dy2;
  742. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  743. symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType;
  744. symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  745. this.layer.select.f_selectWallLine = false;
  746. this.layer.control.refreshCanvas = true;
  747. this.layer.control.refreshSelectCanvas = true;
  748. };
  749. //移动Symbol上的端点
  750. Move.prototype.moveSymbolEndpoint = function (point, selectindex) {
  751. var wallid = this.draggingSymbol2dPoint.wallid;
  752. var index1 = this.draggingSymbol2dPoint.wallStartindex;
  753. var index2 = this.draggingSymbol2dPoint.wallEndindex;
  754. var selectPoint = this.draggingSymbol2dPoint.selectPoint;
  755. var noselectPoint = this.draggingSymbol2dPoint.noselectPoint;
  756. var mid = {
  757. x: (selectPoint.x + noselectPoint.x) / 2,
  758. y: (selectPoint.y + noselectPoint.y) / 2
  759. };
  760. var line = this.calculateLine.createLine(this.layer.vectors[wallid].geometry.points[index1], this.layer.vectors[wallid].geometry.points[index2]);
  761. var join = this.calculateLine.getJoinLinePoint(point, line);
  762. var point1 = this.layer.vectors[wallid].geometry.points[index1];
  763. var point2 = this.layer.vectors[wallid].geometry.points[index2];
  764. var dx, dy;
  765. var symbol = this.layer.vectors[this.currentState.currentSymbolId];
  766. if (!this.calculateLine.containPoint(point1, point2, symbol.geometry.point1) || !this.calculateLine.containPoint(point1, point2, symbol.geometry.point2)) {
  767. return;
  768. } else if (this.calculateLine.containPoint(mid, join, selectPoint) || this.calculateLine.containPoint(mid, selectPoint, join)) {
  769. if (BABYLON.Vector2.Distance(point1, symbol.geometry.point1) < symbolMinLen || BABYLON.Vector2.Distance(point2, symbol.geometry.point1) < symbolMinLen || BABYLON.Vector2.Distance(point1, symbol.geometry.point2) < symbolMinLen || BABYLON.Vector2.Distance(point2, symbol.geometry.point2) < symbolMinLen) {
  770. return;
  771. }
  772. if (BABYLON.Vector2.Distance(this.layer.vectors[wallid].geometry.points[index1], join) < symbolMinLen) {
  773. //删除symbol
  774. this.layer.select.endSelectSymbol(this.layer.select.selectSymbolIds.vectorid, this.layer.select.selectSymbolIds.selects, this.layer.select.selectSymbolIds.vectorMeasureid);
  775. this.layer.deleteSymbol(this.currentState.currentSymbolId, wallid);
  776. this.layer.control.refreshCanvas = true;
  777. return;
  778. } else if (BABYLON.Vector2.Distance(selectPoint, join) < symbolMinLen) {
  779. return;
  780. } else {
  781. dx = join.x - selectPoint.x;
  782. dy = join.y - selectPoint.y;
  783. noselectPoint.x -= dx;
  784. noselectPoint.y -= dy;
  785. selectPoint.x += dx;
  786. selectPoint.y += dy;
  787. if (this.layer.select.selectSymbolIds.selectEndPointIndex == 1) {
  788. symbol.geometry.point1 = join;
  789. symbol.geometry.point2 = noselectPoint;
  790. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = join.x;
  791. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = join.y;
  792. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = noselectPoint.x;
  793. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = noselectPoint.y;
  794. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = join;
  795. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = noselectPoint;
  796. } else {
  797. symbol.geometry.point2 = join;
  798. symbol.geometry.point1 = noselectPoint;
  799. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = join.x;
  800. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = join.y;
  801. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = noselectPoint.x;
  802. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = noselectPoint.y;
  803. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = join;
  804. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = noselectPoint;
  805. }
  806. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  807. symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  808. //symbol.geometry.points=this.calculateElement.getSymbolPoints(symbol.geometry.point1,symbol.geometry.point2,symbol.geometry.geoType,point,thick);
  809. this.layer.control.refreshCanvas = true;
  810. this.layer.control.refreshSelectCanvas = true;
  811. }
  812. }
  813. };
  814. //随墙移动
  815. Move.prototype.moveSymbolsWithWallCorner = function (wallid, index) {
  816. var symbol2ds = [];
  817. var movPoint = this.layer.vectors[wallid].geometry.points[index];
  818. for (var key in this.layer.vectors[wallid].symbol2Ds) {
  819. var fixPoint = null;
  820. var symbol2d = this.layer.vectors[wallid].symbol2Ds[key];
  821. if (symbol2d.attributes.wallstartindex == index) {
  822. symbol2ds.push(symbol2d);
  823. fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallendindex];
  824. } else if (symbol2d.attributes.wallendindex == index) {
  825. symbol2ds.push(symbol2d);
  826. fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallstartindex];
  827. } else {
  828. // break;
  829. }
  830. if (fixPoint != null) {
  831. var point = this.calculateLine.getNewSymbolPoint(symbol2d, movPoint, fixPoint);
  832. symbol2d.geometry.point1 = point.point1;
  833. symbol2d.geometry.point2 = point.point2;
  834. symbol2d.select = false;
  835. var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex);
  836. symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick);
  837. }
  838. }
  839. this.layer.control.refreshCanvas = true;
  840. };
  841. //随墙移动
  842. Move.prototype.moveSymbolsWithWallLine = function (id, startIndex, endIndex, dx, dy, flag) {
  843. var a = 1 === 2
  844. if (typeof (this.layer.vectors[id]) != "undefined" && this.layer.vectors[id].symbol2dsCount > 0) {
  845. for (var key in this.layer.vectors[id].symbol2Ds) {
  846. var newWallPoint1 = this.layer.vectors[id].geometry.points[startIndex];
  847. var newWallPoint2 = this.layer.vectors[id].geometry.points[endIndex];
  848. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  849. if ((symbol2d.attributes.wallstartindex == startIndex && symbol2d.attributes.wallendindex == endIndex) || (symbol2d.attributes.wallstartindex == endIndex && symbol2d.attributes.wallendindex == startIndex)) {
  850. if (!this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point1) || !this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point2)) {
  851. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  852. } else {
  853. var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex);
  854. if (!flag) {
  855. symbol2d.geometry.point1.x = symbol2d.geometry.point1.x + dx;
  856. symbol2d.geometry.point1.y = symbol2d.geometry.point1.y + dy;
  857. symbol2d.geometry.point2.x = symbol2d.geometry.point2.x + dx;
  858. symbol2d.geometry.point2.y = symbol2d.geometry.point2.y + dy;
  859. symbol2d.select = false;
  860. } else {
  861. var point = this.calculateLine.getNewSymbolPoint(symbol2d, newWallPoint1, newWallPoint2);
  862. symbol2d.geometry.point1 = point.point1;
  863. symbol2d.geometry.point2 = point.point2;
  864. symbol2d.select = false;
  865. }
  866. symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick);
  867. }
  868. } else if (symbol2d.attributes.wallstartindex == startIndex || symbol2d.attributes.wallendindex == startIndex) {
  869. if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint1)) {
  870. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  871. }
  872. } else if (symbol2d.attributes.wallstartindex == endIndex || symbol2d.attributes.wallendindex == endIndex) {
  873. if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint2)) {
  874. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  875. }
  876. }
  877. }
  878. }
  879. };
  880. //修改门或窗等元素的index
  881. //id表示墙id
  882. //修改该墙上所有的门、窗等物体
  883. Move.prototype.updateSymbolIndex = function (id, startIndex) {
  884. if (this.layer.vectors[id].symbol2dsCount > 0) {
  885. for (var key in this.layer.vectors[id].symbol2Ds) {
  886. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  887. if (symbol2d.attributes.wallstartindex > startIndex) {
  888. --symbol2d.attributes.wallstartindex;
  889. --this.layer.vectors[symbol2d.vectorid].startindex;
  890. } else if (symbol2d.attributes.wallstartindex == startIndex) {
  891. if (symbol2d.attributes.wallstartindex != 0) {
  892. --symbol2d.attributes.wallstartindex;
  893. --this.layer.vectors[symbol2d.vectorid].startindex;
  894. } else {
  895. symbol2d.attributes.wallstartindex = this.layer.vectors[id].geometry.points.length - 2;
  896. this.layer.vectors[symbol2d.vectorid].startindex = this.layer.vectors[id].geometry.points.length - 2;
  897. }
  898. }
  899. }
  900. }
  901. };
  902. //修改该墙上所有的门、窗等物体
  903. Move.prototype.updateSymbolIndex2 = function (id, endIndex) {
  904. if (this.layer.vectors[id].symbol2dsCount > 0) {
  905. for (var key in this.layer.vectors[id].symbol2Ds) {
  906. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  907. if (symbol2d.attributes.wallstartindex > endIndex) {
  908. --symbol2d.attributes.wallstartindex;
  909. --this.layer.vectors[symbol2d.vectorid].startindex;
  910. }
  911. }
  912. }
  913. };