无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as Cesium from 'cesium'
import * as turf from '@turf/turf'
 
/**
 * 线缩放通用方法
 * @param data 数据源 格式 [[lng, lat], [lng, lat], [lng, lat]]
 * @param multiple 缩放倍数
 */
export const lineTransformScale = (data, multiple = 3) => {
    const line = turf.lineString(data)
    const scaledLine = turf.transformScale(line, multiple)
 
    return scaledLine.geometry.coordinates
}
 
/**
 * 盒子缩放通用方法
 * @param data 数据源 格式 [[lng, lat], [lng, lat], [lng, lat]]
 * @param multiple 缩放倍数
 */
export const boxTransformScale = (data, multiple = 3) => {
    const line = turf.lineString(data)
    const bbox = turf.bbox(line)
    const bboxPolygon = turf.bboxPolygon(bbox)
    const scaledPolygon = turf.transformScale(bboxPolygon, multiple)
 
    return turf.bbox(scaledPolygon)
}
 
/**
 * 获取盒子中心点
 * @param {*} data 
 * @returns 
 */
export const boxCenterPosition = (data) => {
    const line = turf.lineString(data)
    const bbox = turf.bbox(line)
    const bboxPolygon = turf.bboxPolygon(bbox)
 
    return turf.center(bboxPolygon).geometry.coordinates
}
 
/**
 * 获取多点间,最大点到点距离
 * @param data 数据源 格式 [[lng, lat], [lng, lat], [lng, lat]]
 * @param center 面的中心点 格式 [lng, lat]
 */
export const morePointMaxLength = (data, center, type = 1) => {
    if (type === 2) {
        let maxLength = 0
        const centerCartesian = Cesium.Cartesian3.fromDegrees(center[0], center[1], 0)
 
        data.forEach(pos => {
            const posCartesian = Cesium.Cartesian3.fromDegrees(pos[0], pos[1], pos[2] || 0)
            const distance = Cesium.Cartesian3.distance(centerCartesian, posCartesian)
            if (distance > maxLength) {
                maxLength = distance
            }
        })
 
        return maxLength
    }
 
    const arr = data.reduce((pre, cur) => {
        let from = turf.point(center)
        let to = turf.point(cur)
        let options = { units: "kilometers" }
 
        let distance = turf.distance(from, to, options) // 60.35329997171415
 
        pre.push(distance)
 
        return pre
    }, [])
 
    return (Math.max(...arr) * 1000 + 500)
}