supermap-2.5d.vue 11 KB

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