Static map with geo-viewport

Use geo-viewport to find a zoom level and centerpoint to display a static map.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Static map with geo-viewport</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<!-- create a placeholder for this static map -->
<img id='static-map'></div>

<!-- include the geo-viewport plugin -->
<script src='https://api.mapbox.com/mapbox.js/plugins/geo-viewport/v0.1.1/geo-viewport.js'></script>

<script>
L.mapbox.accessToken = '<your access token here>';
// This is an example using geo-viewport. See the full docs for full details
// https://github.com/mapbox/geo-viewport

// A bounding box in west, south, east, north order.
var bounds = [
    5.668343999999995,
    45.111511000000014,
    5.852471999999996,
    45.26800200000002
];

// The size of the desired map.
var size = [600, 300];

// Calculate a zoom level and centerpoint for this map.
var vp = geoViewport.viewport(bounds, size);

// Construct a static map url
// https://www.mapbox.com/developers/api/static/
document.getElementById('static-map').src =
    'https://api.mapbox.com/v4/examples.map-zr0njcqy/' +
    vp.center.join(',') + ',' +
    vp.zoom + '/' +
    size.join('x') + '.png' +
    '?access_token=' + L.mapbox.accessToken;
</script>
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example