supermap-2.5d.vue 17 KB

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