viewer行政区划渐变.vue 20 KB

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