Skip to content

Instantly share code, notes, and snippets.

@lxbarth
Created August 10, 2012 14:02
Show Gist options
  • Save lxbarth/3314418 to your computer and use it in GitHub Desktop.
Save lxbarth/3314418 to your computer and use it in GitHub Desktop.
Going mapbox.js
diff --git a/site.js b/site.js
index b31ce96..fcc0add 100644
--- a/site.js
+++ b/site.js
@@ -1,7 +1,4 @@
window.onload = function() {
- // TileJSON URL pointing to MapBox Hosting.
- var url = 'http://a.tiles.mapbox.com/v3/' +
- document.location.search.substr(1) +'.jsonp';
// Reveal all dynamically populated elements.
var reveal = function() {
@@ -11,43 +8,27 @@ window.onload = function() {
}
};
- wax.tilejson(url, function(tilejson) {
+ mapbox.auto('map', document.location.search.substr(1), function(map, o) {
+
// Set up map.
- var m = new MM.Map('map',
- new wax.mm.connector(tilejson));
+ map.ui.hash.add();
+ map.ui.fullscreen.add();
+ map.ui.legend.add();
+ map.ui.refresh();
- // Set zoom range and default location.
- m.setZoomRange(tilejson.minzoom, tilejson.maxzoom);
!document.location.hash &&
- m.setCenterZoom(new MM.Location(
- tilejson.center[1],
- tilejson.center[0]),
- tilejson.center[2]);
-
- // Set up location tracking in URL.
- new MM.Hash(m);
-
- // Set up zoomer and fullscreen.
- wax.mm.zoomer(m).appendTo(m.parent);
- wax.mm.fullscreen(m, tilejson).appendTo(document.getElementById('map'));
-
- // Set up interaction and legends.
- wax.mm.interaction()
- .map(m)
- .tilejson(tilejson)
- .on(wax.tooltip().animate(true).parent(m.parent).events());
- wax.mm.legend(m, tilejson).appendTo(m.parent);
+ map.zoom(o.zoom).center(o.center);
// Populate dynamic fields from tilejson.
- document.getElementById('title').innerHTML = tilejson.name || '';
- document.getElementById('description').innerHTML = tilejson.description || '';
- document.getElementById('attribution').innerHTML = tilejson.attribution || '';
+ document.getElementById('title').innerHTML = o.name || '';
+ document.getElementById('description').innerHTML = o.description || '';
+ document.getElementById('attribution').innerHTML = o.attribution || '';
// Hide instructions and display all dynamic elements.
document.getElementById('instructions').style.display = 'none';
reveal();
});
- // Wax doesn't call us back if there's an error. Cheat.
+ // Mapbox.js doesn't call us back if there's an error. Cheat.
setTimeout(reveal, 750);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment