supermap-2.5d.vue 12 KB

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