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)
|
}
|