ProjectMap.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <div class="ProjectMap" id="ProjectMap" v-if="show">
  3. <ComInfoBox ref="ComInfoBox" />
  4. </div>
  5. </template>
  6. <script>
  7. import Vue from 'vue'
  8. import ComInfoBox from '@/views/groupPage/components/ComInfoBox.vue'
  9. import monitorTree from '@/views/groupPage/districtPageModules/customTools/monitorTree.vue'
  10. import trailJson from './mapJson/TF_PC_PSYS_GHPIPE_B.json'
  11. import { PolylineTrailLinkMaterialProperty } from '@/views/groupPage/util'
  12. const layer_lx = [
  13. {
  14. layerName: 'NETWORK_SJ_PSWS_Node@sxgk#1',
  15. sceneName: 'hnyy_sj_lx',
  16. key: 'geometry',
  17. value: 'lxfxfw'
  18. },
  19. {
  20. layerName: 'NETWORK_SJ_PSWS@sxgk#1',
  21. sceneName: 'hnyy_sj_lx',
  22. key: 'geometry',
  23. value: 'lxfxfw'
  24. },
  25. {
  26. layerName: 'NETWORK_SJ_PSYS_Node@sxgk#1',
  27. sceneName: 'hnyy_sj_lx',
  28. key: 'geometry',
  29. value: 'lxfxfw'
  30. },
  31. {
  32. layerName: 'NETWORK_SJ_PSYS@sxgk#1',
  33. sceneName: 'hnyy_sj_lx',
  34. key: 'geometry',
  35. value: 'lxfxfw'
  36. },
  37. {
  38. layerName: 'NETWORK_SJ_PSHS_Node@sxgk#1',
  39. sceneName: 'hnyy_sj_lx',
  40. key: 'geometry',
  41. value: 'lxfxfw'
  42. },
  43. {
  44. layerName: 'NETWORK_SJ_PSHS@sxgk#1',
  45. sceneName: 'hnyy_sj_lx',
  46. key: 'geometry',
  47. value: 'lxfxfw'
  48. }
  49. ]
  50. export default {
  51. name: 'ProjectMap', //三维底图
  52. components: {
  53. ComInfoBox
  54. },
  55. props: {
  56. show: {}
  57. },
  58. data() {
  59. return {
  60. baselayer: [],
  61. baseScene: 'scenes',
  62. baseTerrain: 'terrain',
  63. terrain: 'dixing',
  64. mapService: ['img', 'theme'],
  65. //
  66. monitorTreeInfo: null
  67. }
  68. },
  69. watch: {
  70. show: {
  71. handler(val) {
  72. if (val) {
  73. // this.$nextTick(() => {
  74. // this.initData().then((result) => {
  75. // this.addToMap()
  76. // })
  77. // })
  78. } else {
  79. this.resetData()
  80. }
  81. },
  82. immediate: true
  83. },
  84. currentProjectInfo() {
  85. if (this.monitorTreeInfo) this.monitorTreeInfo.clearDataSource()
  86. this.$store.state.bigScreen.isInitViewer = false
  87. if (this.viewer) this.viewer.destroy()
  88. if (this.$refs['ComInfoBox']) this.$refs['ComInfoBox'].handelClose()
  89. this.$nextTick(() => {
  90. this.initData().then((result) => {
  91. this.addToMap()
  92. })
  93. })
  94. }
  95. },
  96. computed: {
  97. mapConfig() {
  98. return this.$store.state.bigScreen.mapConfig
  99. },
  100. gLayerList() {
  101. return this.$store.state.bigScreen.sceneLayerList
  102. },
  103. currentProjectInfo() {
  104. return this.$store.state.bigScreen.currentProjectInfo
  105. }
  106. },
  107. methods: {
  108. initData() {
  109. return this.$store.dispatch('bigScreen/initGISResource')
  110. },
  111. //加载地图
  112. addToMap() {
  113. var viewer = new Cesium.Viewer('ProjectMap', {
  114. navigation: false,
  115. contextOptions: {
  116. webgl: {
  117. alpha: false,
  118. depth: true,
  119. stencil: true,
  120. antialias: true,
  121. premultipliedAlpha: true,
  122. preserveDrawingBuffer: true, //通过canvas.toDataURL()实现截图需要将该项设置为true
  123. failIfMajorPerformanceCaveat: false
  124. },
  125. allowTextureFilterAnisotropic: true
  126. },
  127. // skyAtmosphere: false,
  128. timeline: false,
  129. animation: false,
  130. infoBox: false,
  131. selectionIndicator: false //设置绿色框框不可见
  132. })
  133. // viewer.scene.screenSpaceCameraController.minimumZoomDistance = 70 //最小缩放比例
  134. // viewer.scene.screenSpaceCameraController.maximumZoomDistance = 50000 //最大缩放比例
  135. this.viewer = viewer
  136. window.viewer = viewer
  137. this.$store.state.bigScreen.isInitViewer = true
  138. this.$store.state.bigScreen.mapContainerId = 'ProjectMap'
  139. //去掉logo
  140. viewer._cesiumWidget._creditContainer.style.display = 'none'
  141. //地图配置
  142. this.sceneSetting(viewer)
  143. this.addRoad()
  144. this.addTrail()
  145. this.initBaseMap()
  146. //当前项目位置
  147. const initPosition = this.mapConfig.initPosition
  148. const carto = Cesium.Cartographic.fromDegrees(
  149. parseFloat(initPosition.lon),
  150. parseFloat(initPosition.lat),
  151. parseFloat(initPosition.height)
  152. )
  153. const cartes3 = Cesium.Cartographic.toCartesian(carto)
  154. const camera = cartes3
  155. let initView = {
  156. //倾斜设置
  157. // destination: new Cesium.Cartesian3(
  158. // camera.x - 2 * Math.pow(10, 3),
  159. // camera.y - 2 * Math.pow(10, 3),
  160. // camera.z - 28 * Math.pow(10, 3)
  161. // ),
  162. destination: new Cesium.Cartesian3(camera.x, camera.y, camera.z),
  163. orientation: {
  164. // heading: Cesium.Math.toRadians(360),
  165. // pitch: Cesium.Math.toRadians(-20),
  166. // roll: Cesium.Math.toRadians(360)
  167. heading: 0,
  168. pitch: Cesium.Math.toRadians(-90),
  169. roll: 0
  170. }
  171. }
  172. viewer.camera.setView(initView)
  173. // viewer.camera.setView({
  174. // //倾斜设置
  175. // //new Cesium.Cartesian3(camera.x, camera.y, camera.z)
  176. // destination: { x: -2002099.8064685483, y: 5125053.48587751, z: 3240386.7848629407 },
  177. // orientation: {
  178. // heading: 6.241173904929705,
  179. // pitch: -0.3248275425737035,
  180. // roll: 6.283185307179586
  181. // // heading: 0,
  182. // // pitch: Cesium.Math.toRadians(-90),
  183. // // roll: 0
  184. // }
  185. // })
  186. this.$store.state.bigScreen.initView = initView
  187. this.addInitScene()
  188. this.addTerrain()
  189. setTimeout(() => {
  190. this.initModulesContentShow()
  191. }, 5000)
  192. },
  193. addRoad() {
  194. let viewer = this.viewer
  195. let promise = Cesium.GeoJsonDataSource.load(trailJson, {
  196. clampToGround: true //贴地设置
  197. }) //geojson面数据
  198. promise.then(function (dataSource) {
  199. viewer.dataSources.add(dataSource)
  200. var entities = dataSource.entities.values
  201. for (var o = 0; o < entities.length; o++) {
  202. var r = entities[o]
  203. r.polyline.width = 10 //添加默认样式
  204. ;(r.polyline.material = new Cesium.PolylineGlowMaterialProperty({
  205. glowPower: 0.1, //一个数字属性,指定发光强度,占总线宽的百分比。
  206. color: Cesium.Color.DARKBLUE.withAlpha(0.5)
  207. })),
  208. 10
  209. }
  210. })
  211. },
  212. //添加尾迹线
  213. addTrail() {
  214. let viewer = this.viewer
  215. let trailLineColor = null
  216. trailLineColor = new Cesium.Color(0, 2.88, 23.9, 1.0) //初始化尾迹线颜色
  217. Cesium.Math.setRandomNumberSeed(0) //设置随机数种子
  218. let promise2 = Cesium.GeoJsonDataSource.load(trailJson, {
  219. clampToGround: true //贴地设置
  220. }) //geojson面数据
  221. promise2.then(function (dataSource) {
  222. viewer.dataSources.add(dataSource)
  223. var entities = dataSource.entities.values
  224. for (var o = 0; o < entities.length; o++) {
  225. var r = entities[o]
  226. r.polyline.width = 4 //添加默认样式
  227. r.polyline.material = new PolylineTrailLinkMaterialProperty(
  228. trailLineColor,
  229. require('@/views/groupPage/images/trail.png'),
  230. 2000
  231. )
  232. }
  233. })
  234. },
  235. //场景设置
  236. sceneSetting(viewer) {
  237. var scene = viewer.scene
  238. // //开启泛光
  239. // viewer.scene.bloomEffect.show = true
  240. // scene.bloomEffect.threshold = '1'
  241. // scene.bloomEffect.bloomIntensity = '0.3'
  242. // // 开启hdr
  243. // scene.hdrEnabled = true
  244. // //开启抗锯齿
  245. // scene.postProcessStages.fxaa.enabled = true
  246. // //显示天空
  247. // scene.skyBox.show = false
  248. // // scene.shadowMap.darkness = 1.275 //设置第二重烘焙纹理的效果(明暗程度)
  249. // scene.sun.show = true //关闭太阳
  250. // scene.fog.enabled = false //关闭雾气
  251. // //隐藏大气圈
  252. // scene.skyAtmosphere.show = false
  253. //地形深度测试
  254. scene.globe.depthTestAgainstTerrain = true
  255. // //当 Cesium 单个模型过长时,会遇到某些视角模型显示不完整的问题
  256. // // scene.logarithmicDepthBuffer = false;
  257. // //高动态范围渲染
  258. // scene.highDynamicRange = true
  259. // //关闭灯光
  260. // this.viewer.scene.globe.enableLighting = false
  261. // //globeAlpha导致月球始终可见
  262. // this.viewer.scene.moon.show = false
  263. // //地球表面双面显示
  264. // this.viewer.scene.globe.backFaceCulling = false
  265. // //开启地下模式
  266. // this.viewer.scene.undergroundMode = true
  267. // this.viewer.scene.screenSpaceCameraController.minimumZoomDistance = -1000
  268. // this.viewer.terrainProvider.isCreateSkirt = false //关闭地形裙边
  269. // //设置地球表面颜色
  270. // this.viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 1)
  271. //帧率工具
  272. this.viewer.scene.debugShowFramesPerSecond = false
  273. const nowDate = new Date(Date.now())
  274. nowDate.setHours(16) //设置系统时间为12点,时差12小时
  275. nowDate.setMinutes(0)
  276. this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(nowDate)
  277. this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
  278. },
  279. //地图服务配置
  280. baseMapConfig() {
  281. const source = this.mapConfig.gisResource
  282. const mapList = this.mapService
  283. const baseLayer = []
  284. for (let name in source) {
  285. if (mapList.indexOf(name) > -1) {
  286. const config = source[name].config
  287. for (let key in config) {
  288. const item = config[key]
  289. baseLayer.push({
  290. name: key,
  291. type: name,
  292. show: item.isDisplay === '0' ? false : true
  293. })
  294. }
  295. }
  296. }
  297. this.baselayer = baseLayer
  298. },
  299. //初始化基础底图
  300. initBaseMap() {
  301. this.baseMapConfig()
  302. let layerInfo = this.baselayer
  303. layerInfo.forEach((item) => {
  304. if (item.show) {
  305. const gisItem = this.mapConfig.gisResource[item.type].config[item.name]
  306. if (!gisItem) {
  307. return true
  308. }
  309. const url = gisItem.url
  310. if (this.mapService.indexOf(item.type) > -1) {
  311. this.viewer.imageryLayers.addImageryProvider(
  312. new Cesium.SuperMapImageryProvider({
  313. url: url,
  314. credit: item.name,
  315. transparent: true,
  316. maximumLevel: 18
  317. })
  318. )
  319. } else if ((item.type = 'mvt')) {
  320. this.viewer.scene.addVectorTilesMap({
  321. url: url,
  322. name: item.name
  323. })
  324. }
  325. }
  326. })
  327. },
  328. //加载初始化场景
  329. addInitScene() {
  330. var scenes = this.mapConfig.gisResource[this.baseScene]
  331. if (scenes && scenes.config) {
  332. Object.keys(scenes.config).forEach(
  333. function (keyName, index) {
  334. const item = scenes.config[keyName]
  335. var promise = this.viewer.scene.open(item.url, undefined, {
  336. autoSetView: false
  337. })
  338. Cesium.when(
  339. promise,
  340. function (layers) {
  341. for (var i = 0; i < layers.length; i++) {
  342. var ly = layers[i]
  343. ly.selectEnabled = true
  344. ly.clearMemoryImmediately = false
  345. ly.cullEnabled = false
  346. //ly.lodRangeScale=0.01
  347. //初始化流向显示
  348. if (layer_lx.some((item) => item.layerName == ly.name)) {
  349. ly.textureUVSpeed = new Cesium.Cartesian2(-1.0, 0)
  350. }
  351. //初始化建筑物隐藏
  352. if (ly.name === 'TF_PAPN_BUILD@sxgk_base') {
  353. ly.visible = false
  354. }
  355. ly.refresh()
  356. }
  357. // if (!this.AppX.runtimeConfig.activeView.scene.pickPositionSupported) {
  358. // console.error('不支持深度纹理,无法拾取位置!')
  359. // }
  360. }.bind(this),
  361. function (e) {
  362. console.error('加载SCP失败,请检查网络连接状态或者url地址是否正确?')
  363. }
  364. )
  365. }.bind(this)
  366. )
  367. }
  368. // setTimeout(() => {
  369. // this.defaultUpdepth()
  370. // }, 5000)
  371. },
  372. //地形加载
  373. addTerrain() {
  374. var viewer = this.viewer
  375. var configItem = this.mapConfig.gisResource[this.baseTerrain]
  376. var type = configItem.type
  377. var url = configItem.config[this.terrain].url
  378. var layerTitle = configItem.config[this.terrain].name
  379. switch (type) {
  380. case 'ext_terrain':
  381. viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
  382. url: url,
  383. requestWaterMask: true,
  384. requestVertexNormals: true,
  385. credit: layerTitle
  386. })
  387. viewer.terrainProvider.isCreateSkirt = false //关闭地表透明后出现的网格
  388. break
  389. case 'terrain':
  390. viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
  391. url: url,
  392. requestWaterMask: true,
  393. requestVertexNormals: true,
  394. credit: layerTitle,
  395. isSct: true
  396. })
  397. viewer.terrainProvider.isCreateSkirt = false //关闭地表透明后出现的网格
  398. break
  399. }
  400. },
  401. //默认抬升
  402. defaultUpdepth() {
  403. const layers = window.viewer.scene.layers
  404. //默认抬升
  405. const style3D = new Cesium.Style3D()
  406. style3D.altitudeMode = 0
  407. style3D.bottomAltitude = -10
  408. this.gLayerList.forEach((item) => {
  409. var layer = layers.find(item)
  410. if (layer) {
  411. layer.style3D = style3D
  412. layer.refresh()
  413. }
  414. })
  415. },
  416. //初始化显示模块内容
  417. initModulesContentShow() {
  418. const monitorTreeConstructor = Vue.extend(monitorTree)
  419. this.monitorTreeInfo = new monitorTreeConstructor({
  420. store: this.$store
  421. }).$mount()
  422. },
  423. resetData() {
  424. window.viewer = null
  425. this.$store.dispatch('bigScreen/resetProjectState')
  426. if (this.monitorTreeInfo) this.monitorTreeInfo.clearDataSource()
  427. }
  428. }
  429. }
  430. </script>
  431. <style lang='scss' scoped>
  432. .ProjectMap {
  433. width: 100%;
  434. height: 100%;
  435. position: relative;
  436. // background: #000;
  437. background-size: 100% 100%;
  438. }
  439. </style>