UIAnchor.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * 创建UIAnchor界面
  3. * @param {Object} obj - 创建界面的父物体
  4. * @param {String} value - 创建界面的类型
  5. */
  6. function createUIAnchor(floorNum) {
  7. let anchorCreateJson = {
  8. type: "UIAnchor",
  9. // element: $(".pictureMarker")[0],
  10. // position: [100, -10, -21],
  11. // parent: app.query('#1F1FS01')[0],
  12. // pivotPixel: [parseFloat($(".textAndPictureMarker").css("width")) / 2, parseFloat($(".textAndPictureMarker").css("height"))],
  13. }
  14. var s = app.query('#' + floorNum)[0];
  15. let n = Math.ceil(Math.random() * 10)
  16. anchorCreateJson.element = $(".textAndPictureMarker")[0];
  17. //anchorCreateJson.position = [5, 2, n];
  18. anchorCreateJson.parent = app.query('#' + floorNum)[0];
  19. anchorCreateJson.pivotPixel = [parseFloat($(".textAndPictureMarker").css("width")) / 2, parseFloat($(".textAndPictureMarker").css("height"))];
  20. let tempTopCard = app.create(anchorCreateJson); // 创建顶牌
  21. tempTopCard.visible = true; // 设置初始顶牌状态
  22. }
  23. function deviceIcon_click(dwtype, floorNum, ownercode) {
  24. let funcName = "icon_click";
  25. var data = {
  26. 'dwtype': dwtype,
  27. 'level': floorNum,
  28. 'id': ownercode
  29. }
  30. var message = {
  31. 'funcName': funcName, // 所要调用父页面里的函数名
  32. 'param': data
  33. }
  34. // 向父窗体(用户主页面)发送消息
  35. // 第一个参数是具体的信息内容,
  36. // 第二个参数是接收消息的窗口的源(origin),即"协议 + 域名 + 端口"。也可以设为*,表示不限制域名,向所有窗口发送
  37. window.parent.postMessage(message, '*');
  38. }
  39. //======================================================================================================================
  40. // 添加html
  41. function create_html() {
  42. var sign =
  43. `<div
  44. </div>`
  45. $('#div3d').append($(sign));
  46. }
  47. function create_element(dName, deviceTypes, floorNum, ownercode) {
  48. var srcElem = document.getElementById('board');
  49. if (deviceTypes == 'YTVA') {
  50. var sign =
  51. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  52. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  53. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9mvD.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  54. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  55. </div>
  56. </div>`
  57. } else if (deviceTypes == 'YTWP') {
  58. var sign =
  59. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  60. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  61. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9GPP.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  62. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  63. </div>
  64. </div>`
  65. } else if (deviceTypes == 'YTCI') {
  66. var sign =
  67. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  68. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  69. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J935t.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  70. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  71. </div>
  72. </div>`
  73. } else if (deviceTypes == 'YTEF') {
  74. var sign =
  75. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  76. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  77. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J91UI.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  78. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  79. </div>
  80. </div>`
  81. } else if (deviceTypes == 'YTFC') {
  82. var sign =
  83. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  84. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  85. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9lVA.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  86. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  87. </div>
  88. </div>`
  89. } else if (deviceTypes == 'YTSM') {
  90. var sign =
  91. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  92. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  93. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9Mbd.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  94. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  95. </div>
  96. </div>`
  97. } else if (deviceTypes == 'YTLL') {
  98. var sign =
  99. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  100. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  101. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9J8f.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  102. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  103. </div>
  104. </div>`
  105. } else if (deviceTypes == 'YTWI') {
  106. var sign =
  107. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  108. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  109. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url(https://s3.ax1x.com/2021/03/10/6J9Y28.png) no-repeat center;margin: 1px 1px 1px 5px;"></span>
  110. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  111. </div>
  112. </div>`
  113. } else if (deviceTypes == 'YTWG') {
  114. var sign =
  115. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  116. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  117. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url('/uploads/wechat/163607/file/杨浦16/icons/YTWG.png') no-repeat center;margin: 1px 1px 1px 5px;"></span>
  118. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  119. </div>
  120. </div>`
  121. } else if (deviceTypes == 'YTRU') {
  122. var sign =
  123. `<div class="sign" id=${dName} style="font-size: 12px;width: 120px;text-align: center;background-color: rgba(0, 0, 0, .6);border: 0px solid #eeeeee;border-radius: 8px;color: #eee;position: absolute;top: 0;left: 0;z-index: 10;display: none;">
  124. <div class="s1" style="margin: 5px 0px 5px 0px;line-height: 32px;overflow: hidden;">
  125. <span class="span-l icon" style="float: left;width: 30px;height: 30px;background:url('/uploads/wechat/163607/file/杨浦16/icons/YTRU.png') no-repeat center;margin: 1px 1px 1px 5px;"></span>
  126. <span class="span-l font" style="float: left;margin: 0px 0px 0px 1px;">${dName}</span>
  127. </div>
  128. </div>`
  129. }
  130. $('#div3d').append($(sign));
  131. var newElem = document.getElementById(dName);
  132. // var newElem = srcElem.cloneNode(true);
  133. newElem.style.display = "block";
  134. newElem.setAttribute("onclick", "deviceIcon_click('" + deviceTypes + "','" + floorNum + "','" + ownercode + "')");
  135. app.domElement.insertBefore(newElem, srcElem);
  136. return newElem;
  137. }
  138. // 物体顶界面
  139. var ui = null;
  140. var uis = [];
  141. var position = []
  142. var list = []
  143. function create_ui(deviceType, floorNum, deviceList) {
  144. var deviceTypes = deviceType;
  145. destroy_ui();
  146. create_html();
  147. deviceIcon = [];
  148. for (var j = 0; j < deviceList.length; j++) {
  149. if (deviceList[j].dwtype == deviceType) {
  150. deviceIcon.push(deviceList[j]);
  151. }
  152. }
  153. if (deviceType == 'YTVA') {
  154. deviceType = '摄像头';
  155. } else if (deviceType == 'YTWP') {
  156. deviceType = '水表';
  157. } else if (deviceType == 'YTCI') {
  158. deviceType = '环境监测';
  159. } else if (deviceType == 'YTEF') {
  160. deviceType = '电气火灾';
  161. } else if (deviceType == 'YTFC') {
  162. deviceType = '消防控制柜';
  163. } else if (deviceType == 'YTSM') {
  164. deviceType = '烟感';
  165. } else if (deviceType == 'YTLL') {
  166. deviceType = '液位';
  167. } else if (deviceType == 'YTWI') {
  168. deviceType = '水浸';
  169. } else if (deviceType == 'YTWG') {
  170. deviceType = '网关';
  171. } else if (deviceType == 'YTRU') {
  172. deviceType = '4G路由';
  173. }
  174. let num;
  175. if (floorNum == -1) {
  176. num = 'B1'
  177. } else {
  178. num = 'F' + floorNum;
  179. }
  180. var carList = app.query("#" + num)[0].query(deviceType)
  181. var carList1 = app.query("#" + num)[0]
  182. var carList2 = app.query(".Room")[0]
  183. var url = '';
  184. var scale; //物体大小
  185. var parent;
  186. for (var i = 0; i < deviceIcon.length; i++) {
  187. // console.log(deviceIcon[i])
  188. dName = deviceIcon[i].device_name;
  189. var ownercode = deviceIcon[i].owner_code
  190. if (carList[i] == undefined) {
  191. if (deviceType == '烟感') {
  192. url = '/api/models/641A9B800DE5431E8C84DC290F8EFDE6/0/gltf/'
  193. scale = [2, 2, 2]
  194. } else if (deviceType == '摄像头') {
  195. url = '/api/models/2DBD1DCD7B5F49BDA43CC6444FC5CBD0/0/gltf/'
  196. scale = [2, 2, 2]
  197. } else {
  198. url = '/api/models/5BD84A6968384A3F919DE8B82DD7D7DC/0/gltf/'; //万能圆球
  199. scale = [0.1, 0.1, 0.1]
  200. }
  201. var position_1 = [carList1.position[0], carList1.position[1] + 3, carList1.position[2] + i - 3]
  202. if (carList2 == undefined) {
  203. position = position_1
  204. } else {
  205. if (num == 'B1') {
  206. if (carList2.name == '水泵房') {
  207. position = [carList2.position[0], carList2.position[1] + 3, carList2.position[2] + i - 3]
  208. } else {
  209. position = position_1
  210. }
  211. } else {
  212. position = position_1
  213. }
  214. }
  215. // console.log(carList2)
  216. truck = app.create({
  217. type: 'Thing',
  218. name: deviceType,
  219. url: url,
  220. id: deviceType + i,
  221. position: position,
  222. angle: 0,
  223. angles: [0, 270, 0],
  224. scale: scale
  225. });
  226. list.push(truck)
  227. parent = truck
  228. } else {
  229. parent = carList[i]
  230. }
  231. ui = app.create({
  232. type: 'UIAnchor',
  233. parent: parent,
  234. element: create_element(dName, deviceTypes, floorNum, ownercode),
  235. localPosition: [0, 2, 0],
  236. pivot: [0.5, 1] // [0,0]即以界面左上角定位,[1,1]即以界面右下角进行定位
  237. });
  238. uis.push(ui);
  239. }
  240. }
  241. // 删除界面
  242. function destroy_ui() {
  243. if (uis) {
  244. for (var i = 0; i < uis.length; i++) {
  245. uis[i].destroy();
  246. }
  247. uis = [];
  248. }
  249. if (list) {
  250. for (var i = 0; i < list.length; i++) {
  251. list[i].destroy();
  252. }
  253. list = [];
  254. }
  255. }