<title>pixelToLocation</title>
src='https://api.tiles.mapbox.com/mapbox.js/v0.6.3/mapbox.js'></script>
href='https://api.tiles.mapbox.com/mapbox.js/v0.6.3/mapbox.css'
body { margin:0; padding:0; font:normal 14px/20px 'Georgia', serif; }
#map { position:absolute; top:0; left:0; bottom:25px; right:0; }
border-top:1px solid #000;
#places a { margin:0 10px; }
<a href='#' data-pixel='1800,1715'>Albert Memorial</a>
<a href='#' data-pixel='2429,675'>Royal Botanic Gardens</a>
<a href='#' data-pixel='1431,562'>Paddington Recreational Ground</a>
<a href='#' data-pixel='3855,1233'>St Paul's Cathedral</a>
// normalize x/y values to their ratio to the full image size,
// so they can work at multiple scales
function pixelToCoordinate(w, h) {
// here's the only real tricky part
// of the code: if the image doesn't fill
// the whole canvas, that means that it's
// nudged either down or to the left
// to be centered. The size of this nudge
// is equal to the difference between
// the width and height over two.
if (w > h) y += (w - h) / 2;
if (w < h) x += (h - w) / 2;
return new MM.Coordinate(
function pixelToLocation(w, h, map) {
var toCoordinate = pixelToCoordinate(w, h);
// map.coordinateLocation takes a coordinate
// value and returns a geographical
return map.coordinateLocation(toCoordinate(x, y));
mapbox.auto('map', 'tmcw.geographica', function(m) {
var pxl = pixelToLocation(5000, 3292, m);
m.center(pxl(1800, 1715));
var as = document.getElementsByTagName('a');
for (var i = 0; i < as.length; i++) {
if (px = as[i].getAttribute('data-pixel')) {
as[i].onclick = (function(x, y) {
m.center(pxl(x, y), true);