range-version.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <div class="map-range">
  3. <div class="fwlxrange">
  4. <div :class="model.xzmj == 0 ? 'pointer' : ''" @click="drawMap">
  5. <el-button plain icon="edit-pen" size="mini">绘制</el-button>
  6. </div>
  7. <el-upload
  8. class="upload-demo"
  9. :on-change="handleChange"
  10. :auto-upload="false"
  11. :show-file-list="false"
  12. :file-list="fileList"
  13. :limit="1"
  14. accept=".zip"
  15. >
  16. <el-button class="upload-btn" icon="Upload" size="mini">导入</el-button>
  17. </el-upload>
  18. <!-- <div class="clear" @click="clearAll">清除</div> -->
  19. <div>
  20. <el-button size="mini" @click="changePatches">选择图斑</el-button>
  21. </div>
  22. <div>
  23. <el-button size="mini" @click="clearAll">清除</el-button>
  24. </div>
  25. </div>
  26. <div v-if="type != 'cutfill'">
  27. <span v-if="model.xzmj != 0">{{ model.xzmj }} 亩</span>
  28. <el-tooltip
  29. v-if="fileList.length > 0"
  30. :content="fileList[0].name"
  31. placement="bottom-start"
  32. >
  33. <span class="title-item" style="display: inline-block; width: 100%">{{
  34. fileList[0].name
  35. }}</span>
  36. </el-tooltip>
  37. </div>
  38. <el-dialog
  39. title="选择图斑"
  40. :visible.sync="dialogVisible"
  41. width="30%"
  42. :before-close="handleClose"
  43. :modal-append-to-body="false"
  44. :close-on-click-modal="false"
  45. >
  46. <div class="gdzl">
  47. <div class="el-col headerSelect">
  48. <el-select
  49. v-model="yearsVal"
  50. placeholder="请选择"
  51. @change="yearsChange"
  52. size="mini"
  53. >
  54. <el-option
  55. v-for="item in yearsOpt"
  56. :key="item.quarter"
  57. :label="item.quarter"
  58. :value="item"
  59. >
  60. </el-option>
  61. </el-select>
  62. <el-cascader
  63. v-model="updateObj.region"
  64. :show-all-levels="false"
  65. :options="store.state.region_tree"
  66. @change="regionChange1"
  67. placeholder="行政区"
  68. size="mini"
  69. :props="{
  70. checkStrictly: true,
  71. expandTrigger: 'hover',
  72. emitPath: false,
  73. }"
  74. ></el-cascader>
  75. <el-select
  76. v-model="monitorVal"
  77. placeholder="请选择"
  78. @change="typeChange"
  79. clearable
  80. size="mini"
  81. >
  82. <el-option
  83. v-for="item in monitorOpt"
  84. :key="item.dictCode"
  85. :label="item.dictValue"
  86. :value="item.dictLabel"
  87. >
  88. </el-option>
  89. </el-select>
  90. </div>
  91. <div class="el-col headerInp">
  92. <el-input
  93. v-model="input"
  94. placeholder="请输入监测编号搜索"
  95. @keyup.enter.native="initNew"
  96. ></el-input>
  97. <el-button plain icon="edit-pen" size="mini">查询</el-button>
  98. </div>
  99. <el-table
  100. ref="singleTable"
  101. :data="active_dableData"
  102. style="width: 100%"
  103. height="44vh"
  104. @selection-change="handleSelectionChange"
  105. :header-cell-style="{
  106. background: 'rgba(10, 25, 38, 0.6)',
  107. color: '#66b1ff',
  108. fontSize: '14px',
  109. fontFamily: 'Microsoft YaHei',
  110. fontWeight: '400',
  111. }"
  112. >
  113. <el-table-column type="selection" width="55"> </el-table-column>
  114. <el-table-column type="index" align="center" width="50">
  115. </el-table-column>
  116. <el-table-column
  117. prop="jcbh"
  118. label="监测编号"
  119. align="center"
  120. width="220"
  121. show-overflow-tooltip
  122. >
  123. </el-table-column>
  124. <el-table-column
  125. prop="jcmj"
  126. label="监测面积(亩)"
  127. align="center"
  128. show-overflow-tooltip
  129. >
  130. </el-table-column>
  131. <!-- <el-table-column
  132. prop="regioncode"
  133. label="地区编号"
  134. align="center"
  135. show-overflow-tooltip
  136. >
  137. </el-table-column>
  138. <el-table-column
  139. prop="xmc"
  140. label="所属区县"
  141. align="center"
  142. show-overflow-tooltip
  143. >
  144. </el-table-column> -->
  145. <!-- <el-table-column fixed="right" label="操作" width="90" align="center">
  146. <template slot-scope="scope">
  147. <el-button
  148. @click="handleClick(scope.row)"
  149. type="text"
  150. size="small"
  151. >定位</el-button
  152. >
  153. <el-button
  154. type="text"
  155. size="small"
  156. @click="handleDetails(scope.row)"
  157. >详情</el-button
  158. >
  159. </template>
  160. </el-table-column> -->
  161. </el-table>
  162. </div>
  163. <span slot="footer" class="dialog-footer">
  164. <el-button @click="dialogVisible = false">取 消</el-button>
  165. <el-button type="primary" @click="creatTb">确 定</el-button>
  166. </span>
  167. </el-dialog>
  168. </div>
  169. </template>
  170. <script>
  171. import { ShapeUpload, ShapeUploadV1 } from "@/api/ghss/hgxfx.js";
  172. import { ElMessage } from "element-ui";
  173. import { GetXzqhTree } from "@/api/map";
  174. import {
  175. GetDateList,
  176. CodeList,
  177. JscQueryList,
  178. JctbList,
  179. getJctbInfo,
  180. } from "@/api/ghss/jctb.js";
  181. // import { polygon } from "@turf/turf";
  182. import * as turf from "@turf/turf";
  183. import parse from "wellknown";
  184. import { loadGeoJSON } from "@/utils/MapHelper/help.js";
  185. let now_dataSources = null;
  186. let layerSources = {};
  187. export default {
  188. components: {},
  189. props: {
  190. //启用的组件,不传为所有
  191. keys: {
  192. type: Array,
  193. default: ["xzq", "hx", "sc", "zbd"],
  194. },
  195. activeTabs: {
  196. type: String,
  197. },
  198. type: {
  199. type: String,
  200. },
  201. },
  202. data() {
  203. return {
  204. dialogVisible: false,
  205. yearsOpt: [], //检测图斑时间季度数据数组
  206. monitorOpt: [],
  207. monitorVal: "",
  208. yearsVal: "", //时间季度绑定
  209. input: "", //图斑编号搜索条件绑定
  210. updateObj: {
  211. //搜索条件
  212. region: "4602",
  213. tab: 1,
  214. val0: "",
  215. val1: "",
  216. val2: "",
  217. },
  218. active_dableData: [], //表格数据
  219. multipleSelection: [], //选择表格选中的数据
  220. idArr: [], //存储id数组用于删除
  221. // -----------以上为选择图斑功能所需数据------------
  222. userXZQ: "", //store.state.user.user.dept.district,
  223. fwlist: {
  224. xzq: {
  225. id: 0,
  226. name: "行政区",
  227. icon: "wind-power",
  228. },
  229. hx: {
  230. id: 1,
  231. name: "绘制",
  232. icon: "Share",
  233. },
  234. sc: {
  235. id: 2,
  236. name: "上传",
  237. icon: "Upload-filled",
  238. },
  239. zbd: {
  240. id: 3,
  241. name: "坐标点",
  242. icon: "Location",
  243. },
  244. },
  245. model: {
  246. fwlx: 0,
  247. xzfw: "",
  248. xzmj: 0,
  249. feature: null,
  250. yptype:1,
  251. },
  252. handlerDraw: null,
  253. draw: null, //绘制
  254. fileList: [], //文件
  255. fileDataID: "", //存储上传文件获取到的id
  256. dataSources: null,
  257. };
  258. },
  259. mounted() {
  260. // this.model.fwlx = this.fwlist[this.$props.keys[0]].id;
  261. },
  262. methods: {
  263. creatTb() {
  264. this.yptype = 2
  265. this.dialogVisible = false;
  266. this.multipleSelection.forEach((item, index) => {
  267. this.model.xzmj += item.jcmj;
  268. this.fileDataID += item.id + ",";
  269. item.type = "图斑上图";
  270. if (item.geom)
  271. loadGeoJSON(item.geom, "#55A1E3", { isfly: true }, (data) => {
  272. layerSources[item.jcbh] = data;
  273. data.entities.values.forEach((entity) => {
  274. entity.properties = item;
  275. });
  276. });
  277. this.idArr.push(item.jcbh);
  278. });
  279. //去掉最后一个逗号(如果不需要去掉,就不用写)
  280. if (this.multipleSelection.length > 0) {
  281. this.fileDataID = this.fileDataID.substr(0, this.fileDataID.length - 1);
  282. }
  283. },
  284. handleSelectionChange(val) {
  285. this.multipleSelection = val;
  286. },
  287. handleClose(done) {
  288. this.dialogVisible = false;
  289. },
  290. typeChange(val) {
  291. this.updateObj.val2 = val;
  292. },
  293. regionChange1(region) {
  294. this.updateObj.region = region;
  295. },
  296. //年份季度改变
  297. yearsChange(val) {
  298. val = JSON.parse(JSON.stringify(val));
  299. this.updateObj.val0 = val.startTime;
  300. this.updateObj.val1 = val.endTime;
  301. this.yearsVal = val.quarter;
  302. },
  303. getXzqTreeData() {
  304. GetXzqhTree().then((res) => {
  305. if (res.data.length > 0) {
  306. const list = res.data[0].children.filter((item) => {
  307. return item.label == "三亚市";
  308. });
  309. if (list.length > 0) {
  310. list[0].value = "4602";
  311. this.xzqTreeData = list[0];
  312. } else this.xzqTreeData = res.data;
  313. }
  314. });
  315. GetDateList().then((res) => {
  316. this.yearsOpt = res.data;
  317. this.updateObj.val0 = res.data[0].startTime;
  318. this.updateObj.val1 = res.data[0].endTime;
  319. this.yearsVal = res.data[0].quarter;
  320. });
  321. //检测类型分类
  322. CodeList({
  323. dictType: "卫片执法后地类分类标准‌",
  324. pageNum: 1,
  325. pageSize: 999,
  326. }).then((res) => {
  327. if (res.code == 200) {
  328. this.monitorOpt = res.rows;
  329. }
  330. });
  331. },
  332. initNew() {
  333. let obj = {
  334. hlx: this.updateObj.val2,
  335. regioncode: this.updateObj.region,
  336. startTime: this.updateObj.val0,
  337. endTime: this.updateObj.val1,
  338. pageNum: 1,
  339. pageSize: "9999999",
  340. jcbh: this.input,
  341. };
  342. JctbList(obj).then((res) => {
  343. this.active_dableData = res.rows;
  344. this.total = res.total;
  345. });
  346. },
  347. changePatches() {
  348. this.clearAll();
  349. this.getXzqTreeData();
  350. this.dialogVisible = true;
  351. },
  352. remove() {
  353. if (this.idArr.length != 0) {
  354. this.idArr.forEach((item) => {
  355. viewer.dataSources.remove(layerSources[item]);
  356. });
  357. }
  358. },
  359. /** ---------------------以上为选择图斑的逻辑方法----------- **/
  360. //上传文件
  361. handleChange(file, fileList) {
  362. if (fileList.length > 0) {
  363. this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
  364. this.clearAll(false);
  365. }
  366. this.yptype = 1
  367. const formdata = new FormData();
  368. formdata.append("file", file.raw);
  369. formdata.append("fromType", 2);
  370. formdata.append("fromRoute", this.$route.path);
  371. formdata.append("storeStats", 0);
  372. formdata.append("followup", "");
  373. ShapeUploadV1(formdata).then((res) => {
  374. if (res.success) {
  375. this.model.xzmj = (res.data.area * 0.0015).toFixed(2);
  376. // viewer.entities.removeAll();
  377. this.resetDataSources();
  378. this.fileDataID = res.data.id;
  379. this.model.xzfw = res.data.id;
  380. this.model.geom = res.data.geom;
  381. this.addPolygon(parse(res.data.geom));
  382. if (this.$props.type == "cutfill" || this.$props.type == "up") {
  383. this.$emit("cutfill", this.model.geom);
  384. }
  385. }
  386. });
  387. },
  388. //上传文件
  389. handleChange1(file, fileList) {
  390. if (fileList.length > 0) {
  391. this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
  392. this.clearAll(false);
  393. }
  394. const formdata = new FormData();
  395. formdata.append("file", file.raw);
  396. this.addPolygon();
  397. },
  398. // 加载GeoJSON数据
  399. addPolygon(geojson) {
  400. let _this = this;
  401. let polygon = Cesium.GeoJsonDataSource.load(geojson, {
  402. clampToGround: true,
  403. stroke: Cesium.Color.RED,
  404. fill: Cesium.Color.WHITE.withAlpha(0.3),
  405. strokeWidth: 5,
  406. });
  407. polygon.then(function (dataSource) {
  408. // 将数据源添加到Cesium Viewer
  409. viewer.dataSources.add(dataSource);
  410. viewer.zoomTo(dataSource);
  411. now_dataSources = dataSource;
  412. });
  413. },
  414. resetDataSources() {
  415. if (now_dataSources) {
  416. viewer.dataSources.remove(now_dataSources);
  417. now_dataSources = null;
  418. }
  419. },
  420. //绘制
  421. drawMap() {
  422. this.remove(); //删除选择的图斑
  423. this.yptype = 1
  424. if (!window.handlerPolygon) {
  425. common.initHandler("Polygon");
  426. }
  427. common.handlerDrawing("Polygon").then(
  428. (res) => {
  429. //过滤掉高度
  430. const filteredArr = res.positions.filter((item, index) => {
  431. if ((index + 1) % 3 !== 0) {
  432. return item;
  433. }
  434. });
  435. // 数组变二维数组方法
  436. function listToMatrix(list, elementsPerSubArray) {
  437. var matrix = [],
  438. i,
  439. k;
  440. for (i = 0, k = -1; i < list.length; i++) {
  441. if (i % elementsPerSubArray === 0) {
  442. k++;
  443. matrix[k] = [];
  444. }
  445. matrix[k].push(list[i]);
  446. }
  447. return matrix;
  448. }
  449. var matrix = listToMatrix(filteredArr, 2);
  450. matrix.push(matrix[0]);
  451. const geojsonPolygon = turf.polygon([matrix]);
  452. // var parse = require("wellknown"); //引入wellknow
  453. const wktPolygon = parse.stringify(geojsonPolygon);
  454. if (this.$props.type == "cutfill") {
  455. this.model.geom = wktPolygon;
  456. this.$emit("cutfill", this.model.geom);
  457. return;
  458. }
  459. if (this.$props.type == "up") {
  460. this.$emit("cutfill", wktPolygon, res.positions);
  461. }
  462. const formdata = new FormData();
  463. // formdata.append("file", file.raw);
  464. formdata.append("fromType", 1);
  465. formdata.append("geom", wktPolygon);
  466. formdata.append("fromRoute", this.$route.path);
  467. formdata.append("storeStats", 0);
  468. formdata.append("followup", "");
  469. // this.addPolygon();
  470. ShapeUploadV1(formdata).then((res) => {
  471. if (res.success) {
  472. this.fileDataID = res.data.id;
  473. this.model.xzmj = (res.data.area * 0.0015).toFixed(2);
  474. this.model.xzfw = res.data.id;
  475. this.model.geom = res.data.geom;
  476. this.addPolygon(parse(res.data.geom));
  477. this.$message({
  478. message: "绘制成功!",
  479. type: "success",
  480. });
  481. }
  482. });
  483. },
  484. (err) => {
  485. console.log(err);
  486. }
  487. );
  488. window.handlerPolygon.activate();
  489. },
  490. clear() {
  491. if (this.handlerDraw != null) {
  492. this.handlerDraw.clear();
  493. viewer.scene.globe.removeAllExcavationRegion();
  494. this.handlerDraw.deactivate();
  495. this.handlerDraw = null;
  496. this.result = null;
  497. }
  498. },
  499. //清除
  500. clearAll(clearfile = true) {
  501. //销毁上传创建的面
  502. // viewer.entities.removeAll();
  503. this.remove();
  504. this.resetDataSources();
  505. this.model.xzfw = "";
  506. this.model.xzmj = 0;
  507. if (clearfile) {
  508. this.fileDataID = "";
  509. this.fileList = [];
  510. }
  511. common.clearHandlerDrawing("Polygon");
  512. },
  513. //输出:重置
  514. reset() {
  515. this.clearAll();
  516. },
  517. //输出:获取范围
  518. getRange() {
  519. return this.model;
  520. },
  521. },
  522. beforeDestroy() {
  523. this.clearAll();
  524. },
  525. watch: {
  526. // 监听,当路由发生变化的时候执行
  527. $route: {
  528. // $route可以用引号,也可以不用引号//to 老路由信息,from 新路由信息
  529. handler(to, from) {
  530. this.clearAll();
  531. },
  532. deep: true, // 深度观察监听
  533. immediate: true, // 第一次初始化渲染就可以监听到
  534. },
  535. updateObj: {
  536. handler(newVal, oldVal) {
  537. this.initNew();
  538. },
  539. deep: true,
  540. immediate: true,
  541. },
  542. },
  543. };
  544. </script>
  545. <style lang="scss" scoped>
  546. .map-range {
  547. width: 100px;
  548. // height: 100px;
  549. color: #fff;
  550. .xz_type {
  551. margin-bottom: 10px;
  552. // display: flex;
  553. // justify-content: space-between;
  554. .keyitem {
  555. width: 100px;
  556. height: 30px;
  557. font-size: 16px;
  558. line-height: 30px;
  559. display: inline-block;
  560. cursor: pointer;
  561. }
  562. }
  563. .fwlxrange {
  564. display: flex;
  565. justify-content: space-between;
  566. text-align: center;
  567. .clear {
  568. width: 80px;
  569. }
  570. /deep/ .el-button--mini {
  571. background: #0f7ac8;
  572. border: none;
  573. border-radius: 0;
  574. color: #fff;
  575. width: 60px;
  576. height: 26px;
  577. font-size: 12px;
  578. padding: 0;
  579. // line-height: 32px;
  580. // text-align: center;
  581. }
  582. }
  583. }
  584. .gdzl {
  585. .headerSelect {
  586. width: 100%;
  587. height: 26px;
  588. // background: #00ffff;
  589. margin: 5px 0px;
  590. display: flex;
  591. justify-content: space-between;
  592. /deep/ .el-select {
  593. width: 95%;
  594. // padding: 0 10px;
  595. // margin-right: 10px;
  596. }
  597. /deep/ .el-input--suffix .el-input__inner {
  598. padding-right: 15px;
  599. // height: 26px;
  600. background: #041c3273 !important;
  601. border: 1px dashed #0f7ac8;
  602. color: #fff;
  603. }
  604. /deep/ .el-cascader {
  605. // line-height: 26px;
  606. }
  607. /deep/.el-input__icon {
  608. // line-height: 1;
  609. color: #fff;
  610. }
  611. /deep/ .el-input__inner::placeholder {
  612. color: #fff;
  613. }
  614. }
  615. .headerInp {
  616. display: flex;
  617. justify-content: space-between;
  618. align-items: center;
  619. /deep/ .el-button--mini {
  620. background: #0f7ac8;
  621. border: none;
  622. border-radius: 0;
  623. color: #fff;
  624. width: 60px;
  625. height: 26px;
  626. font-size: 12px;
  627. padding: 0;
  628. }
  629. /deep/ .el-input__inner {
  630. height: 26px;
  631. width: 80%;
  632. }
  633. }
  634. }
  635. .ghzc .el-col .el-cascader--mini {
  636. width: 33% !important;
  637. }
  638. .ghzc .el-col .el-select {
  639. width: 33% !important;
  640. }
  641. /deep/ .el-dialog__header {
  642. padding: 10px 20px 0px;
  643. }
  644. /deep/ .el-dialog__body {
  645. padding: 0px 20px;
  646. }
  647. </style>