viewer.vue 21 KB

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