根据随机点和随机角度获取geosjon带(Get a geosjon band based on a random point and a random angle)

编程入门 行业动态 更新时间:2024-10-24 07:24:57
根据随机点和随机角度获取geosjon带(Get a geosjon band based on a random point and a random angle)

我想在d3做一些橡皮筋球 ,我觉得这很容易,因为我记得看到Jason Davies的例子 (顶部的第二个),但看起来它实际上更复杂。

贾森以垂直乐队为榜样的例子很直接:

let band = [2, -2].map((d, i) => { let stripe = d3.range(-180, 180).map((x) => [x, d]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })

所以我首先制作一个像这样的垂直乐队:

let band = [2, -2].map((d, i) => { let stripe = d3.range(-90, 90).map((y) => [d, y]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })

但是,相反,我得到了每个杆子上都会关闭的奇怪形状(它应该也是被填充的,而不是抚摸):

我的最终目标是简单地指定一个点,一个角度和一个宽度(在我的例子中为4),它将返回在全球范围内绘制一个带所需的坐标。

谢谢。

I'm trying to do some kind of rubber band ball in d3, I thought it was going to be easy because I remember seeing Jason Davies example (the 2nd one at the top) but it looks like it was more complex actually.

Jason's example for a vertical band is quite straightfoward:

let band = [2, -2].map((d, i) => { let stripe = d3.range(-180, 180).map((x) => [x, d]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })

So I starting by making a vertical band like this:

let band = [2, -2].map((d, i) => { let stripe = d3.range(-90, 90).map((y) => [d, y]) stripe.push(stripe[0]) return i ? stripe.reverse() : stripe })

But instead, I get this weird shape that closes on each pole (it's supposed to be filled too, not stroked):

My end goal would be to simply specify a point, an angle and a width (4 in my example) and it would return the coordinates necessary to draw a band around the globe.

Thanks.

最满意答案

所以这是一个相当简单的问题,因为d3。 我用角度为90°(默认)和随机点的d3.geo.circle ,因此:

let circle = d3.geo.circle() .origin(coords)()

由于d3.geo.circle返回一个多边形,我需要编辑它的属性:

circle.type = 'LineString' circle.coordinates = circle.coordinates[0]

这是最终结果:

地球仪

So it was a fairly simple problem because of d3. I used d3.geo.circle with an angle of 90° (default) and a random point, so:

let circle = d3.geo.circle() .origin(coords)()

Since d3.geo.circle returns a polygon, I needed to edit it's properties:

circle.type = 'LineString' circle.coordinates = circle.coordinates[0]

Here's the final result:

globes

更多推荐

本文发布于:2023-08-07 22:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角度   band   geosjon   based   point

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!