在 d3 中获取边界框/可见地图图块的范围

Get bounding box / extent of visible map tiles in d3

假设我有一个这样的标准平铺地图:http://bl.ocks.org/mbostock/4132797

如何获取可见地图的边界框坐标?

换句话说,我怎么能准确地说出在任何给定时间显示的地图范围。我将其理解为边界框,但也理解为范围。

谢谢。

我能够找到类似但具体问题的答案,但我将其保留以防有人搜索一般情况。

来自以利亚·米克斯的 answer:

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.

因此,将可见区域的widthheight插入到投影生成器中。瞧,你有盒子。