loadCAD.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. window.grendCAD = (function grendCAD() {
  2. let initFloor
  3. // let initDOM
  4. let point, dire
  5. window.cad = {
  6. setSign: function(p, d) {
  7. point = p
  8. dire = d
  9. }
  10. }
  11. function loadDOM($parent,id) {
  12. // if (initDOM) return initDOM;
  13. let $layer = document.createElement('div')
  14. let $cad = document.createElement('div')
  15. $layer.className = id
  16. $cad.id = id
  17. $layer.appendChild($cad)
  18. let style = document.createElement('style')
  19. style.innerHTML = `
  20. .${id} {
  21. position: fixed;
  22. right: -260px;
  23. top: 90px;
  24. width: 260px;
  25. height: 200px;
  26. z-index: 99;
  27. transition: all 0.3s ease;
  28. }
  29. .${id} > div {
  30. width: 100%;
  31. height: 100%;
  32. }
  33. @media only screen and (max-width: 600px) {
  34. .${id} {
  35. position: absolute;
  36. left: 16px;
  37. top: 65px;
  38. width: 100px;
  39. height: 100px;
  40. background: rgba(0, 0, 0, .3);
  41. border-radius: 5px;
  42. }
  43. }
  44. `
  45. $parent.appendChild(style)
  46. $parent.appendChild($layer)
  47. return $layer
  48. }
  49. function setStyle(signColor, borderColor, borderWidth) {
  50. cad.setDefaultPointStyle({
  51. fillColor: "rgba(0,0,0,0)",
  52. storkeColor: "rgba(0,0,0,0)"
  53. });
  54. console.log(borderWidth)
  55. cad.setDefaultLineStyle({
  56. width: borderWidth,
  57. color: borderColor
  58. });
  59. console.log('执行===============');
  60. cad.setDefaultSignStyle({
  61. color: signColor,
  62. r: 6,
  63. })
  64. }
  65. return function(floor, $parent, signColor, borderColor, borderWidth, id) {
  66. // if (initFloor) {
  67. // console.log('cache')
  68. // return setStyle(signColor, borderColor, borderWidth)
  69. // }
  70. console.log('load')
  71. initFloor = floor
  72. let $layer = loadDOM($parent,id)
  73. $layer.style.visibility = 'hidden'
  74. window.cad = structureCAD({
  75. data: {
  76. block: [],
  77. column: [],
  78. door: [],
  79. hole: [],
  80. segment: [],
  81. "vertex-xy": [],
  82. "vertex-z": [],
  83. },
  84. layer: $layer.querySelector('#'+id),
  85. edit: false
  86. });
  87. setStyle(signColor, borderColor, borderWidth)
  88. cad.hideDire()
  89. cad.hideGauge()
  90. console.log('loadData')
  91. cad.loadData(initFloor);
  92. if (point && dire) {
  93. window.cad.setSign(point, dire)
  94. }
  95. $layer.style.visibility = 'visible'
  96. }
  97. })();
  98. if (window.number == '1149_2') {
  99. $.ajax({
  100. url: 'static/data/first_floor.json',
  101. method: 'GET',
  102. success(res) {
  103. grendCAD(res, document.documentElement, '#4f7d71', '#fcf5d3', '1px','cad1')
  104. $.ajax({
  105. url: 'static/data/second_floor.json',
  106. method: 'GET',
  107. success(res) {
  108. grendCAD(res, document.documentElement, '#4f7d71', '#fcf5d3', '1px','cad')
  109. }
  110. })
  111. }
  112. })
  113. }
  114. if (window.number == '1152_1') {
  115. $.ajax({
  116. url: 'static/data/floor_1152.json',
  117. method: 'GET',
  118. success(res) {
  119. grendCAD(res, document.documentElement, '#4f7d71', '#fcf5d3', '1px','cad')
  120. }
  121. })
  122. }
  123. // $.ajax({
  124. // url: g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(),
  125. // method: 'GET',
  126. // success(data) {
  127. // if (!data.showCad) return
  128. // }
  129. // })