loadCAD.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. {
  2. let $layer = document.createElement('div')
  3. let $cad = document.createElement('div')
  4. $layer.className = 'cad'
  5. $cad.id = 'cad'
  6. $layer.appendChild($cad)
  7. document.documentElement.appendChild($layer)
  8. let style = document.createElement('style')
  9. style.innerHTML = `
  10. .cad {
  11. position: absolute;
  12. right: 80px;
  13. top: 16px;
  14. width: 200px;
  15. height: 200px;
  16. background: rgba(0, 0, 0, .3);
  17. border-radius: 5px;
  18. display: none;
  19. }
  20. .cad > div {
  21. width: 100%;
  22. height: 100%;
  23. }
  24. @media only screen and (max-width: 600px) {
  25. .cad {
  26. position: absolute;
  27. left: 16px;
  28. top: 65px;
  29. width: 100px;
  30. height: 100px;
  31. background: rgba(0, 0, 0, .3);
  32. border-radius: 5px;
  33. }
  34. }
  35. `
  36. //解析查询字符串
  37. function getQueryStringArgs() {
  38. //取得查询字符串,并去掉开头'?'
  39. var qs = location.search.length ? location.search.substring(1) : '';
  40. //保存数据的对象
  41. var args = {},
  42. //以分割符'&'分割字符串,并以数组形式返回
  43. items = qs.length ? qs.split('&') : [],
  44. item = null,
  45. name = null,
  46. value = null,
  47. i = 0,
  48. len = items.length;
  49. //逐个将每一项添加到args对象中
  50. for (; i < len; i++) {
  51. item = items[i].split('=');
  52. //解码操作,因为查询字符串经过编码的
  53. name = decodeURIComponent(item[0]);
  54. value = decodeURIComponent(item[1]);
  55. value = item[1];
  56. if (name.length) {
  57. args[name] = value;
  58. }
  59. }
  60. return args;
  61. }
  62. function getData(url, cb) {
  63. $.ajax({
  64. method: 'GET',
  65. url: url,
  66. success(data) {
  67. cb(null, data)
  68. },
  69. error(e) {
  70. cb(e)
  71. }
  72. })
  73. }
  74. let code = getQueryStringArgs().m
  75. let data, styleArg
  76. getData('/CAD/static/data/'+ code +'/floor.json', (err, args) => {
  77. if (!err) {
  78. data = args
  79. grentCAD()
  80. }
  81. })
  82. getData('/CAD/static/data/'+ code +'/style.json', (err, args) => {
  83. if (err) {
  84. styleArg = {
  85. line: {
  86. color: '#fff',
  87. width: 1
  88. },
  89. sign: {
  90. color: 'rgb(0, 200, 175)'
  91. }
  92. }
  93. } else {
  94. styleArg = args
  95. }
  96. grentCAD()
  97. })
  98. let point, dire
  99. window.cad = {
  100. setSign: function(p, d) {
  101. point = p
  102. dire = d
  103. }
  104. }
  105. function grentCAD() {
  106. if (!(data && styleArg)) return;
  107. $layer.style.display = 'none'
  108. window.cad = structureCAD({
  109. data: {
  110. block: [],
  111. column: [],
  112. door: [],
  113. hole: [],
  114. segment: [],
  115. "vertex-xy": [],
  116. "vertex-z": [],
  117. },
  118. layer: $cad,
  119. edit: false
  120. });
  121. cad.setDefaultPointStyle({
  122. fillColor: "rgba(0,0,0,0)",
  123. storkeColor: "rgba(0,0,0,0)"
  124. });
  125. cad.setDefaultLineStyle({
  126. width: styleArg.line.width,
  127. color: styleArg.line.color
  128. });
  129. cad.setDefaultSignStyle({
  130. color: styleArg.sign.color
  131. })
  132. cad.hideDire()
  133. cad.hideGauge()
  134. cad.loadData(data);
  135. if (point && dire) {
  136. window.cad.setSign(point, dire)
  137. }
  138. $layer.style.display = 'block'
  139. }
  140. }