supermap-2.5d.vue 18 KB

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