TerrainCutFillAnalysisNew.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div
  3. v-show="isCutFill"
  4. class="cut_fill_box"
  5. v-loading="loading"
  6. element-loading-text="正在分析中...."
  7. element-loading-spinner="el-icon-loading"
  8. element-loading-background="rgba(0, 0, 0, 0.8)"
  9. >
  10. <el-radio v-model="radio" label="cut">地形填挖方分析</el-radio>
  11. <el-radio v-model="radio" label="smooth">地形平整分析</el-radio>
  12. <el-form
  13. :model="cutData"
  14. ref="ruleForm"
  15. label-width="100px"
  16. :rules="rules"
  17. class="ruleForm"
  18. >
  19. <el-form-item label="分析范围:" prop="xzmj">
  20. <range type="cutfill" :keys="['hx', 'sc']" class="range" ref="range" />
  21. </el-form-item>
  22. <el-form-item label="填挖基准:" v-if="radio == 'cut'">
  23. <!-- readonly="readonly" -->
  24. <el-input v-model="smooth_height" placeholder="" size="mini"></el-input>
  25. </el-form-item>
  26. <div class="sdatadiv">
  27. 分析结果:
  28. <p v-for="(sitem, index) in sdata" :key="index">
  29. <!-- <img src="/static/images/ghzc/iconSun.png" .toFixed(2) /> -->
  30. <span class="ptitle">{{ sitem.name }}</span>
  31. <span class="pvalue">
  32. {{ cutData[sitem.prop] || 0 }}{{ sitem.unit }}
  33. </span>
  34. </p>
  35. </div>
  36. </el-form>
  37. <div class="bottomBtns">
  38. <!-- <el-button size="mini" type="primary" @click="draw">绘制</el-button> -->
  39. <!-- <el-button size="mini" type="primary" @click="submitData">确定</el-button>
  40. <el-button size="mini" type="primary" @click="reset">清除</el-button> -->
  41. <span class="clearBtn" @click="reset">取消</span>
  42. <span class="sureBtn" @click="submitData">确定</span>
  43. <span
  44. class="sureBtn"
  45. :disabled="!cutData.fillVolume"
  46. @click="ExportResult"
  47. >导出结果</span
  48. >
  49. </div>
  50. <el-descriptions border size="mini" :column="2">
  51. <el-descriptions-item v-for="item in sdh" :key="item" :label="item.scS"
  52. ><div
  53. style="width: 4.5rem; height: 100%"
  54. :style="{ 'background-color': item.fill }"
  55. >
  56. &nbsp;
  57. </div>
  58. </el-descriptions-item>
  59. </el-descriptions>
  60. </div>
  61. </template>
  62. <script>
  63. import { getDsm, cutFill } from "@/api/analse";
  64. import * as turf from "@turf/turf";
  65. import parse from "wellknown";
  66. import { listToMatrix, loadGeoJSON, download } from "@/utils/MapHelper/help.js";
  67. import range from "@/components/mapview/range.vue"; ///mapview/range
  68. export default {
  69. name: "TerrainCutFillAnalysis",
  70. components: { range },
  71. data() {
  72. return {
  73. radio: "smooth",
  74. sharedState: store.state,
  75. loading: false,
  76. smooth_height: "",
  77. cutData: {},
  78. // 石方量
  79. sdata: [
  80. { name: "填土体积:", prop: "fillVolume", unit: "立方米", value: "" },
  81. { name: "开挖体积:", prop: "cutVolume", unit: "立方米", value: "" },
  82. { name: "填挖差值:", prop: "cz", unit: "立方米", value: "" },
  83. { name: "最大高程:", prop: "maxHeight", unit: "米", value: "" },
  84. { name: "最小高程:", prop: "minHeight", unit: "米", value: "" },
  85. { name: "填挖基准:", prop: "midHeight", unit: "米", value: "" },
  86. ],
  87. sdh: [
  88. { scS: "填土", fill: "#1E90A8" },
  89. { scS: "开挖", fill: "#FF0000" },
  90. ],
  91. };
  92. },
  93. //监听属性 类似于data概念
  94. computed: {
  95. isCutFill: function () {
  96. return this.sharedState.terrain[4];
  97. },
  98. },
  99. //监控data中的数据变化
  100. watch: {},
  101. //方法集合
  102. methods: {
  103. reset() {
  104. this.cutData = {};
  105. this.$refs.range.reset();
  106. viewer.entities.removeAll();
  107. viewer.dataSources.removeAll();
  108. },
  109. submitData() {
  110. var _temp = this.$refs.range.getRange();
  111. if (!_temp.geom) {
  112. this.$message.warning("请绘制或导入分析范围!");
  113. return;
  114. }
  115. this.cutFill(_temp.geom);
  116. },
  117. clear() {
  118. common.clearHandlerDrawing("Polygon");
  119. },
  120. async cutFill(geom) {
  121. this.loading = true;
  122. let res = await cutFill({
  123. geom,
  124. height: this.smooth_height,
  125. });
  126. if (res.success) {
  127. this.$refs.range.reset();
  128. this.cutData = res.data;
  129. Object.keys(this.cutData).forEach((key) => {
  130. if (typeof this.cutData[key] == "number")
  131. this.cutData[key] = this.cutData[key].toFixed(2);
  132. });
  133. this.cutData.cz = res.data.cutVolume - res.data.fillVolume;
  134. this.loading = false;
  135. let pitch = Cesium.Math.toRadians(-45.0);
  136. let params = { sw: 0.001, fill_a: 0.8 };
  137. loadGeoJSON(res.data.bottomGeom, "#1E90A8", params, (data) => {
  138. viewer.flyTo(data, {
  139. offset: new Cesium.HeadingPitchRange(0, -45, 100),
  140. });
  141. });
  142. loadGeoJSON(res.data.midGeom, "#ff0000", params, (data) => {
  143. viewer.flyTo(data, {
  144. offset: new Cesium.HeadingPitchRange(0, -45, 100),
  145. });
  146. });
  147. }
  148. // let newArr = positions.map((item, index) => {
  149. // return (index + 1) % 3 === 0 ? data.data : item;
  150. // });
  151. // viewer.scene.globe.removeAllModifyRegion();
  152. // viewer.scene.globe.addModifyRegion({
  153. // name: "ggg",
  154. // position: newArr,
  155. // });
  156. // this.smooth_height = data.data.toFixed(2);
  157. // // let cutVolume = cutFillAnalysis.VolumeAnalysis1(threeArray, Number(height));
  158. // // console.log('cutVolume: ', cutVolume);
  159. // let newArray = [];
  160. // for (let i = 0; i < positions_noHeight.length; i += 2) {
  161. // // 将每两个连续的元素组合成一个新的数组,并添加到新数组中
  162. // newArray.push([positions_noHeight[i], positions_noHeight[i + 1]]);
  163. // }
  164. // newArray.push(newArray[0]);
  165. // var polygon = turf.polygon([newArray]);
  166. // this.result_area = turf.area(polygon).toFixed(2);
  167. },
  168. ExportResult() {
  169. let _this = this;
  170. // let box = that.squarePolygon(entitys);
  171. // viewer.camera.flyTo({
  172. // destination: Cesium.Rectangle.fromDegrees(
  173. // box[0][0] + 0.0002,
  174. // box[0][1] - 0.0002,
  175. // box[2][0] - 0.0002,
  176. // box[2][1] + 0.0002
  177. // ),
  178. // });
  179. setTimeout(function () {
  180. var promise = scene.outputSceneToFile();
  181. Cesium.when(promise, function (base64data) {
  182. download(base64data, _this.drawLegends);
  183. });
  184. }, 1000);
  185. },
  186. /**
  187. * 根据图片生成画布
  188. */
  189. // 绘制图例
  190. drawLegends(canvas, ctx) {
  191. let _this = this;
  192. console.log("-----");
  193. var legends = [...this.sdata, ...this.sdh];
  194. var padding = 10; // 图例与边缘的间距
  195. var lineHeight = 30; // 每行图例的高度
  196. var labW = 200;
  197. var x = canvas.width - padding - labW; // 图例的起始X坐标
  198. var y = canvas.height - legends.length * lineHeight - padding; // 图例的起始Y坐标
  199. // 绘制颜色块
  200. ctx.fillStyle = "#ffffff";
  201. ctx.fillRect(
  202. x - padding,
  203. y - padding,
  204. canvas.width - x + padding,
  205. canvas.height - y + padding
  206. );
  207. legends.forEach(function (legend, index) {
  208. // 绘制文本
  209. if (legend.scS) {
  210. ctx.fillStyle = "black";
  211. ctx.fillText(legend.scS, x, y + index * lineHeight + lineHeight / 2);
  212. // 绘制颜色块
  213. ctx.fillStyle = legend.fill;
  214. ctx.fillRect(
  215. x + (labW / 3) * 2,
  216. y + index * lineHeight,
  217. 30,
  218. lineHeight
  219. );
  220. } else {
  221. ctx.fillStyle = "black";
  222. let text = `${legend.name}:${_this.cutData[legend.prop]}${
  223. legend.unit
  224. }`;
  225. ctx.fillText(text, x, y + index * lineHeight + lineHeight / 2);
  226. }
  227. });
  228. },
  229. },
  230. };
  231. </script>
  232. <style lang="scss" scoped>
  233. .cut_fill_box {
  234. width: 100%;
  235. height: 550px;
  236. padding: 20px;
  237. box-sizing: border-box;
  238. position: relative;
  239. .ruleForm {
  240. width: 100%;
  241. height: calc(100% - 120px);
  242. overflow-y: auto;
  243. }
  244. .el-form-item {
  245. margin-bottom: 0px !important;
  246. }
  247. .range {
  248. width: 90% !important;
  249. }
  250. .sdatadiv {
  251. text-align: left;
  252. line-height: 40px;
  253. }
  254. .ptitle {
  255. width: 100px;
  256. color: #cddeeb;
  257. text-align: right;
  258. padding: 0 12px 0 0;
  259. display: inline-block;
  260. }
  261. .pvalue {
  262. color: #02a7f0;
  263. }
  264. }
  265. .el-radio {
  266. color: white;
  267. }
  268. .bottomBtns {
  269. line-height: 30px;
  270. width: 100%;
  271. // background-color: rgba(255, 192, 203, 0.418);
  272. display: flex;
  273. justify-content: space-between;
  274. text-align: center;
  275. // position: absolute;
  276. // bottom: 70px;
  277. .sureBtn {
  278. width: 30%;
  279. background-color: #0f7ac8;
  280. cursor: pointer;
  281. &:hover {
  282. font-weight: bold;
  283. }
  284. }
  285. .clearBtn {
  286. cursor: pointer;
  287. width: 30%;
  288. background-color: #3f94f53f;
  289. border: 1px solid #3f93f5;
  290. color: #b6e0ff;
  291. &:hover {
  292. font-weight: bold;
  293. }
  294. }
  295. }
  296. </style>
  297. <style lang="scss">
  298. .cut_fill_box {
  299. .el-descriptions {
  300. color: #fff;
  301. margin-top: 20px;
  302. // position: absolute;
  303. // bottom: 20px;
  304. }
  305. .el-descriptions__body {
  306. color: #fff;
  307. background-color: #fff0;
  308. }
  309. .el-descriptions .is-bordered .el-descriptions-item__cell {
  310. border: 1px solid rgba(15, 122, 200, 0.4);
  311. }
  312. .el-descriptions-item__label.is-bordered-label {
  313. font-weight: 700;
  314. color: #ffffff;
  315. background: rgba(4, 28, 50, 0.6);
  316. }
  317. .el-date-editor .el-range-input {
  318. background-color: rgba(4, 28, 50, 0.5);
  319. }
  320. }
  321. </style>