Most modern Web maps use raster or vector tiles to allow zooming to very large scales while only loading a fraction of the whole map. The projection of choice for these tiles is the Mercator projection, and they are typically arranged in the form of a recursively subdivided quadtree.
It would be a shame to limit ourselves to a single map projection, when there are so many to choose from! But how do we figure out which tiles to retrieve?
My initial attempts involved inverting the viewport polygon to figure out which tiles overlap with it. It worked, but slowed down with larger zoom levels.
Mike Bostock then pointed out that the tiles can be traversed recursively (in logarithmic time, since it’s a tree), using a custom geometry stream to detect if a tile is visible or not.
Starting with a single large tile covering most of the globe, this recursively rejects large swathes of the quadtree, and is very fast even at a zoom level of 18!