viewer.vue 17 KB

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