query-graphics.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <script setup>
  2. /**
  3. * element-plus组件
  4. */
  5. import {
  6. ElMessage,
  7. ElLoading
  8. } from 'element-plus';
  9. import {
  10. inject
  11. } from "vue";
  12. const getMapInstance = inject("getMapInstance");
  13. jt3d = getMapInstance();
  14. </script>
  15. <template>
  16. <div class="jt-query-graphics">
  17. <el-row :gutter="20" style="margin-left: 0rem; margin-right: 0rem">
  18. <el-col :span="8" v-for="(item,index) in queryGraphics" @click="handleQueryGraphics(item.type,index)">
  19. <el-avatar shape="circle" :size="70" :class="currentIndex===index?'selectStyle':'defaultStyle'">
  20. <i :class="[item.icon,currentIndex===index?'selectFontStyle':'']" />
  21. </el-avatar>
  22. <div style="margin-top: 5rem; font-size: 14rem;" :class="currentIndex===index?'selectFontStyle':''">{{item.label}}</div>
  23. </el-col>
  24. </el-row>
  25. </div>
  26. </template>
  27. <script>
  28. let jt3d = undefined;
  29. let loading = undefined;
  30. import {
  31. Store
  32. } from '@/store/index'
  33. let store = Store();
  34. import {
  35. deepTree
  36. } from "@/utils/deepTree.js";
  37. export default {
  38. props: {
  39. },
  40. watch: {
  41. },
  42. /* 数据 */
  43. data() {
  44. return {
  45. currentIndex: -1,
  46. queryGraphics: [{
  47. label: '点查询',
  48. type: 'Point',
  49. number: 0,
  50. icon: 'iconfont icon-svgdianchaxun'
  51. },
  52. {
  53. label: '线查询',
  54. type: 'Line',
  55. number: 1,
  56. icon: 'iconfont icon-svgxianchaxun'
  57. },
  58. {
  59. label: '圆形查询',
  60. type: 'Circle',
  61. number: 2,
  62. icon: 'iconfont icon-svgyuanxingchaxun'
  63. },
  64. {
  65. label: '矩形查询',
  66. type: 'Rectangle',
  67. number: 3,
  68. icon: 'iconfont icon-svgjuxingchaxun'
  69. },
  70. {
  71. label: '多边形',
  72. type: 'Polygon',
  73. number: 4,
  74. icon: 'iconfont icon-svgduobianxingchaxun'
  75. },
  76. {
  77. label: '清除',
  78. type: 'clear',
  79. number: 5,
  80. icon: 'iconfont icon-shanchu'
  81. },
  82. ],
  83. }
  84. },
  85. /* 方法 */
  86. methods: {
  87. /**
  88. * 查询事件
  89. * @param {Object} type 查询类型
  90. * @param {Object} index 第几个被选中
  91. */
  92. handleQueryGraphics(type, index) {
  93. let _self = this;
  94. this.currentIndex = index;
  95. //移除左键单击事件
  96. if (jt3d.handlerLeftClick) {
  97. jt3d.handlerLeftClick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); //移除事件
  98. }
  99. jt3d.CommonTools.clear();
  100. switch (type) {
  101. case "Point": //点查询
  102. jt3d.CommonTools.queryByPoint(function(coordinates) {
  103. console.log(coordinates)
  104. //还原左键单击事件
  105. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  106. /* 转换坐标 */
  107. let points = coordinates.split(',');
  108. _self.initQuery({
  109. spatialType: '点',
  110. coordinate: Number(points[0]) + " " + Number(points[1]),
  111. buffer: ''
  112. });
  113. });
  114. break;
  115. case "Line": //线查询
  116. jt3d.CommonTools.queryByLine(function(coordinates) {
  117. console.log(coordinates)
  118. //还原左键单击事件
  119. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  120. /* 转换坐标 */
  121. let points = coordinates.split(',');
  122. let pointsArray = [];
  123. for (let i = 0; i < points.length;) {
  124. pointsArray.push(Number(points[i]) + " " + Number(points[i + 1]));
  125. i = i + 2;
  126. }
  127. _self.initQuery({
  128. spatialType: '线',
  129. coordinate: pointsArray.join(','),
  130. buffer: ''
  131. });
  132. });
  133. break;
  134. case "Circle": //圆形查询
  135. jt3d.CommonTools.queryByCircle(function(coordinates, radius) {
  136. console.log("圆点:" + coordinates + ",半径:" + radius)
  137. //还原左键单击事件
  138. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  139. /* 转换坐标 */
  140. let points = coordinates.split(',');
  141. _self.initQuery({
  142. spatialType: '点',
  143. coordinate: Number(points[0]) + " " + Number(points[1]),
  144. buffer: radius
  145. });
  146. });
  147. break;
  148. case "Rectangle": //矩形查询
  149. jt3d.CommonTools.queryByRectangle(function(coordinates) {
  150. console.log(coordinates)
  151. //还原左键单击事件
  152. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  153. /* 转换坐标 */
  154. let points = coordinates.split(',');
  155. let pointsArray = [];
  156. for (let i = 0; i < points.length;) {
  157. pointsArray.push(Number(points[i]) + " " + Number(points[i + 1]));
  158. i = i + 2;
  159. }
  160. _self.initQuery({
  161. spatialType: '面',
  162. coordinate: pointsArray.join(','),
  163. buffer: ''
  164. });
  165. });
  166. break;
  167. case "Polygon": //多边形查询
  168. jt3d.CommonTools.queryByPolygon(function(coordinates) {
  169. console.log(coordinates)
  170. //还原左键单击事件
  171. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  172. /* 转换坐标 */
  173. let points = coordinates.split(',');
  174. let pointsArray = [];
  175. for (let i = 0; i < points.length;) {
  176. pointsArray.push(Number(points[i]) + " " + Number(points[i + 1]));
  177. i = i + 2;
  178. }
  179. _self.initQuery({
  180. spatialType: '面',
  181. coordinate: pointsArray.join(','),
  182. buffer: ''
  183. });
  184. });
  185. break;
  186. case "clear": //清除查询效果
  187. this.currentIndex = -1;
  188. //清除绘制
  189. jt3d.CommonTools.clear();
  190. //还原左键单击事件
  191. this.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  192. //清除高亮显示
  193. let list = jt3d._dataSources.getByName("单击高亮显示")
  194. list.forEach(res => {
  195. jt3d._dataSources.remove(res)
  196. })
  197. //清除定位样式
  198. if (jt3d.LocateUtil._locationEntity) {
  199. window["viewer"].entities.remove(jt3d.LocateUtil._locationEntity);
  200. }
  201. break;
  202. }
  203. },
  204. /**
  205. * @param {Object} options
  206. */
  207. initQuery(options) {
  208. let _self = this;
  209. let treeNodes = [];
  210. //清除高亮显示
  211. let list = jt3d._dataSources.getByName("单击高亮显示")
  212. list.forEach(res => {
  213. jt3d._dataSources.remove(res)
  214. })
  215. //清除定位样式
  216. if (jt3d.LocateUtil._locationEntity) {
  217. window["viewer"].entities.remove(jt3d.LocateUtil._locationEntity);
  218. }
  219. //查询等待框
  220. loading = ElLoading.service({
  221. lock: true,
  222. text: 'Loading',
  223. background: 'rgba(0, 0, 0, 0.7)',
  224. });
  225. const getData = () => {
  226. let data = [];
  227. store.queryMapTables.forEach((itemTable, index) => {
  228. let result = getAxios(itemTable, options);
  229. data.push(result);
  230. })
  231. Promise.all(data).then(itemList => {
  232. console.log("itemList", itemList) //itemList返回的数据是按顺序的
  233. //执行自己接下来的操作
  234. //doSomething
  235. itemList.forEach((item, index) => {
  236. let field = item.table;
  237. let tableName = item.table[0].tableName;
  238. let tableDescription = item.table[0].tableDescription;
  239. if (item.data.features.length > 0) {
  240. //添加父节点
  241. let parentNode = {
  242. id: tableName,
  243. parentid: "CIM",
  244. label: tableDescription + "(" + item.data.features.length + ")",
  245. };
  246. treeNodes.push(parentNode);
  247. item.data.features.forEach((itemData, index) => {
  248. //**************高亮显示****************
  249. // /* 转换坐标 */
  250. // let positions = itemData.geometry.coordinates[0][0].map(point => {
  251. // return Cesium.Cartesian3.fromDegrees(point[0], point[1], point[2] || 0);
  252. // });
  253. // //先创建一个CustomDataSource源,然后把entity存入这里面
  254. // let Polygon = new Cesium.CustomDataSource("单击高亮显示");
  255. // jt3d._dataSources.add(Polygon);
  256. // //添加数据的方式
  257. // Polygon.entities.add({
  258. // polygon: {
  259. // hierarchy: new Cesium.PolygonHierarchy(positions),
  260. // material: Cesium.Color.fromCssColorString("rgba(255,0,255,.7)"),
  261. // classificationType: Cesium.ClassificationType.BOTH,
  262. // },
  263. // });
  264. //**************高亮显示****************
  265. let childNode = {
  266. id: itemData.properties["id"],
  267. parentid: tableName,
  268. field: field,
  269. data: itemData,
  270. };
  271. switch (tableName) {
  272. //==============规划管理数据-重要控制线=========================
  273. case "yjjbnt": //永久基本农田
  274. childNode.label = itemData.properties["cfzr"] + "(" + itemData.properties["zzsxmc"] + ")"
  275. break;
  276. case "yjtz": //永久基本农田调整
  277. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  278. break;
  279. case "bnrgdbh": //不纳入耕地保护目标
  280. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  281. break;
  282. case "gdbhrw": //耕地保护任务
  283. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  284. break;
  285. //==============规划管理数据-历史规划==============
  286. case "tdzgh": //土地利用总体规划
  287. childNode.label = itemData.properties["ghdlmc"]
  288. break;
  289. case "jsyd": //建设用地管制区
  290. childNode.label = itemData.properties["id"]
  291. break;
  292. //==============现状类数据-森林资源-森林资源调查==============
  293. case "slyzt": //2019年森林资源管理一张图
  294. childNode.label = itemData.properties["id"]
  295. break;
  296. //==============现状类数据-国土调查==============
  297. case "ed2009": //二调
  298. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  299. break;
  300. case "ed2020": //二调2020
  301. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  302. break;
  303. case "ed2021": //二调2021
  304. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  305. break;
  306. case "sddltb": //三调
  307. childNode.label = itemData.properties["zldwmc"] + "(" + itemData.properties["dlmc"] + ")"
  308. break;
  309. }
  310. treeNodes.push(childNode);
  311. });
  312. }
  313. });
  314. //处理左侧树
  315. _self.$parent.$parent.$refs.refQueryResult.expandedKeys = []
  316. _self.$parent.$parent.$refs.refQueryResultPopup.isshow = true;
  317. _self.$parent.$parent.$refs.refQueryResult.treeData = deepTree(treeNodes);
  318. //默认选中第一个节点并赋予选中样式
  319. _self.$nextTick(function() {
  320. let currentNode = _self.$parent.$parent.$refs.refQueryResult.treeData[0].children[0];
  321. let currentKey = currentNode.id;
  322. _self.$parent.$parent.$refs.refQueryResult.currentKey = currentKey;
  323. _self.$parent.$parent.$refs.refQueryResult.$refs.tree.setCurrentKey(currentKey);
  324. _self.$parent.$parent.$refs.refQueryResult.handleNodeClick(currentNode);
  325. });
  326. //expandedKeys默认展开treedata第一层,加载第一层数据
  327. _self.$parent.$parent.$refs.refQueryResult.expandedKeys.push(_self.$parent.$parent.$refs.refQueryResult.treeData[0].id)
  328. //清除绘制
  329. jt3d.CommonTools.clear();
  330. //关闭等待框
  331. loading.close()
  332. })
  333. }
  334. const getAxios = (itemTable, options) => {
  335. return new Promise(function(resolve, reject) {
  336. _self.$http.get('/getSpatialQuery', {
  337. tableName: itemTable,
  338. spatialType: options.spatialType,
  339. coordinate: options.coordinate,
  340. buffer: options.buffer
  341. }).then(res => {
  342. resolve(res)
  343. });
  344. }).catch(err => {
  345. })
  346. }
  347. getData();
  348. },
  349. },
  350. mounted() {
  351. }
  352. };
  353. </script>
  354. <style lang="scss" scoped>
  355. .jt-query-graphics {
  356. .el-col {
  357. padding: 10rem;
  358. // color: rgba(90, 172, 255, 1.0);
  359. //color: #55ffff;
  360. color: #fff;
  361. }
  362. i {
  363. display: inline-block;
  364. width: 100%;
  365. height: 36rem;
  366. line-height: 36rem;
  367. text-align: center;
  368. border-radius: 5rem;
  369. font-size: 40rem;
  370. // color: rgba(90, 172, 255, 1.0);
  371. // color: #55ffff;
  372. color: #fff;
  373. transition: all .3s;
  374. -webkit-transition: all .3s
  375. }
  376. .selectStyle {
  377. // background: rgba(135, 182, 254, 0.5);
  378. background: rgb(0 44 126);
  379. }
  380. .defaultStyle {
  381. background: #ffffff00;
  382. }
  383. .selectFontStyle {
  384. color: #fff;
  385. }
  386. }
  387. </style>