Skip to content

Commit

Permalink
center/zoom defaults, exports, window.onload
Browse files Browse the repository at this point in the history
* Incorporated center and zoom defaults in data-attributes (a la
  layer.js, used in trees-cabs-crime).
* Added a check for the homeLink before doing the syncMapLinks() thing.
* Export `MAP` to window so other scripts can use it.
* Do the initialization on window load, so that the viewport sizing
  works more reliably.
  • Loading branch information
Shawn Allen committed Sep 20, 2012
1 parent 3108adb commit 1e82962
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions js/embed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function(exports) {

function init() {

Expand All @@ -15,14 +15,32 @@

setupZoomControls(main);

syncMapLinks(main, [document.getElementById("home-link")], function(parts) {
parts.unshift(providerName);
});
var zoom = parseInt(parent.getAttribute("data-zoom"));
if (!isNaN(zoom)) {
main.setZoom(zoom);
}

var center = parent.getAttribute("data-center");
if (center && center.length) {
var bits = center.split(",");
main.setCenter(new MM.Location(parseFloat(bits[0]), parseFloat(bits[1])));
}

var homeLink = document.getElementById("home-link");
if (homeLink) {
syncMapLinks(main, [homeLink], function(parts) {
parts.unshift(providerName);
});
}

var hasher = new MM.Hash(main);

exports.MAP = main;
}

init();
track();
window.onload = function() {
init();
track();
};

})();
})(this);

0 comments on commit 1e82962

Please sign in to comment.