viewer1.vue 20 KB

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