Matching Notes

Introducing Mapstatic

I've just published a Ruby Gem and command line tool for generating static maps, Mapstatic.

Mapstatic can generate map images of any size, from any tile provider.

For example, a map of the UK at zoom level 6 using the OpenStreetMap tileset, is generated like so:

mapstatic map uk.png \
  --zoom=5 \
  --bbox=-11.29,49.78,2.45,58.78 \
  --provider=http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png

This produces a file, uk.png, which looks like this:

UK

In this example, I used a bounding box to specify the exact region to map. (This is a good tool if you need to work out the bounding box).

When generating maps from a bounding box, the width and height of the resulting image will be determined by the zoom level. With each increase of zoom level, the dimensions of the image will double.

If you need more control over the dimensions of the image, you can specify the dimensions and center the map on a particular location:

mapstatic map park.png \
  --zoom=15 \
  --lat=40.782563 \
  --lng=-73.965207 \
  --width=560 \
  --height=240 \
  --provider=https://{s}.tiles.mapbox.com/v3/examples.map-9ijuk24y/{z}/{x}/{y}.png

Central Park

I specified a different tile provider in this example with the provider flag. The map uses the Mapbox Streets tileset.

There aren't any limits to the sizes of map that you can produce with Mapstatic, you are only limited by the zoom levels offered by the tile provider. However, I'm pretty sure generating maps like this will be against the terms of service for most commercial tile providers. You should probably check that before rendering a Google Map of the entire world.

At Minified, we use Mapstatic to generate the map images used on our Telescope Cards. We use Tilemill 2 as a tile server serving up tiles with our custom styles. Then we run Mapstatic with the provider flag pointing at Tilemill to generate the images for the cards.

Here's a parting gif from Mapstatic - London rendered with a few different tile providers.

Mapstatic