0

Let's say I have a standard tiled map like this: http://bl.ocks.org/mbostock/4132797

How can I get the bounding box coordinates of the visible map?

In other words, how can I say exactly the extent of the map shown at any given time. I understand this as a bounding box but also as an extent.

Thank you.

Union find
  • 7,759
  • 13
  • 60
  • 111

1 Answers1

0

I was able to find answers to similar but specific questions but am leaving this up in case someone is searching for the general case.

From Elijah Meeks's 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.

So, plug in the width and heightof the visible area into the projection generator. Voila, you have the box.

Community
  • 1
  • 1
Union find
  • 7,759
  • 13
  • 60
  • 111