clickQuery.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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 { Getfiledslist } from "@/api/shared.js";
  97. import { keys } from "lodash";
  98. import { handModel, handnew, clearTranslate, keyName } from "./modelLayering";
  99. import CockpitVector from "./CockpitVector.vue";
  100. import MultiLevelQuery from "./MultiLevelQuery.vue";
  101. import { loadGeoJSON, str2Unicode } from "@/utils/MapHelper/help.js";
  102. import * as pick_cockpit_vector from "./pick_cockpit_vector.js";
  103. import * as tdsy from "@/views/cockpit/js/tdsy";
  104. import * as turf from "@turf/turf";
  105. import { bbox } from "@/utils/MapHelper/help.js";
  106. let gwtype;
  107. let query_click = null;
  108. let manager_layer_png = null;
  109. let dataSourceLayer = null;
  110. export default {
  111. name: "clickQuery",
  112. components: { CockpitVector, MultiLevelQuery },
  113. data() {
  114. return {
  115. inited: false,
  116. activeLayerName: "",
  117. columns: [
  118. {
  119. title: "字段",
  120. key: "name",
  121. },
  122. {
  123. title: "值",
  124. key: "value",
  125. },
  126. ],
  127. layersDataUrl: window.layersDataUrl,
  128. layersData: [],
  129. layerList: [],
  130. loading: false,
  131. handler: {},
  132. activeNames: "查询结果1",
  133. activeLayerId: "",
  134. queryResults: {},
  135. queryResultsGeom: {},
  136. queryResultsGeomPart: {},
  137. viewer: null,
  138. // dataSourceLayer: null,
  139. actionOptions: [
  140. {
  141. index: 1,
  142. lable: "图层",
  143. iconName: "el-icon-tickets",
  144. isSelect: false,
  145. },
  146. {
  147. index: 6,
  148. lable: "框选",
  149. iconName: "el-icon-edit-outline",
  150. isSelect: false,
  151. },
  152. {
  153. index: 2,
  154. lable: "模型",
  155. iconName: "el-icon-office-building",
  156. isSelect: false,
  157. },
  158. // {
  159. // index: 4,
  160. // lable: "矢量",
  161. // iconName: "el-icon-picture",
  162. // isSelect: false,
  163. // },
  164. {
  165. index: 5,
  166. lable: "联级查询",
  167. iconName: "el-icon-c-scale-to-original",
  168. isSelect: false,
  169. },
  170. {
  171. index: 3,
  172. lable: "清除",
  173. iconName: "el-icon-delete",
  174. isSelect: false,
  175. },
  176. ],
  177. };
  178. },
  179. computed: {
  180. PoinyQueryShow: function () {
  181. return store.state.toolBar[9];
  182. },
  183. vectorShow: function () {
  184. return store.state.cockpit_vector.title ||
  185. store.state.cockpit_vector.goitem
  186. ? !store.state.viewer_flag
  187. : true;
  188. },
  189. },
  190. created() {},
  191. watch: {
  192. activeLayerId(val) {
  193. if (val && val != "0") {
  194. for (let i = 0; i < store.state.vectorlayerlist.length; i++) {
  195. let obj = store.state.vectorlayerlist[i];
  196. if (obj.id == val) {
  197. if (obj.serverType == "geoserver") {
  198. this.removeGeoJSON();
  199. this.addGeoJson("#0000ff");
  200. } else {
  201. this.addGeometrys(obj.type == "S3M");
  202. }
  203. break;
  204. }
  205. }
  206. }
  207. },
  208. PoinyQueryShow(val) {
  209. if (!this.inited) {
  210. this.inited = !this.inited;
  211. viewer.entities.removeAll();
  212. this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  213. dataSourceLayer = new Cesium.CustomDataSource("query");
  214. viewer.dataSources.add(dataSourceLayer);
  215. }
  216. },
  217. },
  218. mounted() {
  219. console.log(str2Unicode(`fid_城镇`));
  220. this.$nextTick((res) => {
  221. query_click = new Cesium.CustomDataSource("query_click");
  222. viewer.dataSources.add(query_click);
  223. manager_layer_png = new Cesium.CustomDataSource("manager_layer_png");
  224. viewer.dataSources.add(manager_layer_png);
  225. });
  226. },
  227. methods: {
  228. isArray2D(arr) {
  229. // 首先检查arr是否是数组
  230. if (!Array.isArray(arr)) {
  231. return false;
  232. }
  233. // 检查数组中的每个元素是否也是数组
  234. for (let i = 0; i < arr.length; i++) {
  235. if (!Array.isArray(arr[i])) {
  236. return false;
  237. }
  238. }
  239. // 如果所有元素都是数组,那么arr是二维数组
  240. return true;
  241. },
  242. toggleVisibility() {
  243. this.removeMapLayerQuery();
  244. this.remove_query_click();
  245. this.removeGeoJSON();
  246. store.setToolBarAction(9);
  247. tdsy.remove(false);
  248. },
  249. addGeometrys(fill) {
  250. viewer.entities.removeAll();
  251. dataSourceLayer.entities.removeAll();
  252. let geoms = this.queryResultsGeom[this.activeLayerId];
  253. let parts = this.queryResultsGeomPart[this.activeLayerId];
  254. for (let i = 0; i < geoms.length; i++) {
  255. let cur = geoms[i];
  256. let part = parts[i];
  257. let start = 0;
  258. let end = 0;
  259. for (let k = 0; k < part.length; k++) {
  260. let points = [];
  261. if (k > 0) {
  262. start += part[k - 1];
  263. }
  264. end += part[k];
  265. for (let j = start; j < end; j++) {
  266. let cx = cur[j][0];
  267. let cy = cur[j][1];
  268. points.push(cx);
  269. points.push(cy);
  270. }
  271. if (fill) {
  272. viewer.entities.add({
  273. polyline: new Cesium.PolylineGraphics({
  274. positions: Cesium.Cartesian3.fromDegreesArray(points),
  275. width: 3,
  276. material: Cesium.Color.BLUE.withAlpha(0.9),
  277. clampToGround: true,
  278. }),
  279. polygon: {
  280. //高程
  281. hierarchy: new Cesium.PolygonHierarchy(
  282. Cesium.Cartesian3.fromDegreesArray(points)
  283. ),
  284. classificationType: Cesium.ClassificationType.BOTH,
  285. clampToGround: false,
  286. material: Cesium.Color.RED.withAlpha(0.3),
  287. // material: videoElement,
  288. // perPositionHeight: true
  289. },
  290. });
  291. } else {
  292. viewer.entities.add({
  293. polyline: new Cesium.PolylineGraphics({
  294. positions: Cesium.Cartesian3.fromDegreesArray(points),
  295. width: 3,
  296. material: Cesium.Color.BLUE.withAlpha(0.9),
  297. clampToGround: true,
  298. }),
  299. });
  300. }
  301. }
  302. // viewer.flyTo(viewer.entities);
  303. }
  304. },
  305. flyTo(index) {
  306. let geoms = this.queryResultsGeom[this.activeLayerId];
  307. let cur = geoms[index];
  308. if (cur) {
  309. if (cur.type) {
  310. this.removeGeoJSON();
  311. loadGeoJSON(
  312. cur,
  313. "#ff0000",
  314. { isfly: true, fill_a: 0.6, sw: 5 },
  315. (data) => (data.name = "geoserver")
  316. );
  317. } else {
  318. this.flyToSuperMap(cur);
  319. }
  320. } else {
  321. this.$message({
  322. message: "空间范围为空!",
  323. type: "warning",
  324. });
  325. }
  326. },
  327. addGeoJson() {
  328. let geoms = this.queryResultsGeom[this.activeLayerId];
  329. geoms.forEach((geom) => {
  330. loadGeoJSON(
  331. geom,
  332. "#0000ff",
  333. { fill_a: 0.6, sw: 5 },
  334. (data) => (data.name = "geoserver")
  335. );
  336. });
  337. },
  338. removeGeoJSON() {
  339. viewer.entities.removeAll();
  340. viewer.dataSources._dataSources.forEach((das) => {
  341. if (das.name == "geoserver") viewer.dataSources.remove(das);
  342. });
  343. },
  344. flyToSuperMap(cur) {
  345. dataSourceLayer.entities.removeAll();
  346. let parts = this.queryResultsGeomPart[this.activeLayerId];
  347. let part = parts[index];
  348. let start = 0;
  349. let end = 0;
  350. for (let k = 0; k < part.length; k++) {
  351. let points = [];
  352. if (k > 0) {
  353. start += part[k - 1];
  354. }
  355. end += part[k];
  356. for (let j = start; j < end; j++) {
  357. let cx = cur[j][0];
  358. let cy = cur[j][1];
  359. points.push(cx);
  360. points.push(cy);
  361. }
  362. // let e = dataSourceLayer.entities.
  363. let e = viewer.entities.add({
  364. polyline: new Cesium.PolylineGraphics({
  365. positions: Cesium.Cartesian3.fromDegreesArray(points),
  366. width: 3,
  367. material: Cesium.Color.RED.withAlpha(0.9),
  368. clampToGround: true,
  369. }),
  370. });
  371. viewer.flyTo(e);
  372. }
  373. },
  374. handleTabClick(item, a) {
  375. this.activeLayerId = item.name;
  376. },
  377. // 设置数据
  378. setData() {
  379. dataSourceLayer = new Cesium.CustomDataSource("query");
  380. viewer.dataSources.add(dataSourceLayer);
  381. this.activeLayerId = "0";
  382. this.queryResults = {};
  383. this.queryResultsGeom = {};
  384. this.queryResultsGeomPart = {};
  385. },
  386. /**
  387. * 左键点击查询图层
  388. */
  389. async mapLayerQuery(movement) {
  390. let that = this;
  391. that.activeLayerId = "0";
  392. that.layerList = [];
  393. that.layersData = [];
  394. this.remove_query_click();
  395. let scene = viewer.scene;
  396. viewer.entities.removeAll();
  397. dataSourceLayer.entities.removeAll();
  398. this.removeGeoJSON();
  399. //拾取模型
  400. let pickedFeature = scene.pick(movement.position);
  401. if (
  402. scene.pickPositionSupported &&
  403. Cesium.defined(pickedFeature) &&
  404. pickedFeature != null &&
  405. pickedFeature.primitive
  406. ) {
  407. this.pickClick(pickedFeature);
  408. } else {
  409. this.pickPosition(movement);
  410. }
  411. },
  412. mapSelect(movement) {
  413. console.log(window.tempSelect, "window.tempSelect");
  414. this.drawPolygon(window.tempSelect);
  415. // //拾取模型
  416. // let pickedFeature = viewer.scene.pick(movement.position);
  417. // console.log(pickedFeature, "pickedFeature");
  418. },
  419. async pickClick(pickedFeature) {
  420. let that = this;
  421. let eneityName = pickedFeature.primitive.name;
  422. let Pid = "";
  423. var tempArr = [];
  424. // "ResultNetWork@管线#1"///"ResultNetWork_Node@管线#1"
  425. if (eneityName.indexOf("雨水") > -1 || eneityName.indexOf("管线") > -1) {
  426. // for (let i = 0; i < store.state.vectorlayerlist.length; i++) {
  427. // let obj = store.state.vectorlayerlist[i];
  428. // console.log(obj.url,'url----------',obj);
  429. let str1 = eneityName.match(/@(\S*)#/)[1];
  430. let str2 = eneityName.match(/(\S*)@/)[1];
  431. let str3 = str1 + ":" + str2;
  432. // let obj = store.state.vectorlayerlist.find(i => i.title == str1);
  433. let obj = store.state.vectorlayerlist.find((i) => {
  434. return str1 == i.title;
  435. });
  436. let url1 = obj.url.replace("3D-", "data-");
  437. let url2 = url1.replace(
  438. "realspace",
  439. "data/featureResults.rjson?returnContent=true"
  440. );
  441. let queryByIDParameters = {
  442. getFeatureMode: "ID",
  443. datasetNames: [str3],
  444. ids: [pickedFeature.id],
  445. };
  446. let e = await this.mapQuery(url2, queryByIDParameters);
  447. if (e && e.totalCount > 0) {
  448. // that.layerList.push(store.state.vectorlayerlist[i]);
  449. that.layerList.push(obj);
  450. for (let u = 0; u < e.features.length; u++) {
  451. let cur = [];
  452. var linSAr = JSON.parse(JSON.stringify(e.features[u]));
  453. if (e.features[u].fieldNames) {
  454. linSAr.fieldNames.forEach((fieldName, i) => {
  455. let v = linSAr.fieldValues[i];
  456. if (v != "" && !isNaN(parseFloat(v))) {
  457. v = Math.round(parseFloat(v) * 100) / 100;
  458. }
  459. // cur.push({ name: fieldName, value: v });
  460. if (
  461. fieldName.toLowerCase().indexOf("shape") < 0 &&
  462. fieldName.toLowerCase().indexOf("sm") &&
  463. v != ""
  464. ) {
  465. cur.push({ name: fieldName, value: v });
  466. }
  467. });
  468. //获取图层id的参数
  469. let substring = pickedFeature.primitive._baseUri.query;
  470. for (let p = 0; p < store.state.vectorlayerlist.length; p++) {
  471. if (store.state.vectorlayerlist[p].id == substring) {
  472. that.layerList.push(store.state.vectorlayerlist[p]);
  473. break;
  474. }
  475. }
  476. that.queryResults[substring] = [cur];
  477. that.queryResultsGeom[substring] = [];
  478. that.activeLayerId = substring;
  479. } else {
  480. that.$message({
  481. message: "查询结果为空!",
  482. type: "warning",
  483. customClass: "messageIndex",
  484. });
  485. }
  486. }
  487. }
  488. // }
  489. }
  490. that.loading = true;
  491. that.queryByPickFeature(pickedFeature, function (result, Fields) {
  492. that.loading = false;
  493. if (result != null && result.features[0].fieldNames) {
  494. result.features[0].fieldNames.forEach((fieldName, i) => {
  495. const Field = Fields.find((c) => c.FieldEn == fieldName);
  496. let v = result.features[0].fieldValues[i];
  497. if (!isNaN(parseFloat(v))) {
  498. v = Math.round(parseFloat(v) * 100) / 100;
  499. }
  500. that.layersData.push({
  501. label: Field ? Field.FieldCn : fieldName,
  502. value: v,
  503. });
  504. });
  505. } else {
  506. that.layersData = [];
  507. }
  508. });
  509. },
  510. pickPosition(movement) {
  511. //拾取图层
  512. // let pickRay = viewer.camera.getPickRay(movement.position);
  513. // let artesian3 = viewer.scene.globe.pick(pickRay, viewer.scene);
  514. let artesian3 = viewer.scene.pickPosition(movement.position);
  515. let xy = this.cartesian3ToWGS84(artesian3);
  516. //TODO wanger 分图层查询
  517. for (let i = 0; i < store.state.vectorlayerlist.length; i++) {
  518. let obj = store.state.vectorlayerlist[i];
  519. // 结果高亮
  520. this.highlightResultsPng(xy.lng, xy.lat);
  521. if (obj.serverType == "geoserver") {
  522. this.getGeoserver(xy, obj);
  523. } else {
  524. if (!obj.fwgzkj && !obj.fwmc) {
  525. continue;
  526. }
  527. this.superQuery(xy, obj);
  528. }
  529. }
  530. },
  531. async getfieldList(zymlBsm, resetType) {
  532. this.fieldList = [];
  533. let res = await Getfiledslist({ zymlBsm, resetType });
  534. return res.data;
  535. },
  536. async superQuery(xy, obj) {
  537. console.log(
  538. obj.source.split(","),
  539. `${obj.fwgzkj}:${obj.fwmc}`,
  540. obj.source.split(",") == `${obj.fwgzkj}:${obj.fwmc}`
  541. );
  542. let that = this;
  543. let queryByIDParameters = {
  544. getFeatureMode: "BUFFER",
  545. // getFeatureMode: "SPATIAL",
  546. spatialQueryMode: "INTERSECT",
  547. datasetNames: [`${obj.fwgzkj}:${obj.fwmc}`], //obj.source.split(","),
  548. geometry: {
  549. parts: [1],
  550. points: [{ y: xy.lat, x: xy.lng }],
  551. type: "POINT",
  552. },
  553. bufferDistance: 0.00005,
  554. hasGeometry: true,
  555. };
  556. let e;
  557. if (obj.type == "S3M") {
  558. e = await that.mapQuery(
  559. window.baseModelQueryLayer,
  560. queryByIDParameters
  561. );
  562. } else {
  563. e = await that.mapQuery(
  564. that.calcIserverURI(obj.url),
  565. queryByIDParameters
  566. );
  567. }
  568. if (e && e.totalCount > 0) {
  569. this.addLayerList(obj.title, obj);
  570. let queryData = [];
  571. let geoms = [];
  572. let parts = [];
  573. // let parseJson = JSON.parse(obj.legend);
  574. let parseJson = await this.getfieldList(obj.id, false);
  575. for (let u = 0; u < e.features.length; u++) {
  576. let cur = [];
  577. var linSAr = JSON.parse(JSON.stringify(e.features[u]));
  578. function condition(ci) {
  579. return ci.status != undefined && ci.status;
  580. }
  581. if (e.features[u].fieldNames) {
  582. linSAr.fieldNames.forEach((fieldName, i) => {
  583. let perjson = parseJson.filter(
  584. (p) => p.filedName.toUpperCase() == fieldName
  585. );
  586. if (perjson.length > 0) {
  587. var show = condition(perjson[0]);
  588. var order = perjson[0].order || linSAr.fieldNames.length;
  589. if (fieldName != perjson[0].filedNameZh)
  590. fieldName = perjson[0].filedNameZh;
  591. }
  592. if (show) {
  593. let v = linSAr.fieldValues[i];
  594. if (v != "" && !isNaN(parseFloat(v))) {
  595. v = Math.round(parseFloat(v) * 100) / 100;
  596. }
  597. cur.push({ name: fieldName, value: v, order });
  598. }
  599. });
  600. } else {
  601. that.$message({
  602. message: "查询结果为空!",
  603. type: "warning",
  604. customClass: "messageIndex",
  605. });
  606. }
  607. //排序
  608. cur.sort((a, b) => a.order - b.order);
  609. let urlNew = obj.url + ".json";
  610. let resNew = await axios.get(urlNew);
  611. let serCode = resNew.data.prjCoordSys.epsgCode;
  612. let points = [];
  613. for (let y = 0; y < e.features[u].geometry.points.length; y++) {
  614. let c = {};
  615. if (serCode == 3857) {
  616. c = that.cartesianToCartographic84(
  617. e.features[u].geometry.points[y].x,
  618. e.features[u].geometry.points[y].y
  619. );
  620. } else {
  621. c = e.features[u].geometry.points[y];
  622. }
  623. points.push([c.x, c.y]);
  624. }
  625. parts.push(e.features[u].geometry.parts);
  626. geoms.push(points);
  627. queryData.push(cur);
  628. }
  629. that.queryResultsGeomPart[obj.id] = parts;
  630. that.queryResults[obj.id] = queryData;
  631. that.queryResultsGeom[obj.id] = geoms;
  632. }
  633. this.setactiveLayerId();
  634. },
  635. setactiveLayerId() {
  636. if (this.layerList.length > 0) {
  637. this.activeLayerId = this.layerList[0].id;
  638. } else {
  639. this.$message({
  640. message: "查询结果为空!",
  641. type: "warning",
  642. customClass: "messageIndex",
  643. });
  644. }
  645. },
  646. async getGeoserver(xy, obj) {
  647. this.queryResults[obj.id] = [];
  648. this.queryResultsGeom[obj.id] = [];
  649. let ind =
  650. obj.url.indexOf("geoserver") >= 0
  651. ? obj.url.indexOf("geoserver")
  652. : obj.url.indexOf("siweiserver");
  653. let url = obj.url.substring(0, ind + 9) + "/ows";
  654. let pointml = `<gml:Point srsName='EPSG:4326'><gml:coordinates>
  655. ${xy.lng},${xy.lat}</gml:coordinates></gml:Point>`;
  656. let polygonml = `<gml:Polygon srsName="EPSG:4326">
  657. <gml:outerBoundaryIs>
  658. <gml:LinearRing>
  659. <gml:coordinates> ${xy.points} </gml:coordinates>
  660. </gml:LinearRing>
  661. </gml:outerBoundaryIs>
  662. </gml:Polygon>`;
  663. let params = {
  664. service: "WFS",
  665. version: "1.0.0",
  666. request: "GetFeature",
  667. typeName: `${obj.fwgzkj}:${obj.fwmc}`,
  668. outputFormat: "application/json",
  669. srsName: "EPSG:4326",
  670. filter: `<Filter xmlns='http://www.opengis.net/ogc' xmlns:gml='http://www.opengis.net/gml'><Intersects><PropertyName>geom</PropertyName> ${
  671. xy.lng ? pointml : polygonml
  672. }</Intersects></Filter>`,
  673. };
  674. console.log("----", params);
  675. let res = await axios.get(url, { params });
  676. if (res.data && res.data.features && res.data.features.length > 0) {
  677. this.addLayerList(obj.title, obj);
  678. res.data.features.forEach((feitem) => {
  679. let cur = [];
  680. Object.keys(feitem.properties).forEach((key) => {
  681. cur.push({ name: key, value: feitem.properties[key] });
  682. });
  683. this.queryResults[obj.id].push(cur);
  684. this.queryResultsGeom[obj.id].push(feitem.geometry);
  685. });
  686. } else {
  687. this.$message({
  688. message: "查询结果为空!",
  689. type: "warning",
  690. customClass: "messageIndex",
  691. });
  692. }
  693. this.setactiveLayerId();
  694. },
  695. highlightResultsPng(longitude, latitude) {
  696. manager_layer_png.entities.add({
  697. name: "manager_layer_png",
  698. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  699. billboard: {
  700. // 图像地址,URI或Canvas的属性
  701. image: "./static/images/overview/go.png",
  702. height: 34,
  703. width: 36,
  704. scale: 1.0,
  705. zIndex: 2,
  706. show: true,
  707. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  708. },
  709. });
  710. },
  711. addLayerList(label, obj) {
  712. if (this.layerList.findIndex((a) => a.label == label) >= 0) return;
  713. if (obj) {
  714. this.layerList.push(obj);
  715. } else {
  716. let layers = store.state.vectorlayerlist.filter(
  717. (element) => element.label === label
  718. );
  719. if (layers.length > 0) {
  720. this.activeLayerId = layers[0].id;
  721. this.layerList.push(layers[0]);
  722. }
  723. }
  724. },
  725. /**
  726. * 左键点击模型查询
  727. */
  728. mapModelQuery(movement) {
  729. this.activeLayerId = "0";
  730. this.layerList = [];
  731. this.layersData = [];
  732. viewer.entities.removeAll();
  733. dataSourceLayer.entities.removeAll();
  734. this.removeGeoJSON();
  735. let title;
  736. if (store.state.checkedData) title = store.state.checkedData.title;
  737. // 超图分层分户
  738. if (title == "分层分户" || title == "8号楼-谷") {
  739. let id = handModel(movement);
  740. } else {
  741. handnew(movement);
  742. }
  743. let newArr = [];
  744. GetHouseInfo({ id: "2c01647f-4533-4472-b20b-f5caa4c705b0" }).then(
  745. (res) => {
  746. for (const [key, value] of Object.entries(res.data)) {
  747. newArr.push({ name: keyName[key], value: value });
  748. }
  749. this.addLayerList(title);
  750. this.queryResults[this.activeLayerId] = [newArr];
  751. this.queryResultsGeom[this.activeLayerId] = [];
  752. }
  753. );
  754. },
  755. mapQuerys(queryName) {
  756. this.setData();
  757. let that = this;
  758. this.handler.setInputAction(function (movement) {
  759. that[queryName](movement);
  760. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  761. this.handler.setInputAction(function () {
  762. that.removeMapLayerQuery();
  763. clearTranslate();
  764. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  765. },
  766. /**
  767. * 超图
  768. * 根据返回的三维对象查询数据信息
  769. *
  770. * @param {*} param
  771. */
  772. async queryByPickFeature(param, completed) {
  773. if (param.primitive) {
  774. let dataUrl = "";
  775. let datasourceName = "";
  776. let Fields = [];
  777. for (const layerData of this.layersDataUrl) {
  778. for (const datasource of layerData.datasources) {
  779. if (datasource.Name3D == param.primitive.name) {
  780. dataUrl = layerData.url;
  781. datasourceName = datasource.DataName;
  782. Fields = datasource.Fields;
  783. break;
  784. }
  785. }
  786. }
  787. let queryByIDParameters = {
  788. getFeatureMode: "ID",
  789. datasetNames: [datasourceName],
  790. ids: [param.id],
  791. hasGeometry: "false",
  792. };
  793. if (!dataUrl) {
  794. completed(null);
  795. } else {
  796. let e = await this.mapQuery(dataUrl, queryByIDParameters);
  797. if (completed) {
  798. completed(e, Fields);
  799. }
  800. }
  801. }
  802. },
  803. async mapQuery(url, queryObj) {
  804. let response = await axios.post(url, queryObj);
  805. if (response.data.featureCount > 0) {
  806. return response.data;
  807. } else {
  808. return null;
  809. }
  810. },
  811. convertCoordinates(coordArray) {
  812. return coordArray.map((coord) => [coord.x, coord.y]);
  813. },
  814. // 取消左键点击查询
  815. removeMapLayerQuery() {
  816. this.queryResults = {};
  817. this.queryResultsGeom = {};
  818. this.queryResultsGeomPart = {};
  819. this.layerList = [];
  820. viewer.entities.removeAll();
  821. if (this.handler.removeInputAction) {
  822. this.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
  823. this.handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  824. }
  825. dataSourceLayer.entities.removeAll();
  826. this.removeGeoJSON();
  827. viewer.dataSources.remove(dataSourceLayer);
  828. },
  829. /**
  830. * 笛卡尔坐标系转WGS84坐标系(经纬度)
  831. * @author
  832. * @param {object} point 点,笛卡尔坐标{x:x,y:y,z:z}
  833. * @returns {object} -lat: lat, lng: lng, alt: alt
  834. */
  835. cartesian3ToWGS84(point) {
  836. var cartesian3 = new Cesium.Cartesian3(point.x, point.y, point.z);
  837. var cartographic = Cesium.Cartographic.fromCartesian(cartesian3);
  838. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  839. var lng = Cesium.Math.toDegrees(cartographic.longitude);
  840. var alt = cartographic.height;
  841. return {
  842. lat: lat,
  843. lng: lng,
  844. alt: alt,
  845. };
  846. },
  847. /**
  848. * 墨卡托坐标系转WGS84坐标系(经纬度)
  849. * @author
  850. * @param number x
  851. * @param number y
  852. * @returns {object} x: x, y: y, z: z
  853. */
  854. cartesianToCartographic84(x, y) {
  855. let cartesian3InMercator = new Cesium.Cartesian3(x, y, 0);
  856. let mercator = new Cesium.WebMercatorProjection();
  857. let p = mercator.unproject(cartesian3InMercator);
  858. // 将墨卡托坐标转换为WGS84坐标
  859. // let cartesian3InWGS84 =
  860. // Cesium.Ellipsoid.WGS84.cartesianToCartographic(mercator.unproject(cartesian3InMercator));
  861. return {
  862. x: Cesium.Math.toDegrees(p.longitude),
  863. y: Cesium.Math.toDegrees(p.latitude),
  864. z: p.height,
  865. };
  866. },
  867. calcIserverURI(url) {
  868. let uriArr = url.split("/");
  869. uriArr[5] = uriArr[5].replace("map-", "data-");
  870. uriArr[7] = "data";
  871. uriArr[8] = "featureResults.rjson?returnContent=true";
  872. return uriArr.join("/");
  873. },
  874. remove_query_click() {
  875. for (var i = 0; i < 10; i++) {
  876. query_click.entities.values.forEach((res) => {
  877. query_click.entities.remove(res);
  878. });
  879. }
  880. // 图标
  881. var entities = manager_layer_png.entities.values;
  882. for (var i = entities.length - 1; i >= 0; i--) {
  883. manager_layer_png.entities.remove(entities[i]);
  884. }
  885. },
  886. //地图数据查询事件
  887. changleQueryItem(item) {
  888. switch (item.index) {
  889. case 1: {
  890. this.mapQuerys("mapLayerQuery"); //图层点击事件
  891. this.remove_query_click();
  892. viewer.entities.removeAll();
  893. // common.clearHandlerDrawing("Polygon");
  894. break;
  895. }
  896. case 2: {
  897. this.mapQuerys("mapModelQuery");
  898. break;
  899. }
  900. case 3: {
  901. this.removeMapLayerQuery(); //清除
  902. clearTranslate();
  903. // pick_cockpit_vector.clear_data(); //矢量拾取清除
  904. this.$refs.MultiLevelQuery.clear_data(); //多级查询
  905. this.remove_query_click();
  906. break;
  907. }
  908. case 4: {
  909. //驾驶舱矢量数据点选查询
  910. // pick_cockpit_vector.init_handler();
  911. break;
  912. }
  913. case 5: {
  914. //联级查询
  915. this.$refs.MultiLevelQuery.init_handler();
  916. break;
  917. }
  918. case 6: {
  919. //联级查询
  920. // this.$refs.MultiLevelQuery.init_handler();
  921. this.drawMap();
  922. console.log("框选事件");
  923. break;
  924. }
  925. default:
  926. break;
  927. }
  928. },
  929. //绘制
  930. drawMap() {
  931. if (!window.handlerPolygon) {
  932. common.initHandler("Polygon");
  933. }
  934. common.handlerDrawing("Polygon").then(
  935. (res) => {
  936. store.state.vectorlayerlist.forEach((obj) => {
  937. if (obj.serverType == "geoserver") {
  938. let points = "";
  939. res.positions.forEach((item, index) => {
  940. if ((index + 1) % 3 == 1) points += item + ",";
  941. if ((index + 1) % 3 == 2) points += item + " ";
  942. });
  943. points += res.positions[0] + ",";
  944. points += res.positions[1] + " ";
  945. this.getGeoserver({ points }, obj);
  946. } else {
  947. // if (!obj.fwgzkj && !obj.fwmc) {
  948. // continue;
  949. // }
  950. // this.superQuery(xy, obj);
  951. }
  952. });
  953. },
  954. (err) => {
  955. console.log(err);
  956. }
  957. );
  958. window.handlerPolygon.activate();
  959. },
  960. },
  961. beforeDestroy() {
  962. this.removeMapLayerQuery();
  963. clearTranslate();
  964. },
  965. };
  966. </script>
  967. <style>
  968. .sm-function-module-content-btn {
  969. text-align: center;
  970. padding-top: 5px;
  971. }
  972. .flyBtn2 {
  973. position: absolute;
  974. right: 47px;
  975. }
  976. .el-tabs__item {
  977. color: white !important;
  978. }
  979. .sm-function-module-content-tabs {
  980. height: 45px;
  981. padding: 1px 5px 0px 5px;
  982. /* margin-top: 4rem; */
  983. }
  984. .sm-function-module-content-table {
  985. height: 564px;
  986. overflow-y: auto;
  987. padding: 1px 5px 0px 5px;
  988. }
  989. .sm-function-module-query {
  990. /* padding: 5px 10px; */
  991. overflow: hidden;
  992. max-height: 700px;
  993. scrollbar-width: none;
  994. /* firefox */
  995. -ms-overflow-style: none;
  996. /* IE 10+ */
  997. @media (max-width: 1000px) {
  998. margin: 0.8rem 0;
  999. padding: 0 15px;
  1000. }
  1001. @media (max-width: 750px) {
  1002. margin: 0.5rem 0;
  1003. padding: 0 10px;
  1004. max-height: 410px;
  1005. }
  1006. @media (max-height: 480px) {
  1007. margin: 0.5rem 0;
  1008. padding: 0 15px;
  1009. max-height: 420px;
  1010. max-width: 280px;
  1011. }
  1012. @media (max-height: 300px) {
  1013. margin: 0.5rem 0;
  1014. padding: 0 10px;
  1015. max-height: 280px;
  1016. max-width: 250px;
  1017. }
  1018. @media (max-height: 250px) {
  1019. max-height: 240px;
  1020. }
  1021. }
  1022. </style>
  1023. <style lang="scss" scoped>
  1024. @import "clickQuery";
  1025. /deep/ .el-table tr {
  1026. background: rgba(10, 25, 38, 0.5) !important;
  1027. }
  1028. /deep/ .el-table td.el-table__cell,
  1029. .el-table th.el-table__cell.is-leaf {
  1030. background: rgba(10, 25, 38, 0.5) !important;
  1031. border-bottom: 1px solid #ebeef5;
  1032. }
  1033. .el-table {
  1034. color: #fff;
  1035. background: rgba(10, 25, 38, 0.5) !important;
  1036. }
  1037. /deep/ .el-table__fixed-right::before,
  1038. .el-table__fixed::before {
  1039. background: rgba(10, 25, 38, 0.9) !important;
  1040. }
  1041. /deep/ .el-table__fixed-right-patch {
  1042. background: rgba(10, 25, 38, 0.9) !important;
  1043. }
  1044. /deep/ .el-table--border::after,
  1045. .el-table--group::after,
  1046. .el-table::before {
  1047. background: rgba(10, 25, 38, 0) !important;
  1048. }
  1049. /deep/ .el-collapse-item__header {
  1050. background-color: transparent !important;
  1051. color: rgb(217, 237, 254) !important;
  1052. }
  1053. /deep/ .el-collapse {
  1054. border: none;
  1055. /* border-top: 1px solid #EBEEF5; */
  1056. /* border-bottom: 1px solid #EBEEF5; */
  1057. }
  1058. /deep/ .el-collapse-item__content {
  1059. padding-bottom: 0px;
  1060. }
  1061. </style>