Skip to content

Instantly share code, notes, and snippets.

@RicSwirrl
Created January 19, 2012 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RicSwirrl/1640003 to your computer and use it in GitHub Desktop.
Save RicSwirrl/1640003 to your computer and use it in GitHub Desktop.
Main closure
(function(){
var mapManager
, idleListener = null
, startTime
, map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 14,
center: new google.maps.LatLng(53.48, -2.245), // Manchester
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
});
// initialize with the overall score.
var mapManager = new swirrl.MapManager(map, "IMD-score");
// Handle events coming out of the Map Manager.
$(mapManager).bind('started', function() {
startTime = new Date();
if(idleListener) {
google.maps.event.removeListener(idleListener);
idleListener = null;
}
$("#busy_notice").show();
});
$(mapManager).bind('finished', function() {
window.swirrl.log('busy duration: ' + (new Date() - startTime) + ' ms');
$("#busy_notice").hide();
bindMapIdle();
});
// show warning if zoom too wide
$(mapManager).bind('zoomTooWide', function() {
if (!$("#zoom_warning").is(":visible")) {
$("#zoom_warning").show();
}
});
// hide warning if zoom oK
$(mapManager).bind('zoomOK', function() {
if ($("#zoom_warning").is(":visible")) {
$("#zoom_warning").hide();
}
});
// function to wire up the idleListener
var bindMapIdle = function() {
// if we don't already have an idle-listener, bind one up.
// (fires when the map bounds haven't changed for a bit)
if (!idleListener) {
idleListener = google.maps.event.addListener(map, 'idle', function(e) {
window.swirrl.log('refreshing map');
mapManager.refresh();
});
}
}
// Finally, start listening to Map-Idle events.
bindMapIdle();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment