使用PolygonLayer绘制扇形雷达,绘制出的图形发生偏移,未经过圆心
s337861765 opened this issue · comments
问题描述
const generateSectorGeoJSON = (center, radius, startAngle, endAngle) => {
const earthRadius = 6371000 // 地球半径,单位:米
let coordinates = []
const deltaAngle = 1 // 定义每个点之间的角度差值,以度为单位,越小越精确
// 将角度转换为弧度
const rad = (deg) => (deg * Math.PI) / 180
// 计算扇形边界点
for (let angle = startAngle; angle <= endAngle; angle += deltaAngle) {
const radian = rad(angle)
const latitude = center[1] + (radius / earthRadius) * (180 / Math.PI) * Math.sin(radian)
const longitude =
center[0] +
((radius / earthRadius) * (180 / Math.PI) * Math.cos(radian)) / Math.cos(rad(center[1]))
coordinates.push([longitude, latitude])
// coordinates.push({
// lng: longitude,
// lat: latitude
// })
}
// 将起点添加到末尾,闭合扇形
coordinates.push(coordinates[0])
//构建GeoJSON对象
const sectorGeoJSON = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [[center, ...coordinates, center]]
}
}
]
}
return sectorGeoJSON
}
函数生成扇形雷达的边界点
重现链接
https://codesandbox.io/p/sandbox/confident-burnell-xkvkmz?file=%2Fdemo.js
重现步骤
No response
预期行为
绘制出一个60度的带弧线的扇形
平台
- 操作系统: [macOS, Windows, Linux, React Native ...]
- 网页浏览器: [Google Chrome, Safari, Firefox]
屏幕截图或视频(可选)
![8f7a4861b717df2371806c995b76db8](https://private-user-images.githubusercontent.com/38305930/309192694-026b7303-31a5-4c7c-940e-4b4fbccebf4d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgyMzIyMTcsIm5iZiI6MTcxODIzMTkxNywicGF0aCI6Ii8zODMwNTkzMC8zMDkxOTI2OTQtMDI2YjczMDMtMzFhNS00YzdjLTk0MGUtNGI0ZmJjY2ViZjRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEyVDIyMzgzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdhNjc5Y2FkMzAyOTcyZGFjZDVlYzI5ZWZkMDQ2ZGJkNGEzZDMwYjg0MGUxNzU3MjkyYjM5NGZiOGNlNjI2ODgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ptSQ8LSfZqAVuAEgP8LCzIEoRtd5UtLfiGpXAO1QAtI)
补充说明(可选)
No response
hi @s337861765, welcome!
Hi @s337861765, Please star this repo if you find it useful! Thanks ⭐!
你好 @s337861765。如果该仓库对你有用,可以 star 一下,感谢你的 ⭐!
抱歉,是生成的数组问题,已经解决了