viewer.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <div>
  3. <i class="cesiumbtn" :class="store.state.viewer_flag ? 'el-icon-aim' : 'el-icon-rank'" :title="isbig ? '缩小' : '放大'"
  4. @click="bigViewerChange"></i>
  5. <div v-show="store.state.viewer_flag" class="viewer">
  6. <div class="bg">
  7. <div class="bg_left"></div>
  8. <div class="bg_right"></div>
  9. <div class="bg_bottom"></div>
  10. </div>
  11. <datePicker @dateChange="dateChange"></datePicker>
  12. <!-- <ser-center></ser-center> -->
  13. <KJZB ref="gkzb_ref" />
  14. <JCBD />
  15. <TDSC ref="tdsc_ref" />
  16. <TDSY ref="tdgy_ref" />
  17. <GDBH ref="gdbh_ref" />
  18. <STXF ref="stxf_ref" />
  19. <WPJG ref="wpjg_ref" />
  20. <div class="bottom_model">
  21. <div class="bjxm_box">
  22. <BJXM ref="bjxm_ref" />
  23. </div>
  24. <div class="hysy_box">
  25. <HYSY ref="hysy_ref" />
  26. </div>
  27. </div>
  28. </div>
  29. <Boxcommon v-show="!store.state.viewer_flag"></Boxcommon>
  30. <InfoVector v-show="!store.state.viewer_flag"></InfoVector>
  31. </div>
  32. </template>
  33. <script>
  34. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  35. import KJZB from './cockpit/kjgh';
  36. import TDSC from './cockpit/tdsc';
  37. import HYSY from './cockpit/hysy';
  38. import TDSY from './cockpit/tdsy';
  39. import BJXM from './cockpit/bjxm';
  40. import GDBH from './cockpit/gdbh';
  41. import STXF from './cockpit/stxf';
  42. import WPJG from './cockpit/wpjg';
  43. import JCBD from './cockpit/jcbd';
  44. import Boxcommon from '@/views/cockpit/common/VectorSpace/BoxCommonVector.vue';
  45. import InfoVector from '@/views/cockpit/common/VectorSpace/InfoVector.vue';
  46. import datePicker from './cockpit/datePicker.vue';
  47. import xzqh from "../../static/data/460200_full.json";
  48. import hyqy from "../../static/data/460200_hyqy.json";
  49. import { cockpitInfo } from '@/api/cockpit'
  50. import * as cockpit from "@/common/js/cockpit.js";
  51. export default {
  52. name: 'viewer',
  53. components: { KJZB, BJXM, TDSC, HYSY, TDSY, GDBH, STXF, WPJG, datePicker, JCBD, Boxcommon, InfoVector },
  54. data() {
  55. return {
  56. params: {
  57. beginTime: '',
  58. endTime: '',
  59. id: 4602,
  60. name: ""
  61. },
  62. flag: true,
  63. xzqh_color_click: "rgba(46, 177, 251, 0.6)",
  64. xzqh_color: "rgba(10, 95, 152, 0.5)",
  65. primitivesL: [],
  66. };
  67. },
  68. //监听属性 类似于data概念
  69. computed: {
  70. isViewer_flag() {
  71. return store.state.viewer_flag;  //需要监听的数据
  72. },
  73. isxzqh_flag() {
  74. return store.state.xzqh_flag;  //需要监听的数据
  75. },
  76. },
  77. //监控data中的数据变化
  78. watch: {
  79. isViewer_flag(newVal, oldVal) {
  80. cockpit.hidden_xzqh(newVal);
  81. cockpit.hidden_wall(newVal);
  82. if (newVal) {
  83. viewer.camera.flyTo({ //定位到范围中心点
  84. destination: {
  85. x: -2040463.7901390342,
  86. y: 5793227.819015942,
  87. z: 1894583.1762108966
  88. },
  89. orientation: {
  90. heading: 0.000005686606919574899,
  91. pitch: -0.41034310444770905,
  92. roll: 0.0
  93. },
  94. })
  95. }
  96. },
  97. isxzqh_flag(newVal, oldVal) {
  98. cockpit.hidden_xzqh(newVal);
  99. cockpit.hidden_wall(newVal);
  100. }
  101. },
  102. //方法集合
  103. methods: {
  104. bigViewerChange() {
  105. store.setViewerFlagb(!store.state.viewer_flag);
  106. store.setToolBarShow(!store.state.viewer_flag);
  107. // store.setToolBarShow(true);
  108. // // 隐藏行政区划
  109. // cockpit.hidden_xzqh(store.state.viewer_flag);
  110. // // 隐藏墙体
  111. // cockpit.hidden_wall(store.state.viewer_flag);
  112. },
  113. switch() {
  114. this.flag = !this.flag;
  115. },
  116. setDatas() {
  117. // 耕地保护
  118. this.$refs.gdbh_ref.init_zbph(this.params);
  119. this.$refs.gdbh_ref.init_info(this.params);
  120. this.$refs.gdbh_ref.init_zbph_hz(this.params);
  121. this.$refs.gdbh_ref.init_jcpg_hz(this.params);
  122. this.$refs.gdbh_ref.init_jcph_table(this.params);
  123. // this.$refs.stxf_ref.setData({ id: this.params.id });
  124. // this.$refs.wpjg_ref.setData(this.params);
  125. // 卫片监管
  126. this.$refs.wpjg_ref.init_wpjg_title(this.params);
  127. this.$refs.tdsc_ref.init_scjd(this.params);
  128. // 土地供应
  129. this.$refs.tdgy_ref.init_tdgy_gy_jd(this.params);
  130. this.$refs.tdgy_ref.init_tdgy_gy_jg(this.params);
  131. this.$refs.tdgy_ref.init_tdgy_jt_jg(this.params);
  132. this.$refs.tdgy_ref.getInfo(this.params);
  133. this.$refs.tdgy_ref.init_tdgy_jt_jd(this.params);
  134. this.$refs.tdgy_ref.init_echart_data(this.params);
  135. this.$refs.tdgy_ref.init_info(this.params);
  136. // 海域使用
  137. // this.$refs.hysy_ref.init_info(this.params);
  138. // this.$refs.hysy_ref.init_echart_data(this.params);
  139. // 报建项目
  140. this.$refs.bjxm_ref.init_info(this.params);
  141. this.$refs.bjxm_ref.init_bjxm_echart_info(this.params);
  142. // 生态修复
  143. this.$refs.stxf_ref.getInfo(this.params);
  144. this.$refs.stxf_ref.tdzz(this.params);
  145. // 卫片监管
  146. this.$refs.wpjg_ref.switch_xzqh(this.params);
  147. },
  148. dateChange(date) {
  149. this.params.beginTime = date[0]
  150. this.params.endTime = date[1]
  151. store.setCockpitDate(date);
  152. this.setDatas()
  153. },
  154. async gkzb_xzqh(address) {
  155. let obj = {
  156. // beginTime: store.state.cockpit_date[0],
  157. // endTime: store.state.cockpit_date[1],
  158. jscType: 'jsc_gkzb_ztgu_stbh',
  159. id: address
  160. };
  161. let data = await cockpitInfo(obj);
  162. let obj_yjjbntmj = {
  163. jscType: 'jsc_gdbh_ztgh_nt',
  164. id: address
  165. };
  166. let obj_yjjbntmj_data = await cockpitInfo(obj_yjjbntmj);
  167. let obj_kfbjmj = {
  168. jscType: 'jsc_gkzb_ztgh_kfbj',
  169. id: address
  170. };
  171. let obj_kfbjmj_data = await cockpitInfo(obj_kfbjmj);
  172. let obj_gdbhmb = {
  173. jscType: 'jsc_gkzb_ztgu_gdbhmb',
  174. id: address
  175. };
  176. let obj_gdbhmb_data = await cockpitInfo(obj_gdbhmb);
  177. store.setCockpitGkzb({
  178. mj: data.data[0].mj,// 生态保护红线面积
  179. ly_mj: data.data[0].ly_mj,// 路域生态保护红线
  180. hy_mj: data.data[0].hy_mj,//近海岸面积
  181. yjjbntmj: obj_yjjbntmj_data.data[0].yjjbntmj,// 永久基本农田保护面积
  182. kfbjmj: obj_kfbjmj_data.data[0].kfbjmj,// 城市开发边界
  183. bfb: (obj_kfbjmj_data.data[0].bfb * 100).toFixed(2),// 覆盖城镇开发边界
  184. tbmj_ys: obj_gdbhmb_data.data[0].tbmj_ys,//耕地保护目标
  185. ghdkmj: obj_kfbjmj_data.data[0].ghdkmj//已入库管控范围
  186. });
  187. },
  188. async gkzb() {
  189. const that = this;
  190. that.$refs.gkzb_ref["initData"]();
  191. },
  192. async pick_xzqh() {
  193. const that = this;
  194. const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  195. handler.setInputAction(async event => {
  196. let pickObj = viewer.scene.pick(event.position);
  197. var position = viewer.scene.pickPosition(event.position);
  198. if (!position)//点击到地球之外
  199. return false;
  200. var cartographic = Cesium.Cartographic.fromCartesian(position);
  201. let longitude = Cesium.Math.toDegrees(cartographic.longitude);
  202. let latitude = Cesium.Math.toDegrees(cartographic.latitude);
  203. let height = cartographic.height;
  204. let heading = viewer.scene.camera.heading;
  205. let pitch = viewer.scene.camera.pitch;
  206. if (!position) {
  207. position = Cesium.Cartesian3.fromDegrees(0, 0, 0);
  208. return;
  209. }
  210. if (store.state.viewer_flag) {
  211. if (Cesium.defined(pickObj)) {
  212. if (pickObj.primitive instanceof Cesium.Primitive) {//点击primitive
  213. //primitive相关操作
  214. let obj = JSON.parse(pickObj.id);
  215. let pri_name = obj.name;
  216. let adcode = obj.adcode
  217. that.params.id = adcode
  218. that.params.name = pri_name
  219. store.setCockpitRegion(obj)
  220. that.setDatas()
  221. // 管控指标
  222. that.gkzb_xzqh(adcode);
  223. cockpit.pick_xzqh(pri_name);
  224. }
  225. } else {
  226. // 暂时点击周围数据显示三亚市
  227. // 清除所有xzqh状态
  228. cockpit.pick_xzqh();
  229. // 管控指标
  230. that.gkzb();
  231. that.params.id = '4602'
  232. that.setDatas()
  233. store.setCockpitRegion({ id: '4602',name:'三亚' })
  234. }
  235. }
  236. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  237. },
  238. colorFun(color) {
  239. // * `czm_material czm_getMaterial(czm_materialInput materialInput) {...}`: 这是一个名为 `czm_getMaterial` 的函数,它接受一个 `czm_materialInput` 类型的参数并返回一个 `czm_material` 类型的对象。这是 Cesium 中的一个约定,允许你通过编写自定义的 GLSL 代码来定义材质。
  240. // * `czm_material material = czm_getDefaultMaterial(materialInput);`: 获取默认的材质设置。
  241. // * `vec2 st = materialInput.st;`: 从输入中获取纹理坐标(texture coordinates)。
  242. // * `float dis = distance(st, vec2(0.5));`: 计算纹理坐标与中心 `(0.5, 0.5)` 的距离。
  243. // * `material.diffuse = color.rgb;`: 设置材质的漫反射颜色为你提供的 `color` 的 RGB 部分。
  244. // * `material.alpha = clamp(dis * 2.0, 0.1, 0.7);`: 根据与中心的距离设置材质的透明度(alpha)。使用 `clamp` 函数确保透明度值在 0.1 和 0.7 之间。
  245. const fs = `czm_material czm_getMaterial(czm_materialInput materialInput)
  246. {
  247. czm_material material = czm_getDefaultMaterial(materialInput);
  248. vec2 st = materialInput.st;
  249. float dis = distance(st,vec2(0.5));
  250. material.diffuse = color.rgb;
  251. material.alpha = clamp( dis * 2.0, 0.1, 0.3);
  252. return material;
  253. }
  254. `
  255. const material = new Cesium.Material({
  256. fabric: {
  257. uniforms: {
  258. color: color
  259. },
  260. source: fs,
  261. }
  262. })
  263. const aper = new Cesium.MaterialAppearance({
  264. material,
  265. source: fs,
  266. })
  267. return aper;
  268. },
  269. init_xzqh() {
  270. const that = this;
  271. xzqh.features.forEach((res) => {
  272. let obj = {
  273. 'type': "cockpit",
  274. 'name': res.properties.name,
  275. 'centroid': res.properties.centroid,
  276. 'adcode': res.properties.adcode,
  277. }
  278. res.geometry.coordinates.forEach((item) => {
  279. const twoDArray = item[0];
  280. const oneDArray = twoDArray.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
  281. that.primitivesL.push(JSON.stringify(obj));
  282. // 行政区划
  283. let polygon = new Cesium.GeometryInstance({
  284. id: JSON.stringify(obj),
  285. geometry: new Cesium.PolygonGeometry({
  286. minimum: new Cesium.Cartesian3(0, 0, 0),
  287. maximum: new Cesium.Cartesian3(100000, 100000, 100000),
  288. polygonHierarchy: new Cesium.PolygonHierarchy(
  289. Cesium.Cartesian3.fromDegreesArray(oneDArray)
  290. ),
  291. height: 100,
  292. extrudedHeight: res.properties.extrudedHeight,
  293. })
  294. })
  295. let addPolygonGeometry = new Cesium.Primitive({
  296. geometryInstances: polygon,
  297. appearance: that.colorFun(Cesium.Color.fromCssColorString('#139FF0')),
  298. show: true,
  299. })
  300. // manager.add(addPolygonGeometry)
  301. cockpit.addPrimitive(addPolygonGeometry);
  302. viewer.scene.primitives.add(addPolygonGeometry)
  303. // 墙体流动效果
  304. var positions = Cesium.Cartesian3.fromDegreesArray(oneDArray);
  305. cockpit.add_wall(obj, positions, res);
  306. })
  307. })
  308. },
  309. init_hyqy() {
  310. const that = this;
  311. hyqy.features.forEach((res) => {
  312. let obj = {
  313. 'type': "cockpit",
  314. 'name': res.properties.name,
  315. 'centroid': res.properties.centroid,
  316. 'adcode': res.properties.adcode,
  317. }
  318. const twoDArray = res.geometry.coordinates[0];
  319. const oneDArray = twoDArray.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
  320. cockpit.add_hy(obj, res, oneDArray, that.xzqh_color);
  321. })
  322. },
  323. addSceneFun() {
  324. var pitch = viewer.camera.pitch;
  325. //获取当前视角的heading
  326. var heading = viewer.camera.heading;
  327. //获取当前视角的postion(位置)
  328. var position = viewer.camera.position;
  329. var x = position.x;
  330. var y = position.y;
  331. var z = position.z;
  332. var testPitch = pitch;
  333. var testHeading = heading;
  334. // console.log("获取当前视角x,y,z", position.x, position.y, position.z, "pitch", pitch, "heading", heading);
  335. var obj = {
  336. "x": x,
  337. "y": y,
  338. "z": z,
  339. "pitch": pitch,
  340. "heading": heading,
  341. }
  342. console.log(obj, "asd");
  343. },
  344. flatten3DArray(arr) {
  345. let stack = [...arr]; // 初始化栈,并将数组元素压入栈中
  346. let result = []; // 用于存储结果的一维数组
  347. while (stack.length > 0) {
  348. let current = stack.pop(); // 弹出栈顶元素
  349. if (Array.isArray(current)) {
  350. // 如果当前元素是数组,则将其元素压入栈中(逆序)
  351. for (let i = current.length - 1; i >= 0; i--) {
  352. stack.push(current[i]);
  353. }
  354. } else {
  355. // 如果当前元素不是数组,则将其添加到结果数组中
  356. result.push(current);
  357. }
  358. }
  359. // 注意:因为我们是逆序压入栈中的,所以结果数组的顺序与原始三维数组中的顺序相反
  360. // 如果需要保持原始顺序,可以在压入栈时使用unshift代替push,但这样会降低性能
  361. return result;
  362. },
  363. },
  364. beforeCreate() { }, //生命周期 - 创建之前
  365. created() { }, //生命周期 - 创建完成(可以访问当前this实例)
  366. beforeMount() { }, //生命周期 - 挂载之前
  367. async mounted() {
  368. this.$nextTick((res) => {
  369. cockpit.init(viewer);
  370. this.pick_xzqh();
  371. this.init_xzqh();
  372. this.init_hyqy();
  373. });
  374. }, //生命周期 - 挂在完成
  375. beforeUpdate() { }, //生命周期 - 更新之前
  376. updated() { }, //生命周期 - 更新之后
  377. beforeDestroy() { }, //生命周期 - 销毁之前
  378. destroy() { },//生命周期 - 销毁完成
  379. activated() {
  380. cockpit.hidden_xzqh(true);
  381. cockpit.hidden_wall(true);
  382. }, //若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用。
  383. deactivated() {
  384. cockpit.hidden_xzqh(false);
  385. cockpit.hidden_wall(false);
  386. } //若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用。
  387. };
  388. </script>
  389. <style scoped lang="scss" >
  390. .viewer {
  391. width: 100%;
  392. height: 100%;
  393. }
  394. .bg {
  395. width: 100%;
  396. height: 100%;
  397. .bg_left {
  398. width: 21.6%;
  399. height: calc(100% + 60px);
  400. position: absolute;
  401. top: -60px;
  402. left: 0;
  403. z-index: 100;
  404. background: linear-gradient(to right, rgba(6, 37, 66, 1), rgba(26, 28, 53, 0));
  405. }
  406. .bg_right {
  407. width: 21.6%;
  408. height: calc(100% + 60px);
  409. position: absolute;
  410. top: -60px;
  411. right: 0;
  412. z-index: 100;
  413. background: linear-gradient(to left, rgba(6, 37, 66, 1), rgba(26, 28, 53, 0));
  414. }
  415. .bg_bottom {
  416. width: 100%; // 56.8%;
  417. height: 30%;
  418. position: absolute;
  419. // left: 21.6%;
  420. bottom: 0;
  421. z-index: 100;
  422. background: linear-gradient(to top, rgba(6, 37, 66, 0.5), rgba(26, 28, 53, 0));
  423. }
  424. }
  425. .bottom_model {
  426. // border: 1px solid red;
  427. position: absolute;
  428. left: 28.5vw;
  429. width: 44vw;
  430. height: 29vh;
  431. z-index: 100;
  432. top: 38rem;
  433. .bjxm_box {
  434. // border: 1px solid red;
  435. width: 48%;
  436. height: 100%;
  437. display: inline-block;
  438. }
  439. .hysy_box {
  440. // border: 1px solid red;
  441. width: 48%;
  442. height: 100%;
  443. display: inline-block;
  444. float: right;
  445. }
  446. }
  447. </style>