| | |
| | | * @Author: shuishen 1109946754@qq.com |
| | | * @Date: 2023-03-31 10:52:25 |
| | | * @LastEditors: shuishen 1109946754@qq.com |
| | | * @LastEditTime: 2023-04-04 15:55:33 |
| | | * @LastEditTime: 2023-05-06 16:52:41 |
| | | * @FilePath: \srs-police-affairs\src\utils\turfPolygon.js |
| | | * @Description: |
| | | * |
| | |
| | | */ |
| | | 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)) |
| | | }) |
| | | function getAllRegionCenter (data) { |
| | | let arr = [] |
| | | |
| | | return pre |
| | | }, []) |
| | | data.forEach(item => { |
| | | if (item.position && item.position.length > 0) { |
| | | arr.push(getRegionCenter(item.position)) |
| | | } |
| | | }) |
| | | |
| | | arr.push(arr[0]) |
| | | |
| | | const features = turf.featureCollection(pointArr) |
| | | if (arr.length == 1) { |
| | | return arr[0] |
| | | } else if (arr.length == 2) { |
| | | |
| | | const scope = turf.envelope(features).bbox |
| | | return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1]))).geometry.coordinates |
| | | } else { |
| | | arr.push(arr[0]) |
| | | |
| | | const poly = turf.polygon([[[scope[0], scope[1]], [scope[0], scope[3]], [scope[2], scope[1]], [scope[2], scope[3]]]]) |
| | | return turf.centroid(turf.polygon([arr])).geometry.coordinates |
| | | } |
| | | } |
| | | |
| | | const scaledPoly = turf.transformScale(poly, 3) |
| | | function getRegionCenter (params) { |
| | | let arr = [] |
| | | |
| | | console.log(scope, scaledPoly, 5555) |
| | | params.forEach(areaArray => { |
| | | JSON.parse(areaArray).coordinates.forEach(item => { |
| | | arr.push(turf.centroid(turf.polygon([item[0]])).geometry.coordinates) |
| | | }) |
| | | }) |
| | | |
| | | if (arr.length == 1) { |
| | | return arr[0] |
| | | } else if (arr.length == 2) { |
| | | |
| | | return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1]))).geometry.coordinates |
| | | } else { |
| | | arr.push(arr[0]) |
| | | |
| | | return turf.centroid(turf.polygon([arr])).geometry.coordinates |
| | | } |
| | | } |
| | | |
| | | export const computerCapacity = (data, type = '') => { |
| | | |
| | | if (type != '') { |
| | | |
| | | const center = getAllRegionCenter(data) |
| | | |
| | | if (type == 'all') { |
| | | |
| | | global.viewer.flyToPosition( |
| | | new global.DC.Position( |
| | | Number(center[0] + 0.03), |
| | | Number(center[1] - 0.30), |
| | | Number(36000), |
| | | Number(-3), |
| | | Number(-45), |
| | | Number(0) |
| | | ), |
| | | function () { }, |
| | | 3 |
| | | ) |
| | | |
| | | } else { |
| | | |
| | | global.viewer.flyToPosition( |
| | | new global.DC.Position( |
| | | Number(center[0] + 0.0046), |
| | | Number(center[1] - 0.04), |
| | | Number(4000), |
| | | Number(-3), |
| | | Number(-45), |
| | | Number(0) |
| | | ), |
| | | function () { }, |
| | | 3 |
| | | ) |
| | | |
| | | } |
| | | } else { |
| | | let pointArr = [] |
| | | |
| | | data.forEach(item => { |
| | | if (item.longitude && item.latitude) { |
| | | pointArr.push(turf.point([item.longitude, item.latitude])) |
| | |
| | | |
| | | const scope = turf.envelope(features).bbox |
| | | |
| | | console.log(scope, 5555) |
| | | |
| | | const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]]) |
| | | // const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]]) |
| | | |
| | | global.viewer.flyToBounds(scope, |
| | | { heading: 0, pitch: -45, roll: 0 }, |
| | |
| | | 3 |
| | | ) |
| | | } |
| | | } |
| | | |
| | | export const getMapBounds = (data, type = '') => { |
| | | let pointArr = [] |
| | | |
| | | data.forEach(item => { |
| | | pointArr.push(turf.point([item.x, item.y])) |
| | | return |
| | | }) |
| | | |
| | | const features = turf.featureCollection(pointArr) |
| | | |
| | | const scope = turf.envelope(features).bbox |
| | | |
| | | // const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]]) |
| | | |
| | | return scope |
| | | } |
| | | |
| | | export const getLineSpeed = (data) => { |
| | | var line = turf.lineString(data) |
| | | var length = turf.length(line, { units: 'miles' }) |
| | | |
| | | return length * 1000 / 50 |
| | | } |