农经大屏
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

238 satır
7.3 KiB

  1. import Header from '@/components/header/index.vue';
  2. import Tabs from '@/components/tabs/index.vue';
  3. import Left11 from './comps/left/top/1/index.vue';
  4. import Left21 from './comps/left/middle/1/index.vue';
  5. import Left31 from './comps/left/bottom/1/index.vue';
  6. import Right11 from './comps/right/top/1/index.vue';
  7. import Right21 from './comps/right/middle/1/index.vue';
  8. import Right31 from './comps/right/bottom/1/index.vue';
  9. import Left12 from './comps/left/top/2/index.vue';
  10. import Left22 from './comps/left/middle/2/index.vue';
  11. import Left32 from './comps/left/bottom/2/index.vue';
  12. import Right12 from './comps/right/top/2/index.vue';
  13. import Right22 from './comps/right/middle/2/index.vue';
  14. import Right32 from './comps/right/bottom/2/index.vue';
  15. import Bottom2 from './comps/buttom/2/index.vue';
  16. import Bottom1 from './comps/buttom/1/index.vue';
  17. import { getConfigKey } from "@/api/system/config";
  18. import { getInfo } from "@/api/login";
  19. import { treeselect, treeselectByDeptId } from "@/api/system/dept";
  20. import GisUtils from '@/utils/gis.js';
  21. import { comps } from './data.js'
  22. import {
  23. fromLonLat
  24. } from 'ol/proj'
  25. let gis = null;
  26. export default {
  27. components: {
  28. Header,
  29. Tabs,
  30. Left11,
  31. Left21,
  32. Left31,
  33. Right11,
  34. Right21,
  35. Right31,
  36. Left12,
  37. Left22,
  38. Left32,
  39. Right12,
  40. Right22,
  41. Right32,
  42. Bottom2,
  43. Bottom1
  44. },
  45. data () {
  46. return {
  47. tabData: [
  48. {
  49. id: '1',
  50. name: '统计分析'
  51. },
  52. {
  53. id: '2',
  54. name: '预警分析'
  55. }
  56. ],
  57. yellowIcon: require('./icon/yellow.png'),
  58. tab: '1',
  59. comps,
  60. map: "", // 地图
  61. mapGeoServerUrl: "", // geoserver地址
  62. mapBorder: "", // 地图边界
  63. deptLayer: "", // 坐标点图层
  64. countyBorderLayerName: "", // 区县边界图层名称
  65. townBorderLayerName: "", // 乡镇边界图层名称
  66. villageBorderLayerName: "", // 村边界图层名称
  67. groupBorderLayerName: "", // 组边界图层名称
  68. addrOptions: [],
  69. };
  70. },
  71. computed: {
  72. currentComp: function () {
  73. return this.comps[this.tab]
  74. }
  75. },
  76. created () {
  77. },
  78. mounted () {
  79. // 获取geoserver的地址
  80. this.getGeoServerUrl();
  81. getInfo().then(res => {
  82. // this.getData();
  83. treeselectByDeptId({ deptId: res.user.deptId }).then((resp) => {
  84. this.addrOptions = resp.data;
  85. // 初始化地图
  86. this.initMap();
  87. });
  88. });
  89. },
  90. methods: {
  91. tabChange (info) {
  92. this.tab = info.id;
  93. },
  94. // 初始化地图
  95. initMap () {
  96. let dept = this.addrOptions[0];
  97. let mapCenterLocation;
  98. if (dept.lng && dept.lat) {
  99. mapCenterLocation = [dept.lng, dept.lat];
  100. } else {
  101. mapCenterLocation = [116.391461, 39.902359];
  102. }
  103. gis = new GisUtils('map')
  104. gis.addTianDiTuLayer()
  105. gis.addAnnotationLayer()
  106. if (dept.deptLevel === '5') {
  107. // 登录身份为市级领导
  108. this.userRole = 'cityLeader';
  109. this.cityId = dept.id;
  110. this.currentDeptLevel = '5';
  111. // 添加区县边界
  112. this.addCountyBorder(dept.children.map(item => item.id));
  113. } else if (dept.deptLevel === '4') {
  114. // 登录身份为县级领导
  115. this.userRole = 'countyLeader';
  116. this.countyId = dept.id;
  117. this.currentDeptLevel = '4';
  118. // 添加乡镇边界
  119. this.addTownBorder(dept.children.map(item => item.id));
  120. gis.getView().setZoom(11);
  121. // this.villageIds = this.findLeafNodeIds(dept);
  122. } else if (dept.deptLevel === '3') {
  123. // 登录身份为镇级领导
  124. this.userRole = 'townLeader';
  125. this.townId = dept.id;
  126. this.currentDeptLevel = '3';
  127. // 添加村边界
  128. this.addVillageBorder(dept.children.map(item => item.id));
  129. this.map.getView().setZoom(13);
  130. // this.villageIds = this.findLeafNodeIds(dept);
  131. }
  132. // 添加坐标点图层
  133. if (dept.children) {
  134. this.addDeptLayer(dept.children, 'yellow.png');
  135. }
  136. gis.getView().setCenter(fromLonLat(mapCenterLocation))
  137. // 地图点击事件
  138. gis.getMapContainer().on("click", (evt) => {
  139. let feature = this.map.forEachFeatureAtPixel(
  140. evt.pixel,
  141. (feature) => feature
  142. );
  143. if (feature) {
  144. // 镇级:加载村级坐标点
  145. if (feature.get('level') === 'deptPoint') {
  146. let parentIds = [];
  147. this.findParentNodeIds(this.addrOptions, feature.get('deptId'), parentIds);
  148. this.addrText = parentIds;
  149. this.selectAddress(parentIds);
  150. }
  151. }
  152. });
  153. },
  154. selectAddress (value, isLocated = true) { // isLocated 控制地图是否跳转
  155. this.queryParams.deptId = value[value.length - 1];
  156. this.getData(DEPT_CHANGED);
  157. let node = this.$refs["cascader"].panel.getNodeByValue(value);
  158. this.drawMap(node, isLocated);
  159. },
  160. // 查找指定deptId的所有父节点id
  161. findParentNodeIds (tree, deptId, result) {
  162. for (let node of tree) {
  163. if (node.id === deptId) {
  164. result.unshift(node.id);
  165. return true;
  166. }
  167. if (node.children && node.children.length > 0) {
  168. let isFind = this.findParentNodeIds(node.children, deptId, result);
  169. if (isFind) {
  170. result.unshift(node.id);
  171. return true;
  172. }
  173. }
  174. }
  175. return false;
  176. },
  177. // 添加坐标点图层
  178. addDeptLayer (nextDeptSet) {
  179. let features = [];
  180. nextDeptSet.forEach(item => {
  181. let fs = gis.getFeature(item, this.yellowIcon)
  182. features.push(fs);
  183. });
  184. console.log(features, 88);
  185. gis.getVectorLayerByFs(features)
  186. gis.mapSetFit(features)
  187. },
  188. // 添加区县边界
  189. addCountyBorder (deptIds) {
  190. gis.addImageLayer(this.mapGeoServerUrl, this.countyBorderLayerName, deptIds)
  191. },
  192. // 添加乡镇边界
  193. addTownBorder (deptIds) {
  194. gis.addImageLayer(this.mapGeoServerUrl, this.townBorderLayerName, deptIds)
  195. },
  196. // 添加村边界
  197. addVillageBorder (deptIds) {
  198. gis.addImageLayer(this.mapGeoServerUrl, this.villageBorderLayerName, deptIds)
  199. },
  200. // 获取geoserver的地址
  201. getGeoServerUrl () {
  202. // 获取geoserver的地址
  203. getConfigKey("system.geoServer.url").then(response => {
  204. this.mapGeoServerUrl = response.msg;
  205. });
  206. // 获取区县边界图层名称
  207. getConfigKey("geoserver.layer.countyBorder").then(response => {
  208. this.countyBorderLayerName = response.msg;
  209. });
  210. // 获取乡镇边界的图层名称
  211. getConfigKey("geoserver.layer.townBorder").then(response => {
  212. this.townBorderLayerName = response.msg;
  213. });
  214. // 获取村边界的图层名称
  215. getConfigKey("geoserver.layer.villageBorder").then(response => {
  216. this.villageBorderLayerName = response.msg;
  217. });
  218. // 获取组边界的图层名称
  219. getConfigKey("geoserver.layer.groupBorder").then(response => {
  220. this.groupBorderLayerName = response.msg;
  221. });
  222. }
  223. }
  224. };