supermap-2.5d.vue 15 KB

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