clickQuery.vue 32 KB

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