d3世界地图 - 计算缩放的地理边界 [英] d3 world map -- calculate geo bounds on zoom

查看:849
本文介绍了d3世界地图 - 计算缩放的地理边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图适应Mike Bostock的约束缩放示例以适应我的需要。 ( http://bl.ocks.org/mbostock/4987520 )。有什么方法来计算当地图缩放时的投影的地理界限(在long / lat)。 d3.geo.bounds()方法需要一个feature - 我真的不想放大任何特定的功能。所有我想要的是投影的可见区域的地理界限。

I am trying to adapt Mike Bostock's constrained zoom example to fit my needs. (http://bl.ocks.org/mbostock/4987520). Is there any way to calculate the geo bounds (in long/lat) of the projection when the map is zoomed. The d3.geo.bounds() method expects a 'feature' -- I really don't want to zoom on any particular feature. All I want is the geo bounds for the visible area of the projection.

提前感谢,
Kishore

Thanks in advance, Kishore

推荐答案

其他答案是一个错误的问题,但我会离开它,以防有人以同样的方式误读这个问题。

My other answer was a misreading of the question, but I'll leave it there in case someone else misreads the question in the same way.

要找到边界框您的地图在屏幕上的可视区域,只需使用projection.invert()函数,并将它的SVG的左上角和右下角。如果您有500x500的SVG,则如下所示:

To find the bounding box of the visual area of your map on screen, simply use the projection.invert() function and feed it the top-left and bottom-right corners of your SVG. If you have a 500x500 SVG, then that looks like this:

 projection.invert([0,0])
 projection.invert([500,500])

这是一个屏幕的边框,

This is a bounding box of your screen, in lat-long (or whatever coordinate system you're using).

之后,你可以得到你的特征的边界,并测试他们是完全包含的还是相交的或使它们的质心在这些边界内。我不打算在这里解释如何做,因为这是一个不同的问题,许多不同的答案取决于你在在这些界限内你的决定的定义。

After that, you can get the bounds of your features and test to see if they are fully-contained or intersecting or have their centroid within those bounds. I'm not going to explain how to do that here, because that's a different question with many different answers depending on which definition of "within these bounds" you decide on.

这篇关于d3世界地图 - 计算缩放的地理边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆