index.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>文档</title>
  8. <script src="https://ore.cdchuanxi.cn/assets/libs/jquery/dist/jquery.js"></script>
  9. <script src="./Cesium/Cesium.js"></script>
  10. <link rel="stylesheet" href="./Cesium/Widgets/widgets.css" />
  11. <script src="./index.js"></script>
  12. <style>
  13. * {
  14. margin: 0;
  15. padding: 0;
  16. }
  17. body {
  18. overflow: hidden;
  19. }
  20. #bubble {
  21. position: absolute;
  22. bottom: 0;
  23. left: 0;
  24. background-repeat: no-repeat;
  25. background-size: 100% 100%;
  26. display: none;
  27. }
  28. .tools {
  29. text-align: center;
  30. font-size: 18px;
  31. font-family: MFLiHei;
  32. font-weight: 400;
  33. color: #ffffff;
  34. margin-top: 12px;
  35. }
  36. .tableContainer {
  37. font-size: 16px;
  38. line-height: 16px;
  39. font-weight: bold;
  40. color: #ffffff;
  41. }
  42. .font_content {
  43. display: flex;
  44. align-items: center;
  45. flex-wrap: wrap;
  46. justify-content: space-between;
  47. }
  48. .font_item {
  49. display: flex;
  50. align-items: center;
  51. width: 100%;
  52. padding: 10px 0;
  53. }
  54. .font_item .label {
  55. min-width: 80px;
  56. }
  57. .font_item .value {
  58. flex: 1;
  59. }
  60. .wid50 {
  61. width: 50%;
  62. }
  63. .flex {
  64. display: flex;
  65. align-items: center;
  66. }
  67. .paifang .title {
  68. font-size: 18px;
  69. font-weight: 400;
  70. color: #ffffff;
  71. background-image: url(https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/17.png);
  72. background-repeat: no-repeat;
  73. padding: 0 0 10px 20px;
  74. background-position-y: 3px;
  75. margin-top: 20px;
  76. }
  77. #toolbar {
  78. position: fixed;
  79. top: 20px;
  80. left: 40px;
  81. }
  82. #toolbar input {
  83. height: 30px;
  84. padding: 0 10px;
  85. }
  86. #toolbar button {
  87. padding: 5px 15px;
  88. /* color:#fff */
  89. cursor: pointer;
  90. }
  91. </style>
  92. </head>
  93. <body>
  94. <div id="mapcontain" style="width: 100vw; height: 100vh"></div>
  95. <div id="toolbar" class="param-container tool-bar">
  96. <button type="button" id="polyline" class="button black">360航拍</button>
  97. <!-- <button type="button" id="clear" class="button black">清除</button>
  98. <input type="number" id="number" placeholder="输入浮动数值">
  99. <button id="float">浮动</button>
  100. <button id="save">复制参数</button>
  101. <input type="text" id="lineResult" style="opacity: 0;"> -->
  102. </div>
  103. <!-- 气泡HTML -->
  104. <div id="bubble" class="bubble">
  105. <div class="tools"></div>
  106. <div class="tableContainer"></div>
  107. </div>
  108. </body>
  109. <script>
  110. var viewer = new Cesium.Viewer('mapcontain', {
  111. infoBox: false,
  112. selectionIndicator: false,
  113. });
  114. var scene = viewer.scene;
  115. // var ssss = [{"x":-1298763.6207643023,"y":5399411.728243748,"z":3138209.945266086},{"x":-1298760.6085292918,"y":5399227.055698713,"z":3138328.4980496666},{"x":-1298673.8423515118,"y":5399231.107678385,"z":3138364.636878104},{"x":-1298677.5134506563,"y":5399413.8824037975,"z":3138248.508397252},{"x":-1298762.7671545176,"y":5399402.47754085,"z":3138215.646181551}]
  116. // var polylineEntity = viewer.entities.add({
  117. // polyline: {
  118. // positions:ssss,
  119. // width: 20,
  120. // material: new Cesium.PolylineGlowMaterialProperty({
  121. // glowPower: 0.1,
  122. // color: Cesium.Color.YELLOW
  123. // })
  124. // }
  125. // })
  126. // var ssss = [{ "x": -1298745.327110022, "y": 5399592.358043281, "z": 3137858.9501997 }, { "x": -1298828.4080866768, "y": 5399543.093048332, "z": 3137909.4185346463 }, { "x": -1298768.9944202919, "y": 5399500.561986198, "z": 3137979.1555163916 }, { "x": -1298687.370761928, "y": 5399544.930584177, "z": 3137964.4642523234 }, { "x": -1298731.9210349075, "y": 5399582.995774194, "z": 3137886.772885283 }, { "x": -1298750.1782605655, "y": 5399596.348977975, "z": 3137853.8099602973 }, { "x": -1298746.6629520853, "y": 5399591.450717748, "z": 3137861.394224519 }]
  127. // for(var i=0;i<ssss.length;i++){
  128. // ssss[i].y+=20
  129. // }
  130. // console.log(ssss);
  131. // var tooltip = createTooltip(document.body);
  132. var x1 =[{"x":-1298382.5241493038,"y":5399414.464683887,"z":3138232.257426386},{"x":-1298375.9595880932,"y":5399410.401712257,"z":3138237.3715363783},{"x":-1298366.9506741923,"y":5399415.260397395,"z":3138223.6662184484},{"x":-1298373.3944584492,"y":5399420.301661751,"z":3138214.563328331},{"x":-1298382.0080868679,"y":5399414.084060312,"z":3138232.661454434}]
  133. var x2 =[{"x":-1297963.165030857,"y":5400381.30034336,"z":3137530.678933297},{"x":-1297948.5434228266,"y":5400409.608628515,"z":3137488.69569353},{"x":-1297969.2949100637,"y":5400399.843882703,"z":3137484.7925228556},{"x":-1297976.3478639415,"y":5400380.822944763,"z":3137521.3906440507},{"x":-1297962.6820639062,"y":5400382.313172652,"z":3137529.1376143084}]
  134. var x3 = [{"x":-1297951.379699481,"y":5400929.154787579,"z":3136907.1546409023},{"x":-1297922.9491903689,"y":5400931.336259261,"z":3136922.449279351},{"x":-1297920.7762863487,"y":5400849.217535222,"z":3137006.5530004613},{"x":-1297957.9633402936,"y":5400846.120943799,"z":3136988.629034852},{"x":-1297950.3702054168,"y":5400931.034650669,"z":3136906.1637204266}]
  135. var x4 = [{"x":-1299107.3349838604,"y":5399012.88798698,"z":3138339.657768483},{"x":-1299065.289684003,"y":5399013.501809057,"z":3138346.3060638327},{"x":-1299090.6493302553,"y":5399004.940458745,"z":3138383.355116148},{"x":-1299110.9115068347,"y":5399002.325859704,"z":3138352.223800444},{"x":-1299106.946729713,"y":5399013.105881288,"z":3138338.547136601}]
  136. var polylineEntity = viewer.entities.add({
  137. polyline: {
  138. positions: x1,
  139. width: 30,
  140. material: new Cesium.PolylineGlowMaterialProperty({
  141. glowPower: 0.1,
  142. color: Cesium.Color.YELLOW
  143. })
  144. }
  145. })
  146. viewer.entities.add({
  147. id: 'xxx1',
  148. position: Cesium.Cartesian3.fromDegrees(103.52094734042181,29.47108017329263, 575.53),
  149. billboard: {
  150. image:'https://cdn.sckaiwu.cn/saas/uploads/202307/64a556419e578.png',
  151. scaleByDistance: new Cesium.NearFarScalar(0, 0.8, 10000, 0.1)
  152. },
  153. description:'dzwl' // 自定义信息
  154. });
  155. viewer.entities.add({
  156. polyline: {
  157. positions: x2,
  158. width: 30,
  159. material: new Cesium.PolylineGlowMaterialProperty({
  160. glowPower: 0.1,
  161. color: Cesium.Color.YELLOW
  162. })
  163. }
  164. });
  165. viewer.entities.add({
  166. id: 'xxx2',
  167. position: Cesium.Cartesian3.fromDegrees(103.52904340847827,29.472956215602114, 440.26),
  168. billboard: {
  169. image:'https://cdn.sckaiwu.cn/saas/uploads/202307/64a556419e578.png',
  170. scaleByDistance: new Cesium.NearFarScalar(0, 0.8, 10000, 0.1)
  171. },
  172. description:'dzwl' // 自定义信息
  173. });
  174. viewer.entities.add({
  175. polyline: {
  176. positions: x3,
  177. width: 30,
  178. material: new Cesium.PolylineGlowMaterialProperty({
  179. glowPower: 0.1,
  180. color: Cesium.Color.YELLOW
  181. })
  182. }
  183. });
  184. viewer.entities.add({
  185. id: 'xxx3',
  186. position: Cesium.Cartesian3.fromDegrees(103.51444717577903,29.461569285227476, 962.33),
  187. billboard: {
  188. image:'https://cdn.sckaiwu.cn/saas/uploads/202307/64a556419e578.png',
  189. scaleByDistance: new Cesium.NearFarScalar(0, 0.8, 10000, 0.1)
  190. },
  191. description:'dzwl' // 自定义信息
  192. });
  193. viewer.entities.add({
  194. polyline: {
  195. positions: x4,
  196. width: 30,
  197. material: new Cesium.PolylineGlowMaterialProperty({
  198. glowPower: 0.1,
  199. color: Cesium.Color.YELLOW
  200. })
  201. }
  202. });
  203. viewer.entities.add({
  204. id: 'xxx4',
  205. position: Cesium.Cartesian3.fromDegrees(103.51297946650449,29.455285607173614,1110.82),
  206. billboard: {
  207. image:'https://cdn.sckaiwu.cn/saas/uploads/202307/64a556419e578.png',
  208. scaleByDistance: new Cesium.NearFarScalar(0, 0.8, 10000, 0.1)
  209. },
  210. description:'dzwl' // 自定义信息
  211. });
  212. var lineWidth = 20
  213. $('#xiugai').click(function () {
  214. if ($('#lineWidth').val().length == 0) {
  215. return false
  216. }
  217. console.log(linePoints);
  218. lineWidth = Number($('#lineWidth').val())
  219. clearAll();
  220. viewer.entities.removeAll();
  221. var polylineEntity = viewer.entities.add({
  222. polyline: {
  223. positions: temp ? temp : linePoints,
  224. width: lineWidth,
  225. material: new Cesium.PolylineGlowMaterialProperty({
  226. glowPower: 0.1,
  227. color: Cesium.Color.YELLOW
  228. })
  229. }
  230. })
  231. })
  232. var temp = null
  233. $('#float').click(function () {
  234. console.log(linePoints);
  235. clearAll();
  236. viewer.entities.removeAll();
  237. temp = JSON.parse(JSON.stringify(linePoints))
  238. if ($('#number').val().length == 0) {
  239. return false
  240. }
  241. for (var i = 0; i < temp.length; i++) {
  242. temp[i].y += Number($('#number').val())
  243. }
  244. var polylineEntity = viewer.entities.add({
  245. polyline: {
  246. positions: temp,
  247. width: lineWidth,
  248. material: new Cesium.PolylineGlowMaterialProperty({
  249. glowPower: 0.1,
  250. color: Cesium.Color.YELLOW
  251. })
  252. }
  253. });
  254. });
  255. var handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
  256. handlerPoint.activeEvt.addEventListener(function (isActive) {
  257. if (isActive == true) {
  258. viewer.enableCursorStyle = false;
  259. viewer._element.style.cursor = '';
  260. $('body').removeClass('drawCur').addClass('drawCur');
  261. } else {
  262. viewer.enableCursorStyle = true;
  263. $('body').removeClass('drawCur');
  264. }
  265. });
  266. handlerPoint.movingEvt.addEventListener(function (windowPosition) {
  267. // tooltip.showAt(windowPosition, '<p>点击绘制一个点</p>');
  268. });
  269. var point;//存储画点的节点
  270. handlerPoint.drawEvt.addEventListener(function (result) {
  271. // tooltip.setVisible(false);
  272. point = result.object.position;
  273. });
  274. var handlerLine = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Line);
  275. handlerLine.activeEvt.addEventListener(function (isActive) {
  276. if (isActive == true) {
  277. viewer.enableCursorStyle = false;
  278. viewer._element.style.cursor = '';
  279. $('body').removeClass('drawCur').addClass('drawCur');
  280. } else {
  281. viewer.enableCursorStyle = true;
  282. $('body').removeClass('drawCur');
  283. }
  284. });
  285. handlerLine.movingEvt.addEventListener(function (windowPosition) {
  286. if (handlerLine.isDrawing) {
  287. // tooltip.showAt(windowPosition, '<p>左键点击确定折线中间点</p><p>右键单击结束绘制</p>');
  288. } else {
  289. // tooltip.showAt(windowPosition, '<p>点击绘制第一个点</p>');
  290. }
  291. });
  292. var linePoints;//存储画线的节点
  293. handlerLine.drawEvt.addEventListener(function (result) {
  294. console.log(result.object);
  295. // tooltip.setVisible(false);
  296. // result.object.show = false;
  297. linePoints = result.object.positions;
  298. var polylineEntity = viewer.entities.add({
  299. polyline: {
  300. positions: linePoints,
  301. width: 20,
  302. material: new Cesium.PolylineGlowMaterialProperty({
  303. glowPower: 0.1,
  304. color: Cesium.Color.YELLOW
  305. })
  306. }
  307. });
  308. console.log(linePoints);
  309. });
  310. $('#save').click(function () {
  311. $('#lineResult').val(temp ? temp : linePoints)
  312. var str = JSON.stringify(temp ? temp : linePoints);
  313. var $temp = $('<input>');
  314. $('body').append($temp);
  315. $temp.val(str).select();
  316. document.execCommand('copy');
  317. $temp.remove();
  318. alert('复制成功!');
  319. });
  320. $('#point').click(function () {
  321. deactiveAll();
  322. handlerPoint.activate();
  323. });
  324. $('#polyline').click(function () {
  325. window.open('https://www.720yun.com/vr/e9djOr4vsk2')
  326. // deactiveAll();
  327. // handlerLine.activate();
  328. });
  329. $('#clear').click(function () {
  330. clearAll();
  331. point = undefined;
  332. linePoints = undefined;
  333. viewer.entities.removeAll();
  334. });
  335. $('#toolbar').show();
  336. $('#loadingbar').remove();
  337. function deactiveAll() {
  338. handlerPoint.deactivate();
  339. handlerLine.deactivate();
  340. }
  341. function clearAll() {
  342. // handlerPoint.clear();
  343. handlerLine.clear();
  344. }
  345. if (!scene.pickPositionSupported) {
  346. alert('不支持深度拾取,无法进行鼠标交互绘制!');
  347. }
  348. // 关闭地球模型
  349. scene.globe.show = false;
  350. $(function () {
  351. // 去掉地图自带左下角logo图
  352. $('.cesium-viewer-bottom').hide();
  353. });
  354. // iframe向vue传递信息
  355. function iframeSendMsg(params, cmd = 'myIframe') {
  356. window.parent.postMessage(
  357. {
  358. cmd: cmd,
  359. params: params
  360. },
  361. '*'
  362. );
  363. }
  364. // iframe获取Vue传递过来的信息
  365. window.addEventListener('message', getVueMsg);
  366. function getVueMsg(event) {
  367. const res = event.data;
  368. if (res.cmd == 'superMap') {
  369. if (res.params.type == 'mapUrl') {
  370. scene.open(res.params.url);
  371. } else if (res.params.type == 'delete') {
  372. console.log('删除', res.params.info);
  373. removeMarker(res.params.info.guid);
  374. } else if (res.params.type == 'addOrEdit') {
  375. if (viewer.entities.getById(res.params.info.guid)) {
  376. console.log('更新', res.params.info);
  377. if (res.params.info.type == 1) {
  378. updateModalMarker(res.params.info);
  379. } else {
  380. updateMarker(res.params.info);
  381. }
  382. } else {
  383. console.log('新增', res.params.info);
  384. createPoint(res.params.info);
  385. }
  386. if (!res.params.loadedMap) iframeSendMsg({ id: res.params.info.guid }, 'receipt');
  387. }
  388. }
  389. }
  390. // 更新点标记 marker
  391. function updateModalMarker(info) {
  392. const item = viewer.entities.getById(info.guid);
  393. item.position._value = Cesium.Cartesian3.fromDegrees(info.longitude, info.latitude, info.height);
  394. item._description._value = info;
  395. item._model._uri._value = getModalIconUrl(info);
  396. }
  397. // 更新点标记 marker
  398. function updateMarker(info) {
  399. const item = viewer.entities.getById(info.guid);
  400. item.position._value = Cesium.Cartesian3.fromDegrees(info.longitude, info.latitude, info.height);
  401. item.description._value = info;
  402. item.billboard.image._value = getIconUrl(info);
  403. }
  404. // 移除点标记
  405. function removeMarker(guid) {
  406. viewer.entities.remove(viewer.entities.getById(guid));
  407. }
  408. // 添加自定义marker
  409. function createPoint(worldPosition) {
  410. if (worldPosition.type == 1) {
  411. viewer.entities.add({
  412. id: worldPosition.guid,
  413. position: Cesium.Cartesian3.fromDegrees(worldPosition.longitude, worldPosition.latitude, worldPosition.height),
  414. model: {
  415. uri: 'https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/3dCar/car.glb',
  416. scale: 0.1
  417. },
  418. description: worldPosition // 自定义信息
  419. });
  420. } else {
  421. viewer.entities.add({
  422. id: worldPosition.guid,
  423. position: Cesium.Cartesian3.fromDegrees(worldPosition.longitude, worldPosition.latitude, worldPosition.height),
  424. billboard: {
  425. image: getIconUrl(worldPosition),
  426. scaleByDistance: new Cesium.NearFarScalar(0, 2, 10000, 0.1)
  427. },
  428. description: worldPosition // 自定义信息
  429. });
  430. }
  431. }
  432. // 获取自定义marker图标地址
  433. function getModalIconUrl(worldPosition) {
  434. return `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/icon_${worldPosition.status}/${worldPosition.type
  435. }.glb?res=${new Date()}`;
  436. }
  437. // 获取自定义marker图标地址
  438. function getIconUrl(worldPosition) {
  439. return `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/icon_${worldPosition.status}/${worldPosition.type
  440. }.png?res=${new Date()}`;
  441. }
  442. // 根据经纬度获取高度
  443. // function getHeigthByLonLat(lon, lat) {
  444. // return new Promise((resolve, reject) => {
  445. // var postData = {
  446. // geometries: [{ type: 'POINT3D', x: lon, y: lat, z: 0 }], // 几何对象列表
  447. // sceneName: '金顶矿山', // 场景名
  448. // layerName: 'Config_ems', // 图层名
  449. // interpolationDistance: 0 // 插值距离
  450. // };
  451. // $.ajax({
  452. // url:
  453. // 'http://10.10.10.49:8090/iserver/services/spatialAnalysis-work/restjsr/spatialanalyst/geometry/3d/extractvector3d.json',
  454. // type: 'POST',
  455. // data: JSON.stringify(postData),
  456. // success: function(res) {
  457. // $.ajax({
  458. // url: `http://10.10.10.49:8090/iserver/services/spatialAnalysis-work/restjsr/spatialanalyst/geometry/3d/extractvector3d/${res.newResourceID}.json`,
  459. // type: 'GET',
  460. // success: function(data) {
  461. // resolve(data.geometries[0].z);
  462. // }
  463. // });
  464. // }
  465. // });
  466. // });
  467. // }
  468. // 循环添加点标记
  469. // forMarker();
  470. // function forMarker() {
  471. // for (let index = 0; index < pointPosition.length; index++) {
  472. // const element = pointPosition[index];
  473. // createPoint(element);
  474. // }
  475. // }
  476. var scenePosition = null; // 记录在场景中点击的笛卡尔坐标点
  477. var infoboxContainer = document.getElementById('bubble');
  478. var table = document.getElementById('tab'); // 气泡内的表格
  479. // 点击marker事件
  480. function annotate(pickedObject) {
  481. console.log(pickedObject.id._description._value);
  482. let obj = pickedObject.id._description._value;
  483. if(obj=='dzwl'){
  484. obj={
  485. status:1,
  486. type:13,
  487. showInfo:{
  488. '电子围栏':''
  489. }
  490. }
  491. }
  492. if (obj.type != 8) {
  493. buildModalHtml(obj);
  494. } else {
  495. iframeSendMsg({ info: obj });
  496. }
  497. }
  498. // 生成弹窗html
  499. function buildModalHtml(obj) {
  500. $('#bubble').css({ backgroundImage: `url(${getModalBg(obj)})` });
  501. if (obj.type == 1 || obj.type == 2 || obj.type == 3) {
  502. $('#bubble').css({ width: '486px', height: '330px' });
  503. $('#bubble .tableContainer').css({ padding: '0 50px' });
  504. $('#bubble .tools').text(obj.type == 1 ? '普通车辆' : obj.type == 2 ? '装载机械' : '矿卡');
  505. var html = `<div style="height: 130px;margin: 20px 0 0;text-align: center;"><img src="${obj.imgUrl
  506. ? obj.imgUrl
  507. : `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/default_image/${obj.type}.png`
  508. }" style="max-height:130px;"/></div>`;
  509. html += '<div class="font_content">';
  510. Object.keys(obj.showInfo).map((item, i) => {
  511. html += `<div class="font_item ${i != 0 ? 'wid50' : ''}">
  512. <div class="label">${item}:</div>
  513. <div class="value">${obj.showInfo[item]}</div>
  514. </div>`;
  515. });
  516. html += '</div>';
  517. $('#bubble .tableContainer').html(html);
  518. } else if (
  519. obj.type == 4 ||
  520. obj.type == 7 ||
  521. obj.type == 5 ||
  522. obj.type == 6 ||
  523. obj.type == 9 ||
  524. obj.type == 10 ||
  525. obj.type == 11
  526. ) {
  527. $('#bubble').css({ width: '380px', height: '221px' });
  528. $('#bubble .tableContainer').css({ padding: '0 30px' });
  529. $('#bubble .tools').text(
  530. obj.type == 4
  531. ? '人员信息'
  532. : obj.type == 5
  533. ? '水表'
  534. : obj.type == 6
  535. ? '电表'
  536. : obj.type == 7
  537. ? '边坡监控'
  538. : obj.type == 9
  539. ? '皮带称重'
  540. : obj.type == 10
  541. ? '环境监测'
  542. :'无人地磅'
  543. );
  544. var html = '<div class="flex" style="height:180px;">';
  545. // html += `<img src="${
  546. // obj.imgUrl
  547. // ? obj.imgUrl
  548. // : `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/default_image/${obj.type}.png`
  549. // }" style="height:92px;width:120px;margin-right:15px;"/>`;
  550. html += '<div class="font_content">';
  551. if (obj.type == 4)
  552. for (let i = 0; i < obj.showInfo.length; i++) {
  553. html += `<div class="font_item">
  554. <div class="label">${obj.showInfo[i].title}:</div>
  555. <div class="value">${obj.showInfo[i].text}</div>
  556. </div>`;
  557. }
  558. else
  559. Object.keys(obj.showInfo).map((item, i) => {
  560. html += `<div class="font_item">
  561. <div class="label">${item}:</div>
  562. <div class="value">${obj.showInfo[item]}</div>
  563. </div>`;
  564. });
  565. html += '</div></div>';
  566. $('#bubble .tableContainer').html(html);
  567. } else if (obj.type == 12) {
  568. $('#bubble').css({ width: '486px', height: 'auto' });
  569. $('#bubble .tableContainer').css({ padding: '0 40px 20px' });
  570. $('#bubble .tools').text('排放监测');
  571. var html = `<div class="paifang">`;
  572. html += `<div class="title">${obj.title}</div>`;
  573. html += `<div class="flex" style="justify-content:space-between;flex-wrap: wrap;">`;
  574. Object.keys(obj.showInfo).map((item, i) => {
  575. html += `<div style="display:flex;align-items:center;justify-content: space-between;
  576. padding: 5px 10px;
  577. background-color: rgba(255, 255, 255, 0.1);
  578. width: 40%;
  579. font-size: 12px;
  580. font-weight: 500;
  581. color: #ffffff;
  582. margin-top: 10px;font-size:12px;font-weight: 500;
  583. color: #FFFFFF;">
  584. <div>${item}:</div>
  585. <div class="value">${obj.showInfo[item]}</div>
  586. </div>`;
  587. });
  588. html += '</div></div>';
  589. $('#bubble .tableContainer').html(html);
  590. } else if (obj.type == 13) {
  591. $('#bubble').css({ width: '250px', height: 'auto',marginLeft:'118px' });
  592. $('#bubble .tableContainer').css({ padding: '0 40px 20px' });
  593. $('#bubble .tools').text('电子围栏');
  594. var html = `<div class="paifang">`;
  595. // html += `<div class="title">${obj.title}</div>`;
  596. // html += `<div class="flex" style="justify-content:space-between;flex-wrap: wrap;">`;
  597. html += '</div></div>';
  598. $('#bubble .tableContainer').html(html);
  599. }
  600. $('#bubble').show();
  601. }
  602. // 获取弹窗背景图
  603. function getModalBg(obj) {
  604. if (obj.status == 1) {
  605. if (obj.type == 1 || obj.type == 2 || obj.type == 3)
  606. return 'https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_1/1.png';
  607. else if (obj.type == 12) return 'https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_1/2.png';
  608. else if (obj.type == 5 || obj.type == 6)
  609. return 'https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_1/3.png';
  610. else if (obj.type == 4 || obj.type == 7 || obj.type == 9 || obj.type == 10 || obj.type == 11)
  611. return 'https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_1/4.png';
  612. else{
  613. return `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_1/3.png`;
  614. }
  615. } else if (obj.status == 2 || obj.status == 3) {
  616. if (obj.type == 1 || obj.type == 2 || obj.type == 3 || obj.type == 12)
  617. return `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_${obj.status}/1.png`;
  618. else if (
  619. obj.type == 4 ||
  620. obj.type == 7 ||
  621. obj.type == 5 ||
  622. obj.type == 6 ||
  623. obj.type == 9 ||
  624. obj.type == 10 ||
  625. obj.type == 11
  626. )
  627. return `https://ore-1302260927.cos.ap-chengdu.myqcloud.com/data_screen/image/bg_${obj.status}/2.png`;
  628. }
  629. }
  630. // 移除信息提示框
  631. function remove_primitives() {
  632. scenePosition = null;
  633. $('#bubble').hide();
  634. }
  635. scene.postRender.addEventListener(function () {
  636. // 每一帧都去计算气泡的正确位置
  637. if (scenePosition) {
  638. var canvasHeight = scene.canvas.height;
  639. var windowPosition = new Cesium.Cartesian2();
  640. Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, scenePosition, windowPosition);
  641. infoboxContainer.style.bottom = canvasHeight - windowPosition.y + 30 + 'px';
  642. infoboxContainer.style.left = windowPosition.x - 243 + 'px';
  643. infoboxContainer.style.visibility = 'visible';
  644. }
  645. });
  646. // todo:拾取模型表面的位置
  647. var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  648. handler.setInputAction(function (evt) {
  649. // logLocation(evt);
  650. var pickedObject = scene.pick(evt.position); // 判断是否拾取到模型
  651. var position = scene.pickPosition(evt.position);
  652. if (!position) {
  653. position = Cesium.Cartesian3.fromDegrees(0, 0, 0);
  654. }
  655. remove_primitives(viewer);
  656. if (scene.pickPositionSupported && Cesium.defined(pickedObject)) {
  657. var cartesian = viewer.scene.pickPosition(evt.position);
  658. if (Cesium.defined(cartesian)) {
  659. var cartographic = Cesium.Cartographic.fromCartesian(cartesian); // 根据笛卡尔坐标获取到弧度
  660. var lng = Cesium.Math.toDegrees(cartographic.longitude); // 根据弧度获取到经度
  661. var lat = Cesium.Math.toDegrees(cartographic.latitude); // 根据弧度获取到纬度
  662. var height = cartographic.height; // 模型高度
  663. scenePosition = position;
  664. annotate(pickedObject);
  665. }
  666. }
  667. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  668. function logLocation(e) {
  669. //获取点击位置笛卡尔坐标
  670. var position = scene.pickPosition(e.position);
  671. //将笛卡尔坐标转化为经纬度坐标
  672. var cartographic = Cesium.Cartographic.fromCartesian(position);
  673. var longitude = Cesium.Math.toDegrees(cartographic.longitude);
  674. var latitude = Cesium.Math.toDegrees(cartographic.latitude);
  675. var height = cartographic.height;
  676. if (height < 0) {
  677. height = 0;
  678. }
  679. console.log(height);
  680. console.log(longitude);
  681. console.log(latitude);
  682. }
  683. </script>
  684. </html>