var deselectCurrent = function() {}; function init() { document.getElementById('button_sidebar_hide').onclick = function() { return changeBodyClass('sidebar_right', 'sidebar_off'); }; document.getElementById('button_sidebar_show').onclick = function() { return changeBodyClass('sidebar_off', 'sidebar_right'); }; if (GBrowserIsCompatible()) { var container = document.getElementById("googlemap"); var location = new GLatLng(centerLatitude,centerLongitude); var type; var allTypes = {'All':[]}; // Create and center our base map. map = new GMap2(container, "en_CA"); map.setCenter(location, startZoom); // Directions stuff. gdir = new GDirections(map, document.getElementById("directions")); GEvent.addListener(gdir, "load", onGDirectionsLoad); GEvent.addListener(gdir, "error", handleErrors); // Add controls to our base map. map.addControl(new GSmallZoomControl3D()); map.addControl(new GMapTypeControl()); for(id in markers) { //addMarker(markers[id].latitude, markers[id].longitude, markers[id].icon, markers[id].description); initializePoint(markers[id]); allTypes[markers[id].type]=true; } for(type in allTypes) { initializeSortTab(type); } } } function addMarker(latitude, longitude, icon, description) { var cIcon = new GIcon(); cIcon.image=icon; cIcon.iconsize = GSize(21,31); cIcon.iconAnchor = new GPoint(10,31); cIcon.infoWindowAnchor = new GPoint(10,31); var marker = new GMarker(new GLatLng(latitude, longitude), cIcon); GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(description + '******* test *******'); } ); map.addOverlay(marker); } function initializePoint(pointData) { var visible = false; var point = new GLatLng(pointData.latitude, pointData.longitude); var cIcon = new GIcon(); cIcon.image=pointData.icon; cIcon.iconsize = GSize(21,31); cIcon.iconAnchor = new GPoint(10,31); cIcon.infoWindowAnchor = new GPoint(10,31); var marker = new GMarker(point, cIcon); var listItem = document.createElement('li'); var listItemLink = listItem.appendChild(document.createElement('a')); listItemLink.href = "#"; // This adds to the list of points used as a menu. listItemLink.innerHTML = '
' + pointData.name + '
' + pointData.description + '
' + pointData.telephone + '
'; var focusPoint = function() { deselectCurrent(); listItem.className = 'current'; deselectCurrent = function() { listItem.className = ''; } marker.openInfoWindowHtml('' + pointData.name + '
' + pointData.description + '
' + pointData.telephone); if(document.getElementById('toAddress')) { document.getElementById('toAddress').value=pointData.description; } map.setCenter(point); return false; } GEvent.addListener(marker, 'click', focusPoint); listItemLink.onclick = focusPoint; //document.getElementById('sidebar-list').appendChild(listItem); //map.addOverlay(marker); pointData.show = function() { if (!visible) { document.getElementById('sidebar-list').appendChild(listItem); map.addOverlay(marker); visible = true; } } pointData.hide = function() { if (visible) { document.getElementById('sidebar-list').removeChild(listItem); map.removeOverlay(marker); visible = false; } } pointData.show(); } function initializeSortTab(type) { var listItem = document.createElement('li'); var listItemLink = listItem.appendChild(document.createElement('a')); listItemLink.href = "#"; listItemLink.innerHTML = type; listItemLink.onclick = function() { //changeBodyClass('standby', 'loading'); for(id in markers) { if (markers[id].type == type || 'All' == type) markers[id].show(); else markers[id].hide(); } changeBodyClass('loading', 'standby'); return false; } document.getElementById('filters').appendChild(listItem); } // Function for opening and closing a sidebar or information pane. function changeBodyClass(from, to) { document.body.className = document.body.className.replace(from,to); return false; } // Directions fuctions. function setDirections(fromAddress, toAddress, locale) { gdir.load("from: " + fromAddress + " to: " + toAddress, {"locale": locale}); } function handleErrors() { if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) { alert("No corresponding geographic location could be found for one of the specified addresses."); } else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) { alert("A geocoding or directions request could not be successfully processed."); } else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) { alert("Error code: " + gdir.getStatus().code); } else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) { alert("Error code: " + gdir.getStatus().code); } else { alert("An unknown error occurred."); } } function onGDirectionsLoad() { // Use this function to access information about the latest load() // results. // e.g. // document.getElementById("getStatus").innerHTML = gdir.getStatus().code; // and yada yada yada... } // Initialize the map. window.onload = init; // Prevent memory-leaks in browsers (IE, I am looking at you) window.onunload = GUnload;