antvis / L7

🌎 Large-scale WebGL-powered Geospatial Data Visualization analysis engine.

Home Page:https://l7.antv.antgroup.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用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

补充说明(可选)

No response

Hi @s337861765, Please star this repo if you find it useful! Thanks ⭐!
你好 @s337861765。如果该仓库对你有用,可以 star 一下,感谢你的 ⭐!

抱歉,是生成的数组问题,已经解决了