|
@@ -20,14 +20,19 @@ export function slopeCalculation(data: any[]) {
|
|
|
console.log("坡度:", result.slope.toFixed(6), "米/经度纬度单位");
|
|
|
console.log("倾斜方向:", result.direction.toFixed(2) + "°(0°为正东,逆时针方向)");
|
|
|
|
|
|
- let max = data.map(a => a.value).reduce((acc, cur) => Math.max(acc, cur), Number.MIN_SAFE_INTEGER);
|
|
|
- let min = data.map(a => a.value).reduce((acc, cur) => Math.min(acc, cur));
|
|
|
+ const {maxObj, minObj} = data.reduce((acc, cur) => ({
|
|
|
+ maxObj: acc.maxObj.value > cur.value ? acc.maxObj : cur,
|
|
|
+ minObj: acc.minObj.value < cur.value ? acc.minObj : cur
|
|
|
+ }), {
|
|
|
+ maxObj: data[0],
|
|
|
+ minObj: data[0]
|
|
|
+ });
|
|
|
|
|
|
return {
|
|
|
slope: result.slope.toFixed(6),
|
|
|
direction: result.direction.toFixed(2),
|
|
|
- max: max,
|
|
|
- min: min,
|
|
|
+ max: `${maxObj.name},${maxObj.value}`,
|
|
|
+ min: `${minObj.name},${minObj.value}`,
|
|
|
}
|
|
|
} catch (error: any) {
|
|
|
console.error("计算失败:", error.message);
|