supermap-2.5d.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div id="cesiumContainer" style="width: 100%; height: 100%;background: none;">
  3. </div>
  4. </template>
  5. <script>
  6. import {
  7. iconList,
  8. } from '@/api/components/supermap.js'
  9. export default {
  10. name: 'sookaSuperMap',
  11. data() {
  12. return {
  13. viewer:null,
  14. scene:null,
  15. handler:null,
  16. pick:null,
  17. back_position:null,
  18. content:null,
  19. mvtMap0:null,
  20. shuixi_name:null,
  21. mvtMap1:null,
  22. mvtMap2:null,
  23. mvtMap3:null,
  24. road_name:null,
  25. layer_xiangzhenjie_name:null,
  26. /*************************原地图属性*********************/
  27. isEditableLayers: false, //绘图控件
  28. /*************************原地图属性*********************/
  29. }
  30. },
  31. watch: {
  32. },
  33. mounted() {
  34. this.onload();
  35. },
  36. props: {},
  37. methods: {
  38. onload() {
  39. let that = this;
  40. //1.添加地形数据
  41. that.viewer = new Cesium.Viewer('cesiumContainer', {
  42. //创建地形服务提供者的实例,url为SuperMap iServer发布的TIN地形服务
  43. terrainProvider: new Cesium.CesiumTerrainProvider({
  44. url: "http://121.36.228.94:8090/iserver/services/3D-sipingchangjing/rest/realspace/datas/dem%40spyx4326",
  45. //isSct : false,//地形服务源自SuperMap iServer发布时需设置isSct为true
  46. invisibility: true
  47. }),
  48. infoBox: true
  49. }, {
  50. contextOptions: {
  51. msaaLevel: 4,
  52. requestWebgl2: true
  53. },
  54. orderIndependentTranslucency: false
  55. });
  56. that.viewer.cesiumWidget.creditContainer.style.display = "none" // 去掉超图logo水印
  57. this.scene = this.viewer.scene;
  58. //2.添加SuperMap iServer发布的影像服务
  59. let layer = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  60. url: "http://121.36.228.94:8090/iserver/services/3D-sipingchangjing/rest/realspace/datas/siping_2m@spyx4326",
  61. }));
  62. //3.添加县界
  63. // let layer_xianjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  64. // url : "http://121.36.228.94:8090/iserver/services/map-SIPING/rest/maps/XianJie",
  65. // }));
  66. //4.添加乡镇界
  67. let layer_xiangzhenjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  68. url: "http://121.36.228.94:8090/iserver/services/map-SIPING/rest/maps/XiangZhenJie",
  69. }));
  70. // //5.水系
  71. // let shuixi = "http://121.36.228.94:8090/iserver/services/map-mvt-shuixiMian/restjsr/v1/vectortile/maps/shuixi_Mian";
  72. // this.mvtMap0 = this.scene.addVectorTilesMap({
  73. // url: shuixi,
  74. // canvasWidth: 512,
  75. // name: 'mvt_map0',
  76. // viewer: this.viewer,
  77. // // show: true,
  78. // // selectedColor: new Cesium.Color(6, 169, 254, 0.5)
  79. // });
  80. // //6.林地
  81. // let lindi = "http://121.36.228.94:8090/iserver/services/map-mvt-lindi/restjsr/v1/vectortile/maps/lindi";
  82. // this.mvtMap1 = this.scene.addVectorTilesMap({
  83. // url: lindi,
  84. // canvasWidth: 512,
  85. // name: 'mvt_map1',
  86. // viewer: this.viewer,
  87. // show:true,
  88. // selectedColor:new Cesium.Color(6,169,254,0.5)
  89. // });
  90. //7.农田
  91. let nongtian = "http://121.36.228.94:8090/iserver/services/map-mvt-nongtian/restjsr/v1/vectortile/maps/nongtian";
  92. this.mvtMap2 = this.scene.addVectorTilesMap({
  93. url: nongtian,
  94. canvasWidth: 512,
  95. name: 'mvt_map2',
  96. viewer: this.viewer,
  97. show:true,
  98. selectedColor:new Cesium.Color(6,169,254,0.5)
  99. });
  100. // //8.路网
  101. // let road = "http://121.36.228.94:8090/iserver/services/map-mvt-roadXian/restjsr/v1/vectortile/maps/road_Xian";
  102. // this.mvtMap3 = this.scene.addVectorTilesMap({
  103. // url: road,
  104. // canvasWidth: 512,
  105. // name: 'mvt_map3',
  106. // viewer: this.viewer,
  107. // show:true,
  108. // selectedColor:new Cesium.Color(6,169,254,0.5)
  109. // });
  110. // //9.添加路网NAME
  111. // this.road_name = this.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  112. // url : "http://121.36.228.94:8090/iserver/services/map-SIPING/rest/maps/road_Name",
  113. // show : false
  114. // }));
  115. // // 10.添加水系NAME
  116. // this.shuixi_name = this.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  117. // url: "http://121.36.228.94:8090/iserver/services/map-SIPING/rest/maps/shuixi_Name",
  118. // show: false
  119. // }));
  120. //11.添加乡镇界名称
  121. let layer_xiangzhenjie_name = 'http://121.36.228.94:8090/iserver/services/3D-XiangZhenJie_Name/rest/realspace';
  122. this.scene.open(layer_xiangzhenjie_name);
  123. // heading-代表镜头左右方向,正值为右,负值为左
  124. // pitch-代表镜头上下方向,正值为上,负值为下.
  125. // roll-代表镜头左右倾斜,正值,向右倾斜,负值向左倾斜
  126. that.viewer.camera.setView({
  127. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 350000),
  128. orientation: {
  129. // heading : Cesium.Math.toRadians(346.4202942851978),
  130. // pitch : Cesium.Math.toRadians(-16.74026687972041),
  131. // roll : Cesium.Math.toRadians(0)
  132. }
  133. });
  134. },
  135. //移除之前添加的点
  136. clearM(){
  137. this.viewer.entities.removeAll();
  138. },
  139. /**
  140. * 地图落点
  141. */
  142. setMarkers(makerList){
  143. let that = this;
  144. that.handler = new Cesium.ScreenSpaceEventHandler(this.scene.canvas);
  145. clearInterval(that.aac);
  146. for (let i in makerList) {
  147. let longitude = makerList[i].lng;
  148. let latitude = makerList[i].lat;
  149. that.viewer.entities.add({
  150. name:"",
  151. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  152. billboard: {
  153. image: iconList[makerList[i].icon],
  154. width: 48,
  155. height: 48,
  156. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  157. disableDepthTestDistance:Number.POSITIVE_INFINITY
  158. },
  159. description: makerList[i].bindPopupHtml,
  160. click: makerList[i].click,
  161. parameter: makerList[i].parameter,
  162. });
  163. }
  164. that.viewer.scene.globe.depthTestAgainstTerrain=false;
  165. that.createLeftClickDescription();
  166. that.createRightClickDescription();
  167. },
  168. /**
  169. *鼠标左击事件是原来的气泡
  170. */
  171. createLeftClickDescription() {
  172. let that = this;
  173. that.handler.setInputAction(function (movement) {
  174. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  175. },
  176. /**
  177. * 地图落点(传感器)
  178. */
  179. setMarkers_cgq(makerList){
  180. let that = this;
  181. that.handler = new Cesium.ScreenSpaceEventHandler(this.scene.canvas);
  182. for (let i in makerList) {
  183. let longitude = makerList[i].lng;
  184. let latitude = makerList[i].lat;
  185. that.viewer.entities.add({
  186. name:"",
  187. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  188. billboard: {
  189. image: iconList[makerList[i].icon],
  190. width: 48,
  191. height: 48,
  192. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  193. disableDepthTestDistance:Number.POSITIVE_INFINITY
  194. },
  195. description: makerList[i].bindPopupHtml,
  196. click: makerList[i].click,
  197. parameter: makerList[i].parameter,
  198. });
  199. }
  200. that.viewer.scene.globe.depthTestAgainstTerrain=false;
  201. that.createLeftClickDescription_cgq();
  202. },
  203. /**
  204. *鼠标左击事件是原来的气泡(传感器)
  205. */
  206. createLeftClickDescription_cgq() {
  207. let that = this;
  208. clearInterval(that.aac);
  209. that.handler.setInputAction(function (movement) {
  210. that.aac = setInterval(function (){
  211. let color = "green";
  212. let value = Math.random();
  213. let up = "▲";
  214. let down = "▼";
  215. if(value>0.5){
  216. color = "red";
  217. value = value +""+ up;
  218. }else{
  219. value = value +""+ down;
  220. }
  221. let html = "<span style='color:"+color+"'>当前传感器数值:"+value+"</span>";
  222. window.parent.frames[0].document.querySelector(".cesium-infoBox-description").innerHTML = html;
  223. },1000);
  224. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  225. },
  226. /**
  227. *鼠标右击事件是原来的点击
  228. */
  229. createRightClickDescription() {
  230. let that = this;
  231. that.handler.setInputAction(function (movement) {
  232. // 监听鼠标的当前位置坐标,然后根据当前坐标去动态更新气泡窗口div的显示位置;
  233. that.pick = that.viewer.scene.pick(movement.position);
  234. if (that.pick && that.pick) {
  235. let id = Cesium.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(movement.position).primitive.id);
  236. let clickName = id._click;
  237. that.$emit(clickName, id._parameter)
  238. }
  239. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  240. },
  241. /**
  242. * 落点定位
  243. */
  244. dropLocation(lat, lng) {
  245. this.viewer.camera.flyTo({
  246. destination: Cesium.Cartesian3.fromDegrees(lng, lat, 3000),
  247. });
  248. },
  249. }
  250. }
  251. </script>
  252. <style lang="scss" scoped>
  253. @import '@/assets/styles/base.scss';
  254. </style>