Branches = {} /*********** Adding a comment to the file as a test ****************/ /*********** Functions for setting branch detail table****************/ var geocoder, map, qString, place, point; var maxlon,minlon,maxlat,minlat; var infoWindow; var NEIGHBOURHOOD_BRANCH = "Neighbourhood"; var DISTRICT_BRANCH = "District"; var REFERENCE_BRANCH = "Research and Reference"; var BOOKMOBILE = "Bookmobile"; Branches.onPageLoad = function() { Branches.init(); } Branches.clearSearch = function() { location.href = SITE_PAGES + '/hours-locations/'; } Branches.init = function() { qString = Common.getQueryString(); if (qString != null && document.getElementById("map_canvas") != null) { if (google.maps == null) google.load("maps","3", {"other_params":"sensor=false"}); if (document.getElementById('searchType1') != null && document.getElementById('searchType2') != null) { if (qString.indexOf('Ntt=') == -1 || qString.indexOf('Nttb=') > -1) document.getElementById('searchType1').checked = true; } var lat,lng,z; if (document.getElementById("map-one-icon") !=null){ lat = 43.72535; lng = -79.40483; z = 11; } else if (document.getElementById("bookmobiles-left-column") !=null){ lat = 43.7080862; lng = -79.3993254; z = 11; } else { lat = 43.667262962962944; lng = -79.37446666666666; z = 12; }; infoWindow = new google.maps.InfoWindow; infoWindow.setOptions({maxWidth:330}); var myLatlng = new google.maps.LatLng(lat, lng); var myOptions = { zoom: z, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, position: google.maps.ControlPosition.TOP_RIGHT }, panControl: true, panControlOptions: { position: google.maps.ControlPosition.TOP_LEFT }, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE, position: google.maps.ControlPosition.TOP_LEFT } } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); //set geocoder geocoder = new google.maps.Geocoder(); var marker,point; //set markers at library locations for(var i=0; i < branches.length; i++) { point = new google.maps.LatLng(branches[i].latitude, branches[i].longitude); marker = Branches.createMarker(point, branches[i].record_id, branches[i].branch_type,branches[i].name,map); marker.setMap(map); //map.addOverlay(Branches.createMarker(point, branches[i].record_id, branches[i].branch_type,branches[i].name)); } if (branches.length == 1) { map.setCenter(new google.maps.LatLng(branches[0].latitude, branches[0].longitude), 10); map.setZoom(14); } Branches.locate(Common.getKeyValue(Common.getQueryString(), "Nttb")); if (document.getElementById("map-loading")) document.getElementById("map-loading").style.display = "none"; if (document.getElementById("arabic") != null){ OPTIONAL = 1; } } } Branches.search = function() { qString = (qString != '' ? qString + '&' : qString); if (document.getElementById("searchType1").value == "true") { var branch = ""; var address = document.getElementById("locationTerms").value; var bound = new google.maps.LatLngBounds(new google.maps.LatLng(43.58436,-79.62238),new google.maps.LatLng(43.85593,-79.12062)); geocoder.geocode( {'address': address, bounds:bound, region:'CA'}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { setCoordinatesRange(results[0].geometry.location.lat(),results[0].geometry.location.lng()); executeRangeFilterQuery(); } else { alert("Sorry, we were unable to process that address. Please try again."); } }); } else if (document.getElementById("searchType2").checked == true){ executeKeywordQuery(); } } Branches.locate = function(address) { if (address != "") { var bound = new google.maps.LatLngBounds(new google.maps.LatLng(43.58436,-79.62238),new google.maps.LatLng(43.85593,-79.12062)); geocoder.geocode( {'address': address, bounds:bound, region:'CA'}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); map.setZoom(13); var marker = new google.maps.Marker({ position: results[0].geometry.location, map:map }); /* var infowindow = new google.maps.InfoWindow({ content: "Your location: "+results[0].formatted_address, maxWidth: 340 }); */ infoWindow.setContent("Your location: "+results[0].formatted_address); infoWindow.open(map,marker); } else { alert("Geocode was not successful for the following reason: " + status); } }); } } function executeKeywordQuery (){ currQueryString = FilterHandler.removeRangeFilter(); document.forms['searchBranches'].Nf.value=""; document.forms['searchBranches'].Nttb.value=""; document.forms['searchBranches'].submit(); } function executeRangeFilterQuery(){ currQueryString = FilterHandler.removeRangeFilter(); document.forms['searchBranches'].Nttb.value = document.getElementById("locationTerms").value; document.getElementById("locationTerms").value = ""; document.forms['searchBranches'].Nf.value = Common.getKeyValue(currQueryString, "Nf"); document.forms['searchBranches'].submit(); } function setCoordinatesRange(lat, lon){ var D = 5; var R = 6371.009; maxlon = lon + (180/Math.PI)*Math.asin(Math.sin(D/R)/Math.cos(lat*Math.PI/180)); minlon = lon - (180/Math.PI)*Math.asin(Math.sin(D/R)/Math.cos(lat*Math.PI/180)); maxlat = lat + (180/Math.PI)*(D/R); minlat = lat - (180/Math.PI)*(D/R); } function branchesNearBy(branch){ if (branch != ""){ document.forms['searchBranches'].Ntt.value= branch; // use branch ID document.forms['searchBranches'].Ntx.value="mode+matchany"; document.forms['searchBranches'].Ntk.value="p_library_branch"; document.forms['searchBranches'].submit(); } } function distance(lat1, lat2, lon1, lon2) { // Get numeric values out of form elements. var lat_1 = parseFloat(lat1); var lat_2 = parseFloat(lat2); var lon_1 = parseFloat(lon1); var lon_2 = parseFloat(lon2); // Compute spherical coordinates var rho = 6373.0; // earth diameter in kilometers // convert latitude and longitude to spherical coordinates in radians // phi = 90 - latitude var phi_1 = (90.0 - lat_1)*Math.PI/180.0; var phi_2 = (90.0 - lat_2)*Math.PI/180.0; // theta = longitude var theta_1 = lon_1*Math.PI/180.0; var theta_2 = lon_2*Math.PI/180.0; // compute spherical distance from spherical coordinates // arc length = \arccos(\sin\phi\sin\phi'\cos(\theta-\theta') + \cos\phi\cos\phi') // distance = rho times arc length return rho*Math.acos( Math.sin(phi_1)*Math.sin(phi_2)*Math.cos(theta_1 - theta_2) + Math.cos(phi_1)*Math.cos(phi_2) ); } Branches.createMarker = function(point, branchId, branchType, branchName,map) { // Set up our GMarkerOptions object var iconImage; var iconHeight; var iconWidth; var anchor; //The line below checks to see if map-one-icon id exists if it does than it changes all the icons to the larger 24px version if (document.getElementById("map-one-icon") != null){ iconImage = SITE_ROOT + "/images/google/gIcon_reference.png"; iconHeight = 24; iconWidth = 24; anchor = new google.maps.Point(12,12); } else if (branchName.indexOf("Merril") !=-1 | branchName.indexOf("Osborne") !=-1 | branchName.indexOf("Urban Affairs") !=-1) { iconImage = SITE_ROOT + "/images/google/gIcon_neighbourhood.png"; iconHeight = 12; iconWidth = 12; anchor = new google.maps.Point(6,6); } else if(branchType.indexOf(REFERENCE_BRANCH) !=-1) { iconImage = SITE_ROOT + "/images/google/gIcon_reference.png"; iconHeight = 24; iconWidth = 24; anchor = new google.maps.Point(12,12); } else if (branchType.indexOf(DISTRICT_BRANCH) !=-1) { iconImage = SITE_ROOT + "/images/google/gIcon_district.png"; iconHeight = 18; iconWidth = 18; anchor = new google.maps.Point(9,9); } else if(branchType.indexOf(NEIGHBOURHOOD_BRANCH) !=-1) { iconImage = SITE_ROOT + "/images/google/gIcon_neighbourhood.png"; iconHeight = 12; iconWidth = 12; anchor = new google.maps.Point(6,6); } else if(branchType.indexOf(BOOKMOBILE) !=-1) { iconImage = SITE_ROOT + "/images/google/gIcon_bookmobile.png"; iconHeight = 16; iconWidth = 16; anchor = new google.maps.Point(8,8); } else { iconImage = SITE_ROOT + "/images/google/gIcon_neighbourhood.png"; iconHeight = 12; iconWidth = 12; anchor = new google.maps.Point(6,6); } var libraryIcon = new google.maps.MarkerImage(iconImage,new google.maps.Size(iconWidth, iconHeight),new google.maps.Point(0,0), anchor, new google.maps.Size(iconWidth, iconHeight)); var marker = new google.maps.Marker({ position: point, icon: libraryIcon }); /*var infowindow = new google.maps.InfoWindow({ content: Branches.showBranchInfoWindow(branchId), maxWidth: 340 }); */ google.maps.event.addListener(marker, 'click', function() { //Branches.showBranchInfo(branchId); map.panTo(point); infoWindow.setContent(Branches.showBranchInfoWindow(branchId)); infoWindow.open(map,new google.maps.Marker({position: point})); }); return marker; } Branches.showBranchInfoWindow = function(branchId) { var ajaxData = "R=" + branchId; var ajaxResponse = jQuery.ajax({ url: SITE_ROOT + "/components/widget_branch-infowindow.jspf", data: ajaxData, dataType: "html", async: false }).responseText; return ajaxResponse; } Branches.showBranchInfo = function(branchId) { if (document.getElementById('branch-info') != null) { var ajaxData = "R=" + branchId; var ajaxResponse = jQuery.ajax({ url: SITE_ROOT + "/components/widget_branch-infowindow.jspf", data: ajaxData, dataType: "html", async: false }).responseText; document.getElementById('branch-info').innerHTML = ajaxResponse; // Widgets.roundCorners(); } } Branches.onEnter = function(form, evt) { var keyCode = null; if( evt.which ) { keyCode = evt.which; } else if( evt.keyCode ) { keyCode = evt.keyCode; } if( 13 == keyCode ) { Branches.search(); return false; } return true; } Branches.showDetailImage = function(newSrc) { var img = document.getElementById("detail-image"); img.src = newSrc; } Branches.goToBranch = function(latitude,longitude,recordId) { infoWindow.close(); var point = new google.maps.LatLng(latitude,longitude); map.setCenter(point); infoWindow.setContent(Branches.showBranchInfoWindow(recordId)); var marker = new google.maps.Marker({ position: point }); infoWindow.open(map,marker); }