Geographic Viewport Clipping

Viewport clipping of geographic features using D3 version 3.1.

Hint: zoom by scrolling your mouse or pinching on a touch screen.

You can specify an arbitrary 2D clip rectangle in pixel coordinates. The benefits are twofold:

  1. Large pixel values are avoided, which can sometimes cause issues with browser rendering. This only occurs if the projection itself has areas of extreme distortion, e.g. the satellite projection.
  2. Smaller SVG paths are generated, which should be rendered faster.

The Liang–Barsky algorithm is used to clip lines efficiently against a rectangular viewport.

For polygons, we rejoin these lines along the clip region edge using Greiner–Hormann, which can clip arbitrary polygons (the same algorithm is used to clip polygons on a sphere).