geo-viewport

Turns a bounding box into a center point and zoom level for static maps. It works in Node.js and in browsers.

Share on XLicense: BSD-2-Clause

Overview

geo-viewport turns a bounding box, also called an extent, into a center point and zoom level, which is what static maps need. It works in Node.js and in browsers, either through browserify or a plain script tag that exposes a geoViewport object. The viewport method takes bounds and an image size in pixels and returns the center and zoom. The bounds method does the reverse and returns the extent for a given center, zoom and size.

Key features

  • viewport() converts bounds and pixel size to center and zoom
  • bounds() returns the extent for a center, zoom and size
  • Runs in Node.js and in browsers
  • Script tag exposes a geoViewport object

Best for

Developers building static map images or views that must fit a known bounding box.

Upstream
mapbox/geo-viewport
Fork on GitHub
Guo-astro/geo-viewport
Upstream stars
197
Category
Maps and geospatial
Language
JavaScript
License
BSD-2-Clause
Forked
2020-11-01
Sync status
In syncLast synced 2026-09-29