Unless stated otherwise, code available for viewing through this tool is dedicated to the public domain. If you have any questions, drop me a line.
var map;
var centerLatitude = 38;
var centerLongitude = -95;
var startZoom = 4;
var activeOverlays = {};
function addSideBarItem(title, id, func) {
var listItem = document.createElement('li');
var listItemLink = listItem.appendChild(document.createElement('a'));
listItem.id = id;
listItemLink.href = "#";
listItemLink.innerHTML = title;
listItemLink.onclick = func;
document.getElementById('sidebar-list').appendChild(listItem);
return listItemLink;
}
function regionListClickHandler() {
var code = this.parentNode.id;
if (!activeOverlays[code])
{
var tilelayer = new GTileLayer(new GCopyrightCollection(''));
tilelayer.getTileUrl = function(tile, zoom) { return 'cache/' + code + '/' + tile.x + '-' + tile.y + '-' + zoom + '.gif'; }
tilelayer.isPng = function() { return false; }
tilelayer.getOpacity = function() { return 0.4; }
activeOverlays[code] = new GTileLayerOverlay(tilelayer);
map.addOverlay(activeOverlays[code]);
this.parentNode.className = 'visible';
}
else
{
map.removeOverlay(activeOverlays[code]);
activeOverlays[code] = null;
this.parentNode.className = '';
}
return false;
}
function windowHeight() {
// Standard browsers (Mozilla, Safari, etc.)
if (self.innerHeight)
return self.innerHeight;
// IE 6
if (document.documentElement && document.documentElement.clientHeight)
return document.documentElement.clientHeight;
// IE 5
if (document.body)
return document.body.clientHeight;
// Just in case.
return 0;
}
function handleResize() {
var height = windowHeight() - document.getElementById('toolbar').offsetHeight - 30;
document.getElementById('map').style.height = height + 'px';
document.getElementById('sidebar').style.height = height + 'px';
}
function changeBodyClass(from, to) {
document.body.className = document.body.className.replace(from, to);
return false;
}
function init() {
document.getElementById('button-sidebar-hide').onclick = function() { return changeBodyClass('sidebar-right', 'nosidebar'); };
document.getElementById('button-sidebar-show').onclick = function() { return changeBodyClass('nosidebar', 'sidebar-right'); };
handleResize();
map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
for(id in regions) {
addSideBarItem(regions[id].title, regions[id].code, regionListClickHandler);
}
}
window.onresize = handleResize;
window.onload = init;