supermap-2.5d.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div id="cesiumContainer" style="width: 100%; height: 100%;background: none;">
  3. <!--地图top 显示 开始-->
  4. <transition name='fade'>
  5. <div class="map-tit" v-show="mapshow">
  6. <div class="top-tit">
  7. <i class="iconfont sj-icon-jkzx"></i>
  8. <span><img src="../assets/images/close.svg" @click="mapShow" /></span>
  9. </div>
  10. <div class="map-txt" v-html="bindPopupHtml">
  11. </div>
  12. </div>
  13. </transition>
  14. <!--地图top 显示 结束-->
  15. </div>
  16. </template>
  17. <script>
  18. import {
  19. iconList,
  20. getDeviceList
  21. } from '@/api/components/supermap.js'
  22. import Cookies from 'js-cookie'
  23. import {
  24. getConfigKey
  25. } from "@/api/system/config";
  26. export default {
  27. name: 'supermap-2.5d',
  28. data() {
  29. return {
  30. bindPopupHtml: null,
  31. mapshow: false,
  32. superMapRootUrl: null,
  33. viewer: null,
  34. scene: null,
  35. handler: null,
  36. pick: null,
  37. back_position: null,
  38. content: null,
  39. mvtMap0: null,
  40. shuixi_name: null,
  41. mvtMap1: null,
  42. mvtMap2: null,
  43. mvtMap3: null,
  44. road_name: null,
  45. layer_xiangzhenjie_name: null,
  46. markerboxEntity: [], //地图落点实体
  47. connectBoxEntity: null, //地图线实体
  48. graphicsBoxEntity: null, //地图面实体
  49. markerboxEntityRadius: [], //地图落点实体
  50. connectBoxEntityTwo: null, //地图线实体
  51. timer: null,
  52. /*************************原地图属性*********************/
  53. isEditableLayers: false, //绘图控件
  54. /*************************原地图属性*********************/
  55. aac: null,
  56. queryParams: {
  57. name: null,
  58. mapData: null,
  59. mapName: null
  60. },
  61. }
  62. },
  63. watch: {},
  64. created() {
  65. this.superMapInfo();
  66. },
  67. mounted() {},
  68. props: {},
  69. methods: {
  70. mapShow() {
  71. this.mapshow = false,
  72. clearInterval(this.timer)
  73. },
  74. //清除所有
  75. clearAll() {
  76. this.viewer.entities.removeAll()
  77. },
  78. //移除之前添加的点
  79. clearMRadius() {
  80. if (this.markerboxEntityRadius != null && this.markerboxEntityRadius.length > 0) {
  81. for (let i = 0; i < this.markerboxEntityRadius.length; i++) {
  82. this.viewer.entities.remove(this.markerboxEntityRadius[i])
  83. }
  84. this.markerboxEntityRadius = []
  85. }
  86. },
  87. //移除之前添加的线
  88. clearTwoC() {
  89. if (this.connectBoxEntityTwo != null) {
  90. this.viewer.entities.remove(this.connectBoxEntityTwo)
  91. this.connectBoxEntityTwo = []
  92. }
  93. },
  94. /**
  95. * 地图落点-覆盖范围
  96. */
  97. setMarkersRadius(makerList) {
  98. let that = this
  99. that.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
  100. for (let i in makerList) {
  101. let longitude = makerList[i].lng;
  102. let latitude = makerList[i].lat;
  103. let marker = that.viewer.entities.add({
  104. name: "",
  105. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  106. billboard: {
  107. image: iconList[makerList[i].icon],
  108. width: 48,
  109. height: 48,
  110. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  111. disableDepthTestDistance: Number.POSITIVE_INFINITY
  112. },
  113. description: makerList[i].bindPopupHtml,
  114. click: makerList[i].click,
  115. parameter: makerList[i].parameter
  116. })
  117. that.markerboxEntityRadius.push(marker)
  118. //绘制摄像头的圈(覆盖范围)
  119. let markerRadius = that.viewer.entities.add({
  120. position: Cesium.Cartesian3.fromDegrees(makerList[i].lng, makerList[i].lat, 2),
  121. ellipse: {
  122. semiMinorAxis: makerList[i].radius,
  123. semiMajorAxis: makerList[i].radius,
  124. height: 0.0,
  125. material: Cesium.Color.DODGERBLUE.withAlpha(0.4),
  126. outline: true,
  127. outlineColor: Cesium.Color.DEEPSKYBLUE.withAlpha(1),
  128. outlineWidth: 1,
  129. },
  130. });
  131. that.markerboxEntityRadius.push(markerRadius)
  132. }
  133. that.viewer.scene.globe.depthTestAgainstTerrain = false
  134. that.createLeftClickDescription()
  135. that.createRightClickDescription()
  136. },
  137. /**
  138. * 地图画线(贴地)
  139. */
  140. setConnectTwoList(connectList, color, withAlpha) {
  141. let that = this
  142. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  143. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  144. that.connectBoxEntityTwo = that.viewer.entities.add({
  145. Type: 'Polyline',
  146. polyline: {
  147. positions: Cesium.Cartesian3.fromDegreesArray(connectList),
  148. clampToGround: true, //贴地 true,不贴地 false
  149. width: 5,
  150. material: material
  151. }
  152. })
  153. },
  154. //移除之前添加的点
  155. clearM() {
  156. if (this.markerboxEntity != null && this.markerboxEntity.length > 0) {
  157. for (let i = 0; i < this.markerboxEntity.length; i++) {
  158. this.viewer.entities.remove(this.markerboxEntity[i])
  159. }
  160. this.markerboxEntity = []
  161. }
  162. },
  163. //移除之前添加的线
  164. clearC() {
  165. if (this.connectBoxEntity != null) {
  166. this.viewer.entities.remove(this.connectBoxEntity)
  167. this.connectBoxEntity = []
  168. }
  169. },
  170. //移除之前添加的面
  171. clearG() {
  172. if (this.graphicsBoxEntity != null) {
  173. this.viewer.entities.remove(this.graphicsBoxEntity)
  174. this.graphicsBoxEntity = []
  175. }
  176. },
  177. superMapInfo() {
  178. getConfigKey('superMap.iServer').then(response => {
  179. this.superMapRootUrl = response.msg;
  180. this.onload();
  181. })
  182. },
  183. onload() {
  184. let that = this;
  185. //1.添加地形数据
  186. that.viewer = new Cesium.Viewer('cesiumContainer', {
  187. //创建地形服务提供者的实例,url为SuperMap iServer发布的TIN地形服务
  188. terrainProvider: new Cesium.CesiumTerrainProvider({
  189. url: that.superMapRootUrl + "/3D-sipingchangjing/rest/realspace/datas/dem@spyx4326",
  190. //isSct : false,//地形服务源自SuperMap iServer发布时需设置isSct为true
  191. invisibility: true
  192. }),
  193. infoBox: false,
  194. navigation: false
  195. }, {
  196. contextOptions: {
  197. msaaLevel: 4,
  198. requestWebgl2: true
  199. },
  200. orderIndependentTranslucency: false
  201. });
  202. that.scene = that.viewer.scene;
  203. that.viewer.cesiumWidget.creditContainer.style.display = "none" // 去掉超图logo水印
  204. //2.添加SuperMap iServer发布的影像服务
  205. let layer = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  206. url: that.superMapRootUrl + "/3D-sipingchangjing/rest/realspace/datas/siping_2m@spyx4326",
  207. }));
  208. //飞行值坐标点,每3秒推进一级
  209. //heading-代表镜头左右方向,正值为右,负值为左
  210. //pitch-代表镜头上下方向,正值为上,负值为下.
  211. //roll-代表镜头左右倾斜,正值,向右倾斜,负值向左倾斜
  212. setTimeout(function() {
  213. that.viewer.camera.flyTo({
  214. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 950000),
  215. orientation: {
  216. // heading : Cesium.Math.toRadians(346.4202942851978),
  217. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  218. // roll : Cesium.Math.toRadians(0)
  219. }
  220. });
  221. }, 3000);
  222. setTimeout(function() {
  223. that.viewer.camera.flyTo({
  224. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 650000),
  225. orientation: {
  226. // heading : Cesium.Math.toRadians(346.4202942851978),
  227. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  228. // roll : Cesium.Math.toRadians(0)
  229. }
  230. });
  231. }, 3000);
  232. setTimeout(function() {
  233. that.viewer.camera.flyTo({
  234. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 350000),
  235. orientation: {
  236. // heading : Cesium.Math.toRadians(346.4202942851978),
  237. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  238. // roll : Cesium.Math.toRadians(0)
  239. }
  240. });
  241. }, 3000);
  242. //开始加载专题图等数据,8秒后开始执行
  243. setTimeout(function() {
  244. // // 3.水系
  245. // let shuixi = that.superMapRootUrl+"/map-mvt-shuixiMian/restjsr/v1/vectortile/maps/shuixi_Mian";
  246. // that.mvtMap0 = that.scene.addVectorTilesMap({
  247. // url: shuixi,
  248. // canvasWidth: 512,
  249. // name: 'mvt_map0',
  250. // viewer: that.viewer,
  251. // selectedColor:new Cesium.Color(6,169,254,0.5),
  252. // show:true,
  253. // });
  254. // //4.林地
  255. // let lindi = that.superMapRootUrl+"/map-mvt-lindi/restjsr/v1/vectortile/maps/lindi";
  256. // that.mvtMap1 = that.scene.addVectorTilesMap({
  257. // url: lindi,
  258. // canvasWidth: 512,
  259. // name: 'mvt_map1',
  260. // viewer: that.viewer,
  261. // selectedColor:new Cesium.Color(6,254,181,0.5),
  262. // show:true,
  263. // });
  264. //
  265. // //5.农田
  266. // let nongtian = that.superMapRootUrl+"/map-mvt-nongtian/restjsr/v1/vectortile/maps/nongtian";
  267. // that.mvtMap2 = that.scene.addVectorTilesMap({
  268. // url: nongtian,
  269. // canvasWidth: 512,
  270. // name: 'mvt_map2',
  271. // viewer: that.viewer,
  272. // selectedColor:new Cesium.Color(250, 236, 246,1.0),
  273. // show:true,
  274. // });
  275. //
  276. // //6.路网
  277. // let road = that.superMapRootUrl+"/map-mvt-roadXian/restjsr/v1/vectortile/maps/road_Xian";
  278. // that.mvtMap3 = that.scene.addVectorTilesMap({
  279. // url: road,
  280. // canvasWidth: 512,
  281. // name: 'mvt_map3',
  282. // viewer: that.viewer,
  283. // show:true,
  284. // });
  285. //
  286. // //7.添加路网NAME
  287. // let road_name_url = that.superMapRootUrl+'/3D-road_Name_S/rest/realspace';
  288. // that.road_name = that.scene.open(road_name_url);
  289. //
  290. // // 8.添加水系NAME
  291. // let shuixi_name_url = that.superMapRootUrl+'/3D-shuixi_Name/rest/realspace';
  292. // that.shuixi_name = that.scene.open(shuixi_name_url);
  293. //9.添加县界和乡镇界
  294. let layer_xianjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  295. url: that.superMapRootUrl + "/map-SIPING/rest/maps/XianJie_XiangZhenJie",
  296. }));
  297. //10.添加区县乡镇村名称
  298. let layer_xiangzhenjie_name = that.superMapRootUrl + '/3D-Name_he/rest/realspace';
  299. that.scene.open(layer_xiangzhenjie_name);
  300. that.road_name.then(function(layers) {
  301. let xianJie_textLayer = that.scene.layers.find('XianJie@SiPing#1'); //区县文字图层
  302. let xiangZhenJie_textLayer = that.scene.layers.find('XiangZhenJie@SiPing#2'); //乡镇文字图层
  303. let cun_textLayer = that.scene.layers.find('Cun@SiPing#1'); //村文字图层
  304. //关闭避让
  305. xianJie_textLayer.isOverlapDisplayed = true;
  306. xiangZhenJie_textLayer.isOverlapDisplayed = true;
  307. cun_textLayer.isOverlapDisplayed = true;
  308. });
  309. }, 3000);
  310. },
  311. /**
  312. * 地图落点
  313. */
  314. setMarkers(makerList) {
  315. let that = this
  316. that.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
  317. for (let i in makerList) {
  318. let longitude = makerList[i].lng
  319. let latitude = makerList[i].lat
  320. let marker = that.viewer.entities.add({
  321. name: '',
  322. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  323. billboard: {
  324. image: iconList[makerList[i].icon],
  325. width: 48,
  326. height: 48,
  327. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  328. disableDepthTestDistance: Number.POSITIVE_INFINITY
  329. },
  330. description: makerList[i].bindPopupHtml,
  331. click: makerList[i].click,
  332. parameter: makerList[i].parameter
  333. })
  334. that.markerboxEntity.push(marker)
  335. }
  336. that.viewer.scene.globe.depthTestAgainstTerrain = false
  337. that.createLeftClickDescription()
  338. that.createRightClickDescription()
  339. },
  340. /**
  341. *鼠标左击事件是原来的气泡
  342. */
  343. createLeftClickDescription() {
  344. let that = this;
  345. that.handler.setInputAction(function(movement) {
  346. that.pick = that.viewer.scene.pick(movement.position);
  347. if (that.pick && that.pick) {
  348. let id = Cesium.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(
  349. movement.position).primitive.id);
  350. let html = id._description;
  351. clearInterval(that.timer)
  352. if (html != undefined && html._value != null && html._value != '' && html != 'cgq') {
  353. that.bindPopupHtml = html
  354. that.mapshow = true
  355. } else if (html == 'cgq') {
  356. that.timer = setInterval(function() {
  357. var color = "green";
  358. var value = Math.random();
  359. var up = "▲";
  360. var down = "▼";
  361. if (value > 0.5) {
  362. color = "red";
  363. value = value + "" + up;
  364. } else {
  365. value = value + "" + down;
  366. }
  367. that.bindPopupHtml = "<span style='color:" + color + "'>当前传感器数值: " + value + "</span>";
  368. }, 1000)
  369. that.mapshow = true
  370. } else {
  371. that.mapshow = false
  372. clearInterval(that.timer)
  373. }
  374. } else {
  375. that.mapshow = false
  376. clearInterval(that.timer)
  377. }
  378. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  379. },
  380. /**
  381. *鼠标右击事件是原来的点击
  382. */
  383. createRightClickDescription() {
  384. let that = this;
  385. that.handler.setInputAction(function(movement) {
  386. that.mapshow = false
  387. clearInterval(that.timer)
  388. // 监听鼠标的当前位置坐标,然后根据当前坐标去动态更新气泡窗口div的显示位置;
  389. that.pick = that.viewer.scene.pick(movement.position);
  390. if (that.pick && that.pick) {
  391. let id = Cesium.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(
  392. movement.position).primitive.id);
  393. let clickName = id._click;
  394. that.$emit(clickName, id._parameter)
  395. }
  396. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  397. },
  398. /**
  399. * 落点定位
  400. */
  401. dropLocation(lat, lng) {
  402. this.viewer.camera.flyTo({
  403. destination: Cesium.Cartesian3.fromDegrees(lng, lat, 3000),
  404. });
  405. },
  406. /**
  407. * 地图画线(贴地)
  408. */
  409. setConnectList(connectList, color, withAlpha) {
  410. let that = this
  411. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  412. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  413. that.connectBoxEntity = that.viewer.entities.add({
  414. Type: 'Polyline',
  415. polyline: {
  416. positions: Cesium.Cartesian3.fromDegreesArray(connectList),
  417. clampToGround: true, //贴地 true,不贴地 false
  418. width: 5,
  419. material: material
  420. }
  421. })
  422. },
  423. /**
  424. * 地图图形(贴地)
  425. */
  426. setGraphicsList(graphicsList, color, withAlpha) {
  427. let that = this
  428. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  429. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  430. that.graphicsBoxEntity = that.viewer.entities.add({
  431. polygon: {
  432. hierarchy: Cesium.Cartesian3.fromDegreesArray(graphicsList),
  433. clampToGround: true, //贴地 true,不贴地 false
  434. width: 5,
  435. material: material
  436. }
  437. })
  438. }
  439. },
  440. }
  441. </script>
  442. <style rel="stylesheet/scss" lang="scss" scoped>
  443. .map-tit {
  444. position: absolute;
  445. top: 90px;
  446. left: 50%;
  447. transform: translatex(-50%);
  448. border: 1px solid #15519b;
  449. z-index: 9999;
  450. background: linear-gradient(rgba(4, 23, 62, 0.6), rgba(0, 28, 70, 0.6));
  451. min-width: 300px;
  452. .top-tit {
  453. width: 100%;
  454. height: 28px;
  455. line-height: 28px;
  456. display: flex;
  457. flex-direction: row;
  458. justify-content: space-between;
  459. background: #15519b80;
  460. padding: 0px 10px;
  461. align-items: center;
  462. i {
  463. color: #10ccff;
  464. font-size: 18px;
  465. text-shadow: 0px 0px 5px #23b3b3;
  466. ;
  467. }
  468. span img {
  469. display: block;
  470. width: 12px;
  471. height: 12px;
  472. color: #fff;
  473. cursor: pointer;
  474. }
  475. }
  476. .map-txt {
  477. padding: 10px 15px;
  478. color: #fff;
  479. line-height: 20px;
  480. font-size: 12px;
  481. .d-l-con {}
  482. }
  483. }
  484. .fade-enter-active,
  485. .fade-leave-active {
  486. transition: 1s;
  487. }
  488. .fade-enter,
  489. .fade-leave-to {
  490. opacity: 0;
  491. transform: translateY(-10rem);
  492. }
  493. </style>