clickQuery.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. <template>
  2. <div class="sm-panel sm-function-module-query" v-show="PoinyQueryShow && vectorShow" v-drag>
  3. <div class="sm-panel-header">
  4. <span>{{ Resource.PoinyQuery }}</span>
  5. <span class="closeBtn" @click="toggleVisibility">&times;</span>
  6. </div>
  7. <!-- <div class="sm-function-module-content-btn"> -->
  8. <div class="btnList">
  9. <span v-for="(item, index) in actionOptions" :key="index" class="icon-span" :title="item.lable"
  10. :class="item.isSelect ? 'selected-icon' : ''" @click="changleQueryItem(item)">
  11. <i class="iconfont iconSize" :class="item.iconName" style="margin-top: 0px"></i>
  12. </span>
  13. <!-- <el-button type="primary" size="small" @click.stop="mapLayerQuery"
  14. >点击</el-button
  15. >
  16. <el-button type="primary" size="small" @click.stop="removeMapLayerQuery"
  17. >清除</el-button
  18. > -->
  19. </div>
  20. <div class="sm-function-module-content-tabs">
  21. <el-tabs @tab-click="handleTabClick" v-model="activeLayerId">
  22. <el-tab-pane :label="item.label" :name="item.id" v-for="(item, index) in layerList" :key="index"></el-tab-pane>
  23. </el-tabs>
  24. </div>
  25. <div class="sm-function-module-content-table">
  26. <el-collapse :value="activeNames" @change="handleCollapseChange" v-if="activeLayerId &&
  27. queryResults[activeLayerId] &&
  28. queryResults[activeLayerId].length > 0
  29. ">
  30. <el-collapse-item :title="'查询结果' + (index + 1)" :name="'查询结果' + (index + 1)"
  31. v-for="(item, index) in queryResults[activeLayerId]" :key="index">
  32. <template slot="title">
  33. 查询结果{{ index + 1
  34. }}<i title="定位" class="header-icon el-icon-s-promotion flyBtn2" @click.stop="flyTo(index)"></i>
  35. </template>
  36. <el-table :data="item" :show-header="false" border style="width: 100%" :header-cell-style="{
  37. background: 'rgba(10, 25, 38, 0.6)',
  38. color: '#66b1ff',
  39. fontSize: '14px',
  40. fontFamily: 'Microsoft YaHei',
  41. fontWeight: '400',
  42. }">
  43. <el-table-column prop="name" label="字段" width="100">
  44. </el-table-column>
  45. <el-table-column prop="value" label="值" width="208">
  46. </el-table-column>
  47. </el-table>
  48. </el-collapse-item>
  49. </el-collapse>
  50. </div>
  51. <CockpitVector v-if="store.state.vectorData.length > 0"></CockpitVector>
  52. <MultiLevelQuery ref="MultiLevelQuery" />
  53. </div>
  54. </template>
  55. <script>
  56. import axios from "axios";
  57. import { GetGDlnfo, GetXzqhTree, GetHouseInfo } from "../../../api/map";
  58. import { keys } from "lodash";
  59. import { handModel, handnew, clearTranslate, keyName } from "./modelLayering";
  60. import CockpitVector from "./CockpitVector.vue";
  61. import MultiLevelQuery from "./MultiLevelQuery.vue";
  62. import * as pick_cockpit_vector from "./pick_cockpit_vector.js";
  63. import * as tdsy from "@/views/cockpit/js/tdsy";
  64. import * as turf from "@turf/turf";
  65. let gwtype;
  66. let query_click = null;
  67. export default {
  68. name: "clickQuery",
  69. components: { CockpitVector, MultiLevelQuery },
  70. data() {
  71. return {
  72. inited: false,
  73. activeLayerName: "",
  74. columns: [
  75. {
  76. title: "字段",
  77. key: "name",
  78. },
  79. {
  80. title: "值",
  81. key: "value",
  82. },
  83. ],
  84. layersDataUrl: window.layersDataUrl,
  85. layersData: [],
  86. layerList: [],
  87. loading: false,
  88. handler: {},
  89. activeNames: "查询结果1",
  90. activeLayerId: "",
  91. queryResults: {},
  92. queryResultsGeom: {},
  93. queryResultsGeomPart: {},
  94. viewer: null,
  95. dataSourceLayer: null,
  96. actionOptions: [
  97. {
  98. index: 1,
  99. lable: "图层",
  100. iconName: "el-icon-tickets",
  101. isSelect: false,
  102. },
  103. {
  104. index: 2,
  105. lable: "模型",
  106. iconName: "el-icon-office-building",
  107. isSelect: false,
  108. },
  109. {
  110. index: 4,
  111. lable: "矢量",
  112. iconName: "el-icon-picture",
  113. isSelect: false,
  114. }, {
  115. index: 5,
  116. lable: "联级查询",
  117. iconName: "el-icon-c-scale-to-original",
  118. isSelect: false,
  119. },
  120. {
  121. index: 3,
  122. lable: "清除",
  123. iconName: "el-icon-delete",
  124. isSelect: false,
  125. },
  126. ],
  127. };
  128. },
  129. computed: {
  130. PoinyQueryShow: function () {
  131. return store.state.toolBar[9];
  132. },
  133. vectorShow: function () {
  134. return store.state.cockpit_vector.title || store.state.cockpit_vector.goitem ? !store.state.viewer_flag : true
  135. },
  136. },
  137. created() { },
  138. watch: {
  139. activeLayerId(val) {
  140. if (val && val != "0") {
  141. for (let i = 0; i < store.state.vectorlayerlist.length; i++) {
  142. let obj = store.state.vectorlayerlist[i];
  143. if (obj.id == val) {
  144. if (obj.type == "S3M") {
  145. this.addGeometrys(true);
  146. } else {
  147. this.addGeometrys();
  148. }
  149. break;
  150. }
  151. }
  152. }
  153. },
  154. PoinyQueryShow(val) {
  155. if (!this.inited) {
  156. this.inited = !this.inited;
  157. this.viewer = viewer;
  158. this.viewer.entities.removeAll();
  159. this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  160. this.dataSourceLayer = new Cesium.CustomDataSource("query");
  161. this.viewer.dataSources.add(this.dataSourceLayer);
  162. }
  163. },
  164. },
  165. mounted() {
  166. this.$nextTick((res) => {
  167. query_click = new Cesium.CustomDataSource("query_click");
  168. viewer.dataSources.add(query_click);
  169. });
  170. },
  171. methods: {
  172. isArray2D(arr) {
  173. // 首先检查arr是否是数组
  174. if (!Array.isArray(arr)) {
  175. return false;
  176. }
  177. // 检查数组中的每个元素是否也是数组
  178. for (let i = 0; i < arr.length; i++) {
  179. if (!Array.isArray(arr[i])) {
  180. return false;
  181. }
  182. }
  183. // 如果所有元素都是数组,那么arr是二维数组
  184. return true;
  185. },
  186. toggleVisibility() {
  187. this.removeMapLayerQuery();
  188. store.setToolBarAction(9);
  189. tdsy.remove()
  190. store.state.vectorData = [];
  191. },
  192. addGeometrys(fill) {
  193. this.viewer.entities.removeAll();
  194. this.dataSourceLayer.entities.removeAll();
  195. let geoms = this.queryResultsGeom[this.activeLayerId];
  196. let parts = this.queryResultsGeomPart[this.activeLayerId];
  197. for (let i = 0; i < geoms.length; i++) {
  198. let cur = geoms[i];
  199. let part = parts[i];
  200. let start = 0;
  201. let end = 0;
  202. for (let k = 0; k < part.length; k++) {
  203. let points = [];
  204. if (k > 0) {
  205. start += part[k - 1];
  206. }
  207. end += part[k];
  208. for (let j = start; j < end; j++) {
  209. let cx = cur[j][0];
  210. let cy = cur[j][1];
  211. points.push(cx);
  212. points.push(cy);
  213. }
  214. if (fill) {
  215. this.viewer.entities.add({
  216. polyline: new Cesium.PolylineGraphics({
  217. positions: Cesium.Cartesian3.fromDegreesArray(points),
  218. width: 3,
  219. material: Cesium.Color.BLUE.withAlpha(0.9),
  220. clampToGround: true,
  221. }),
  222. polygon: {
  223. //高程
  224. hierarchy: new Cesium.PolygonHierarchy(
  225. Cesium.Cartesian3.fromDegreesArray(points)
  226. ),
  227. classificationType: Cesium.ClassificationType.BOTH,
  228. clampToGround: false,
  229. material: Cesium.Color.RED.withAlpha(0.3),
  230. // material: videoElement,
  231. // perPositionHeight: true
  232. },
  233. });
  234. } else {
  235. this.viewer.entities.add({
  236. polyline: new Cesium.PolylineGraphics({
  237. positions: Cesium.Cartesian3.fromDegreesArray(points),
  238. width: 3,
  239. material: Cesium.Color.BLUE.withAlpha(0.9),
  240. clampToGround: true,
  241. }),
  242. });
  243. }
  244. }
  245. // this.viewer.flyTo(this.viewer.entities);
  246. }
  247. },
  248. flyTo(index) {
  249. this.dataSourceLayer.entities.removeAll();
  250. let geoms = this.queryResultsGeom[this.activeLayerId];
  251. let parts = this.queryResultsGeomPart[this.activeLayerId];
  252. let cur = geoms[index];
  253. if (cur) {
  254. let part = parts[index];
  255. let start = 0;
  256. let end = 0;
  257. for (let k = 0; k < part.length; k++) {
  258. let points = [];
  259. if (k > 0) {
  260. start += part[k - 1];
  261. }
  262. end += part[k];
  263. for (let j = start; j < end; j++) {
  264. let cx = cur[j][0];
  265. let cy = cur[j][1];
  266. points.push(cx);
  267. points.push(cy);
  268. }
  269. let e = this.dataSourceLayer.entities.add({
  270. polyline: new Cesium.PolylineGraphics({
  271. positions: Cesium.Cartesian3.fromDegreesArray(points),
  272. width: 3,
  273. material: Cesium.Color.RED.withAlpha(0.9),
  274. clampToGround: true,
  275. }),
  276. });
  277. }
  278. this.viewer.flyTo(this.dataSourceLayer);
  279. } else {
  280. this.$message({
  281. message: "空间范围为空!",
  282. type: "warning",
  283. });
  284. }
  285. },
  286. handleTabClick(item, a) {
  287. this.activeLayerId = item.name;
  288. console.log('this.: ', this.activeLayerId);
  289. },
  290. // 设置数据
  291. setData() {
  292. this.dataSourceLayer = new Cesium.CustomDataSource("query");
  293. this.viewer.dataSources.add(this.dataSourceLayer);
  294. this.activeLayerId = "0";
  295. this.queryResults = {};
  296. this.queryResultsGeom = {};
  297. this.queryResultsGeomPart = {};
  298. },
  299. /**
  300. * 左键点击查询图层
  301. */
  302. async mapLayerQuery(movement) {
  303. let that = this;
  304. that.activeLayerId = "0";
  305. that.layerList = [];
  306. that.layersData = [];
  307. let scene = viewer.scene;
  308. that.viewer.entities.removeAll();
  309. that.dataSourceLayer.entities.removeAll();
  310. //拾取模型
  311. let pickedFeature = scene.pick(movement.position);
  312. if (
  313. scene.pickPositionSupported &&
  314. Cesium.defined(pickedFeature) &&
  315. pickedFeature != null &&
  316. pickedFeature.primitive
  317. ) {
  318. let eneityName = pickedFeature.primitive.name;
  319. let Pid = "";
  320. var tempArr = [];
  321. // "ResultNetWork@管线#1"///"ResultNetWork_Node@管线#1"
  322. if (eneityName.indexOf("雨水") > -1 || eneityName.indexOf("管线") > -1) {
  323. let buildingLayer = scene.layers.find(eneityName);
  324. buildingLayer.indexedDBSetting.isAttributesSave = true; //保存属性
  325. if (buildingLayer.getSelection().length > 0) {
  326. const selectedId = Number(buildingLayer.getSelection()[0]);
  327. buildingLayer.getAttributesById([selectedId]).then(function (atts) {
  328. if (atts) {
  329. Pid = atts["管线段"] || atts["物探点"];
  330. var length = Object.keys(atts).length;
  331. var des;
  332. for (var i = 0; i < length; i++) {
  333. var key = Object.keys(atts)[i];
  334. var value = atts[key];
  335. // console.log(key);
  336. // console.log(value);
  337. if (
  338. key.toLowerCase().indexOf("shape") < 0 &&
  339. key.toLowerCase().indexOf("sm") &&
  340. value != ""
  341. ) {
  342. tempArr.push({
  343. name: key,
  344. value: value,
  345. });
  346. }
  347. }
  348. }
  349. //获取图层id的参数
  350. let substring = pickedFeature.primitive._baseUri.query;
  351. for (let p = 0; p < store.state.vectorlayerlist.length; i++) {
  352. if (store.state.vectorlayerlist[p].id == substring) {
  353. that.layerList.push(store.state.vectorlayerlist[p]);
  354. break;
  355. }
  356. }
  357. that.queryResults[substring] = [tempArr];
  358. that.queryResultsGeom[substring] = [];
  359. that.activeLayerId = substring;
  360. });
  361. }
  362. }
  363. that.loading = true;
  364. that.queryByPickFeature(pickedFeature, function (result, Fields) {
  365. that.loading = false;
  366. if (result != null && result.features[0].fieldNames) {
  367. result.features[0].fieldNames.forEach((fieldName, i) => {
  368. const Field = Fields.find((c) => c.FieldEn == fieldName);
  369. let v = result.features[0].fieldValues[i];
  370. if (!isNaN(parseFloat(v))) {
  371. v = Math.round(parseFloat(v) * 100) / 100;
  372. }
  373. that.layersData.push({
  374. label: Field ? Field.FieldCn : fieldName,
  375. value: v,
  376. });
  377. });
  378. } else {
  379. that.layersData = [];
  380. }
  381. });
  382. } else {
  383. //拾取图层
  384. // let pickRay = viewer.camera.getPickRay(movement.position);
  385. // let artesian3 = viewer.scene.globe.pick(pickRay, viewer.scene);
  386. let artesian3 = viewer.scene.pickPosition(movement.position);
  387. let xy = that.cartesian3ToWGS84(artesian3);
  388. //TODO wanger 分图层查询
  389. for (let i = 0; i < store.state.vectorlayerlist.length; i++) {
  390. let obj = store.state.vectorlayerlist[i];
  391. if (!obj.source) {
  392. continue;
  393. }
  394. let queryByIDParameters = {
  395. getFeatureMode: "BUFFER",
  396. // getFeatureMode: "SPATIAL",
  397. spatialQueryMode: "INTERSECT",
  398. datasetNames: obj.source.split(","),
  399. geometry: {
  400. parts: [1],
  401. points: [{ y: xy.lat, x: xy.lng }],
  402. type: "POINT",
  403. },
  404. bufferDistance: 0.00005,
  405. hasGeometry: true,
  406. };
  407. let e;
  408. if (obj.type == "S3M") {
  409. e = await that.mapQuery(
  410. window.baseModelQueryLayer,
  411. queryByIDParameters
  412. );
  413. } else {
  414. e = await that.mapQuery(
  415. that.calcIserverURI(obj.url),
  416. queryByIDParameters
  417. );
  418. }
  419. // 结果高亮
  420. const outputCoords = this.convertCoordinates(e.features[0].geometry.points);
  421. outputCoords.push(outputCoords[0])
  422. let f = { "type": "Polygon", "coordinates": [outputCoords] };
  423. let result = turf.buffer(f, 1 / 99999, {
  424. units: "kilometers",
  425. });
  426. let positions = [];
  427. const twoDArray = result.geometry.coordinates[0];
  428. const oneDArray = twoDArray.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
  429. positions = oneDArray;
  430. if (this.isArray2D(oneDArray)) {
  431. const oneDArray2 = oneDArray.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
  432. positions = oneDArray2;
  433. } else {
  434. }
  435. query_click.entities.add({
  436. polygon: {
  437. // 获取指定属性(positions,holes(图形内需要挖空的区域))
  438. hierarchy: {
  439. positions: Cesium.Cartesian3.fromDegreesArray(positions)
  440. },
  441. // 边框
  442. outline: false,
  443. // 边框颜色
  444. outlineColor: Cesium.Color.RED,
  445. // 边框尺寸
  446. outlineWidth: 10,
  447. // 填充的颜色,withAlpha透明度
  448. material: Cesium.Color.RED,
  449. // 是否被提供的材质填充
  450. fill: true,
  451. // 恒定高度
  452. height: 1.1,
  453. // 显示在距相机的距离处的属性,多少区间内是可以显示的
  454. // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1000, 10000000),
  455. // 是否显示
  456. show: true,
  457. // 顺序,仅当`clampToGround`为true并且支持地形上的折线时才有效。
  458. zIndex: 10
  459. }
  460. });
  461. if (e && e.totalCount > 0) {
  462. that.layerList.push(store.state.vectorlayerlist[i]);
  463. let queryData = [];
  464. let geoms = [];
  465. let tempTreeData = store.state.tempResourceTree;
  466. //递归查询点击的图层信息
  467. function getTreeId(list, id) {
  468. //判断list是否是数组
  469. if (!list instanceof Array) {
  470. return null;
  471. }
  472. //遍历数组
  473. for (let i in list) {
  474. let item = list[i];
  475. if (item.id === id) {
  476. return item;
  477. } else {
  478. //查不到继续遍历
  479. if (item.children) {
  480. let value = getTreeId(item.children, id);
  481. //查询到直接返回
  482. if (value) {
  483. return value;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. let parts = [];
  490. let legendJson = getTreeId(tempTreeData, obj.id);
  491. for (let u = 0; u < e.features.length; u++) {
  492. let cur = [];
  493. // if (legendJson.legend != "") {
  494. // //将数据转为json
  495. // let parseJson = JSON.parse(legendJson.legend);
  496. // //初始化下标
  497. // let index = -1;
  498. // var linSAr = JSON.parse(JSON.stringify(e.features[u]));
  499. // parseJson.forEach((p) => {
  500. // //将数据改为大写
  501. // p.fieldname = p.fieldname.toUpperCase();
  502. // let index1 = linSAr.fieldNames.indexOf(p.fieldname);
  503. // if (index1 > -1 && !condition(p)) {
  504. // this.$delete(linSAr.fieldNames, index1);
  505. // this.$delete(linSAr.fieldValues, index1);
  506. // }
  507. // //判断数据是否存在
  508. // index = linSAr.fieldNames.indexOf(p.fieldname);
  509. // if (index > -1 && p.fieldaliasname != p.fieldname) {
  510. // //如果数据存在数组中并且进行了修改,找到它对应的下标对数据进行替换
  511. // linSAr.fieldNames[index] = p.fieldaliasname;
  512. // }
  513. // });
  514. // } else {
  515. // var linSAr = JSON.parse(JSON.stringify(e.features[u]));
  516. // }
  517. var linSAr = JSON.parse(JSON.stringify(e.features[u]));
  518. let parseJson = legendJson.legend != "" ? JSON.parse(legendJson.legend) : [];
  519. function condition(ci) {
  520. return ci.status != undefined && ci.status;
  521. }
  522. if (e.features[u].fieldNames) {
  523. linSAr.fieldNames.forEach((fieldName, i) => {
  524. let perjson = parseJson.filter(p=> p.fieldname.toUpperCase() == fieldName);
  525. if (perjson.length > 0) {
  526. var show = condition(perjson[0]);
  527. var order = perjson[0].order || linSAr.fieldNames.length;
  528. if(fieldName != perjson[0].fieldaliasname)
  529. fieldName=perjson[0].fieldaliasname
  530. }
  531. if (linSAr.fieldValues[i] != "" && show) {
  532. let v = linSAr.fieldValues[i];
  533. if (!isNaN(parseFloat(v))) {
  534. v = Math.round(parseFloat(v) * 100) / 100;
  535. }
  536. cur.push({
  537. name: fieldName,
  538. value: v,
  539. order,
  540. });
  541. }
  542. });
  543. // e.features[u].fieldNames.forEach((fieldName, i) => {
  544. // if (
  545. // fieldName.toLowerCase().indexOf("shape") < 0 &&
  546. // fieldName.toLowerCase().indexOf("sm") &&
  547. // e.features[u].fieldValues[i] != ""
  548. // ) {
  549. // let v = e.features[u].fieldValues[i];
  550. // if (!isNaN(parseFloat(v))) {
  551. // v = Math.round(parseFloat(v) * 100) / 100;
  552. // }
  553. // cur.push({
  554. // name: fieldName,
  555. // value: v,
  556. // });
  557. // }
  558. // });
  559. } else {
  560. that.$message({
  561. message: "查询结果为空!",
  562. type: "warning",
  563. customClass: "messageIndex",
  564. });
  565. }
  566. //排序
  567. cur.sort((a, b) => a.order - b.order);
  568. // cur.sort((a, b) => {
  569. // if (a === b) {
  570. // return 0;
  571. // } else if (a.value == null || a.value == "") {
  572. // return 1;
  573. // } else if (b.value == null || b.value == "") {
  574. // return -1;
  575. // } else {
  576. // // 降序
  577. // return a.value < b.value ? 1 : -1;
  578. // }
  579. // });
  580. let points = [];
  581. for (let y = 0; y < e.features[u].geometry.points.length; y++) {
  582. let c = that.cartesianToCartographic84(
  583. e.features[u].geometry.points[y].x,
  584. e.features[u].geometry.points[y].y
  585. );
  586. points.push([c.x, c.y]);
  587. }
  588. parts.push(e.features[u].geometry.parts);
  589. geoms.push(points);
  590. queryData.push(cur);
  591. }
  592. that.queryResultsGeomPart[obj.id] = parts;
  593. that.queryResults[obj.id] = queryData;
  594. that.queryResultsGeom[obj.id] = geoms;
  595. }
  596. }
  597. if (that.layerList.length > 0) {
  598. that.activeLayerId = that.layerList[0].id;
  599. } else {
  600. that.$message({
  601. message: "查询结果为空!",
  602. type: "warning",
  603. customClass: "messageIndex",
  604. });
  605. }
  606. }
  607. },
  608. addLayerList(label) {
  609. if (this.layerList.findIndex((a) => a.label == label) >= 0) return;
  610. let layers = store.state.vectorlayerlist.filter(
  611. (element) => element.label === label
  612. );
  613. if (layers.length > 0) {
  614. this.activeLayerId = layers[0].id;
  615. this.layerList.push(layers[0]);
  616. }
  617. },
  618. /**
  619. * 左键点击模型查询
  620. */
  621. mapModelQuery(movement) {
  622. this.activeLayerId = "0";
  623. this.layerList = [];
  624. this.layersData = [];
  625. this.viewer.entities.removeAll();
  626. this.dataSourceLayer.entities.removeAll();
  627. let title;
  628. if (store.state.checkedData) title = store.state.checkedData.title;
  629. // 超图分层分户
  630. if (title == "分层分户" || title == "8号楼-谷") {
  631. let id = handModel(movement);
  632. } else {
  633. handnew(movement);
  634. }
  635. let newArr = [];
  636. GetHouseInfo({ id: "2c01647f-4533-4472-b20b-f5caa4c705b0" }).then(
  637. (res) => {
  638. for (const [key, value] of Object.entries(res.data)) {
  639. newArr.push({ name: keyName[key], value: value });
  640. }
  641. this.addLayerList(title);
  642. this.queryResults[this.activeLayerId] = [newArr];
  643. this.queryResultsGeom[this.activeLayerId] = [];
  644. }
  645. );
  646. },
  647. mapQuerys(queryName) {
  648. this.setData();
  649. let that = this;
  650. this.handler.setInputAction(function (movement) {
  651. that[queryName](movement);
  652. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  653. this.handler.setInputAction(function () {
  654. that.removeMapLayerQuery();
  655. clearTranslate();
  656. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  657. },
  658. /**
  659. * 超图
  660. * 根据返回的三维对象查询数据信息
  661. *
  662. * @param {*} param
  663. */
  664. async queryByPickFeature(param, completed) {
  665. if (param.primitive) {
  666. let dataUrl = "";
  667. let datasourceName = "";
  668. let Fields = [];
  669. for (const layerData of this.layersDataUrl) {
  670. for (const datasource of layerData.datasources) {
  671. if (datasource.Name3D == param.primitive.name) {
  672. dataUrl = layerData.url;
  673. datasourceName = datasource.DataName;
  674. Fields = datasource.Fields;
  675. break;
  676. }
  677. }
  678. }
  679. let queryByIDParameters = {
  680. getFeatureMode: "ID",
  681. datasetNames: [datasourceName],
  682. ids: [param.id],
  683. hasGeometry: "false",
  684. };
  685. if (!dataUrl) {
  686. completed(null);
  687. } else {
  688. let e = await this.mapQuery(dataUrl, queryByIDParameters);
  689. if (completed) {
  690. completed(e, Fields);
  691. }
  692. }
  693. }
  694. },
  695. async mapQuery(url, queryObj) {
  696. let response = await axios.post(url, queryObj);
  697. if (response.data.featureCount > 0) {
  698. return response.data;
  699. } else {
  700. return null;
  701. }
  702. },
  703. convertCoordinates(coordArray) {
  704. return coordArray.map(coord => [coord.x, coord.y]);
  705. },
  706. // 取消左键点击查询
  707. removeMapLayerQuery() {
  708. this.queryResults = {};
  709. this.queryResultsGeom = {};
  710. this.queryResultsGeomPart = {};
  711. this.layerList = [];
  712. this.viewer.entities.removeAll();
  713. this.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
  714. this.handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  715. this.dataSourceLayer.entities.removeAll();
  716. this.viewer.dataSources.remove(this.dataSourceLayer);
  717. },
  718. /**
  719. * 笛卡尔坐标系转WGS84坐标系(经纬度)
  720. * @author
  721. * @param {object} point 点,笛卡尔坐标{x:x,y:y,z:z}
  722. * @returns {object} -lat: lat, lng: lng, alt: alt
  723. */
  724. cartesian3ToWGS84(point) {
  725. var cartesian3 = new Cesium.Cartesian3(point.x, point.y, point.z);
  726. var cartographic = Cesium.Cartographic.fromCartesian(cartesian3);
  727. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  728. var lng = Cesium.Math.toDegrees(cartographic.longitude);
  729. var alt = cartographic.height;
  730. return {
  731. lat: lat,
  732. lng: lng,
  733. alt: alt,
  734. };
  735. },
  736. /**
  737. * 墨卡托坐标系转WGS84坐标系(经纬度)
  738. * @author
  739. * @param number x
  740. * @param number y
  741. * @returns {object} x: x, y: y, z: z
  742. */
  743. cartesianToCartographic84(x, y) {
  744. let cartesian3InMercator = new Cesium.Cartesian3(x, y, 0);
  745. let mercator = new Cesium.WebMercatorProjection();
  746. let p = mercator.unproject(cartesian3InMercator);
  747. // 将墨卡托坐标转换为WGS84坐标
  748. // let cartesian3InWGS84 =
  749. // Cesium.Ellipsoid.WGS84.cartesianToCartographic(mercator.unproject(cartesian3InMercator));
  750. return {
  751. x: Cesium.Math.toDegrees(p.longitude),
  752. y: Cesium.Math.toDegrees(p.latitude),
  753. z: p.height,
  754. };
  755. },
  756. calcIserverURI(url) {
  757. let uriArr = url.split("/");
  758. uriArr[5] = uriArr[5].replace("map-", "data-");
  759. uriArr[7] = "data";
  760. uriArr[8] = "featureResults.rjson?returnContent=true";
  761. return uriArr.join("/");
  762. },
  763. remove_query_click() {
  764. for (var i = 0; i < 10; i++) {
  765. query_click.entities.values.forEach((res) => {
  766. query_click.entities.remove(res);
  767. })
  768. }
  769. },
  770. //地图数据查询事件
  771. changleQueryItem(item) {
  772. switch (item.index) {
  773. case 1: {
  774. this.mapQuerys("mapLayerQuery"); //图层点击事件
  775. this.remove_query_click();
  776. break;
  777. }
  778. case 2: {
  779. this.mapQuerys("mapModelQuery");
  780. break;
  781. }
  782. case 3: {
  783. this.removeMapLayerQuery(); //清除
  784. clearTranslate();
  785. pick_cockpit_vector.clear_data();//矢量拾取清除
  786. this.$refs.MultiLevelQuery.clear_data();//多级查询
  787. this.remove_query_click();
  788. break;
  789. }
  790. case 4: {//驾驶舱矢量数据点选查询
  791. pick_cockpit_vector.init_handler();
  792. break;
  793. } case 5: {//联级查询
  794. this.$refs.MultiLevelQuery.init_handler();
  795. break;
  796. }
  797. default:
  798. break;
  799. }
  800. },
  801. },
  802. beforeDestroy() {
  803. this.removeMapLayerQuery();
  804. clearTranslate();
  805. },
  806. };
  807. </script>
  808. <style>
  809. .sm-function-module-content-btn {
  810. text-align: center;
  811. padding-top: 5px;
  812. }
  813. .flyBtn2 {
  814. position: absolute;
  815. right: 47px;
  816. }
  817. .el-tabs__item {
  818. color: white !important;
  819. }
  820. .sm-function-module-content-tabs {
  821. height: 45px;
  822. padding: 1px 5px 0px 5px;
  823. /* margin-top: 4rem; */
  824. }
  825. .sm-function-module-content-table {
  826. height: 564px;
  827. overflow-y: auto;
  828. padding: 1px 5px 0px 5px;
  829. }
  830. .sm-function-module-query {
  831. /* padding: 5px 10px; */
  832. overflow: hidden;
  833. max-height: 700px;
  834. scrollbar-width: none;
  835. /* firefox */
  836. -ms-overflow-style: none;
  837. /* IE 10+ */
  838. @media (max-width: 1000px) {
  839. margin: 0.8rem 0;
  840. padding: 0 15px;
  841. }
  842. @media (max-width: 750px) {
  843. margin: 0.5rem 0;
  844. padding: 0 10px;
  845. max-height: 410px;
  846. }
  847. @media (max-height: 480px) {
  848. margin: 0.5rem 0;
  849. padding: 0 15px;
  850. max-height: 420px;
  851. max-width: 280px;
  852. }
  853. @media (max-height: 300px) {
  854. margin: 0.5rem 0;
  855. padding: 0 10px;
  856. max-height: 280px;
  857. max-width: 250px;
  858. }
  859. @media (max-height: 250px) {
  860. max-height: 240px;
  861. }
  862. }
  863. </style>
  864. <style lang="scss" scoped>
  865. @import "clickQuery";
  866. /deep/ .el-table tr {
  867. background: rgba(10, 25, 38, 0.5) !important;
  868. }
  869. /deep/ .el-table td.el-table__cell,
  870. .el-table th.el-table__cell.is-leaf {
  871. background: rgba(10, 25, 38, 0.5) !important;
  872. border-bottom: 1px solid #EBEEF5;
  873. }
  874. .el-table {
  875. color: #fff;
  876. background: rgba(10, 25, 38, 0.5) !important;
  877. }
  878. /deep/ .el-table__fixed-right::before,
  879. .el-table__fixed::before {
  880. background: rgba(10, 25, 38, 0.9) !important;
  881. }
  882. /deep/ .el-table__fixed-right-patch {
  883. background: rgba(10, 25, 38, 0.9) !important;
  884. }
  885. /deep/ .el-table--border::after,
  886. .el-table--group::after,
  887. .el-table::before {
  888. background: rgba(10, 25, 38, 0) !important;
  889. }
  890. </style>