query-graphics.vue 12 KB

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