shuishen
2023-04-09 85fb13abbeadc1765d2c0056ba99c6c19aa35dfd
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
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2023-03-31 10:52:25
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-04-04 15:55:33
 * @FilePath: \srs-police-affairs\src\utils\turfPolygon.js
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
 */
import * as turf from '@turf/turf'
 
export const computerCapacity = (data, type) => {
    if (type == 'region') {
        const pointArr = data.reduce((pre, cur) => {
            cur.position && JSON.parse(cur.position).coordinates[0][0].forEach(item => {
                console.log(item, 959)
                item[0] && item[1] && pre.push(turf.point(item))
            })
 
            return pre
        }, [])
 
 
        const features = turf.featureCollection(pointArr)
 
        const scope = turf.envelope(features).bbox
 
        const poly = turf.polygon([[[scope[0], scope[1]], [scope[0], scope[3]], [scope[2], scope[1]], [scope[2], scope[3]]]])
 
        const scaledPoly = turf.transformScale(poly, 3)
 
        console.log(scope, scaledPoly, 5555)
    } else {
        let pointArr = []
 
        data.forEach(item => {
            if (item.longitude && item.latitude) {
                pointArr.push(turf.point([item.longitude, item.latitude]))
                return
            }
 
            if (item.lng && item.lat) {
                pointArr.push(turf.point([item.lng, item.lat]))
                return
            }
        })
 
        const features = turf.featureCollection(pointArr)
 
        const scope = turf.envelope(features).bbox
 
        console.log(scope, 5555)
 
        const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]])
 
        global.viewer.flyToBounds(scope,
            { heading: 0, pitch: -45, roll: 0 },
            (e) => { },
            3
        )
    }
}