|
@@ -82,7 +82,7 @@
|
|
|
import { getDsm, cutFill } from "@/api/analse";
|
|
|
import * as turf from "@turf/turf";
|
|
|
import parse from "wellknown";
|
|
|
-import { listToMatrix, loadGeoJSON, download } from "@/utils/MapHelper/help.js";
|
|
|
+import { loadGeoJSON, download } from "@/utils/MapHelper/help.js";
|
|
|
import range from "@/components/mapview/range.vue"; ///mapview/range
|
|
|
export default {
|
|
|
name: "TerrainCutFillAnalysis",
|
|
@@ -133,6 +133,7 @@ export default {
|
|
|
this.$refs.range.reset();
|
|
|
viewer.entities.removeAll();
|
|
|
viewer.dataSources.removeAll();
|
|
|
+ viewer.scene.globe.removeAllModifyRegion();
|
|
|
},
|
|
|
submitData() {
|
|
|
var _temp = this.$refs.range.getRange();
|
|
@@ -143,12 +144,39 @@ export default {
|
|
|
this.form.geom = _temp.geom;
|
|
|
this.cutFill();
|
|
|
},
|
|
|
+ flatten(coordinates) {
|
|
|
+ if (coordinates.length === 0) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ let result = [];
|
|
|
+ coordinates.forEach((c) => {
|
|
|
+ if (Array.isArray(c[0])) {
|
|
|
+ result = result.concat(this.flatten(c));
|
|
|
+ } else {
|
|
|
+ result.push(c[0]);
|
|
|
+ result.push(c[1]);
|
|
|
+ result.push(Number(this.cutData.midHeight));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ // geojson 转一维数组
|
|
|
+ geojsonToFlatArray(geojson) {
|
|
|
+ if (geojson.type === "MultiLineString" || geojson.type === "Polygon") {
|
|
|
+ return this.flatten(geojson.coordinates[0]);
|
|
|
+ }
|
|
|
+ if (geojson.type === "MultiPolygon") {
|
|
|
+ return this.flatten(geojson.coordinates.map((polygon) => polygon[0]));
|
|
|
+ }
|
|
|
+ },
|
|
|
clear() {
|
|
|
common.clearHandlerDrawing("Polygon");
|
|
|
},
|
|
|
|
|
|
async getDsm(geom) {
|
|
|
let res = await getDsm({ geom, type: "all" });
|
|
|
+ if (!res.data)
|
|
|
+ this.$message.error("抱歉!不在分析范围内,请在抱坡区进行分析");
|
|
|
this.cutData = {
|
|
|
min: res.data.min.toFixed(2),
|
|
|
max: res.data.max.toFixed(2),
|
|
@@ -161,7 +189,8 @@ export default {
|
|
|
this.loading = false;
|
|
|
if (res.success) {
|
|
|
this.$refs.range.reset();
|
|
|
- if (!res.data) this.$message.error("抱歉!不在分析范围内");
|
|
|
+ if (!res.data)
|
|
|
+ this.$message.error("抱歉!不在分析范围内,请在抱坡区进行分析");
|
|
|
// this.cutData = { ...this.cutData, ...res.data };
|
|
|
Object.keys(res.data).forEach((key) => {
|
|
|
if (typeof res.data[key] == "number")
|
|
@@ -176,8 +205,19 @@ export default {
|
|
|
viewer.dataSources.removeAll();
|
|
|
loadGeoJSON(res.data.bottomGeom, "#1E90A8", params);
|
|
|
loadGeoJSON(res.data.midGeom, "#ff0000", params);
|
|
|
+ let threeArray = [];
|
|
|
+ threeArray = this.geojsonToFlatArray(parse(this.form.geom));
|
|
|
+ this.extract(threeArray);
|
|
|
}
|
|
|
},
|
|
|
+ //地形抽出部分
|
|
|
+ extract(positions) {
|
|
|
+ viewer.scene.globe.removeAllModifyRegion();
|
|
|
+ viewer.scene.globe.addModifyRegion({
|
|
|
+ name: "ggg",
|
|
|
+ position: positions,
|
|
|
+ });
|
|
|
+ },
|
|
|
ExportResult() {
|
|
|
var legends = [];
|
|
|
// legends.push({ name: "最小高程", value: this.cutData.min, unit: "米" });
|
|
@@ -194,47 +234,6 @@ export default {
|
|
|
download(base64data, legends);
|
|
|
});
|
|
|
},
|
|
|
- /**
|
|
|
- * 根据图片生成画布
|
|
|
- */
|
|
|
-
|
|
|
- // 绘制图例
|
|
|
- drawLegends(canvas, ctx) {
|
|
|
- var padding = 10; // 图例与边缘的间距
|
|
|
- var lineHeight = 30; // 每行图例的高度
|
|
|
- var labW = 200;
|
|
|
- var x = canvas.width - padding - labW; // 图例的起始X坐标
|
|
|
- var y = canvas.height - legends.length * lineHeight - padding; // 图例的起始Y坐标
|
|
|
- // 绘制颜色块
|
|
|
- ctx.fillStyle = "#ffffff";
|
|
|
- ctx.fillRect(
|
|
|
- x - padding,
|
|
|
- y - padding,
|
|
|
- canvas.width - x + padding,
|
|
|
- canvas.height - y + padding
|
|
|
- );
|
|
|
- legends.forEach(function (legend, index) {
|
|
|
- // 绘制文本
|
|
|
- if (legend.scS) {
|
|
|
- ctx.fillStyle = "black";
|
|
|
- ctx.fillText(legend.scS, x, y + index * lineHeight + lineHeight / 2);
|
|
|
- // 绘制颜色块
|
|
|
- ctx.fillStyle = legend.fill;
|
|
|
- ctx.fillRect(
|
|
|
- x + (labW / 3) * 2,
|
|
|
- y + index * lineHeight,
|
|
|
- 30,
|
|
|
- lineHeight
|
|
|
- );
|
|
|
- } else {
|
|
|
- ctx.fillStyle = "black";
|
|
|
- let text = `${legend.name}:${_this.cutData[legend.prop]}${
|
|
|
- legend.unit
|
|
|
- }`;
|
|
|
- ctx.fillText(text, x, y + index * lineHeight + lineHeight / 2);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
},
|
|
|
};
|
|
|
</script>
|