summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-05-20 21:43:30 +0100
committerComment <tim@gray.(none)>2013-05-20 21:43:30 +0100
commitce58f84fda93e6089caa5b724110dc7e01feddd1 (patch)
tree5a51419580b33adf219ce6d0073ab9ab390f74b3
parent4f81e9399051cc90ccddeb69b785d7422a28a1ff (diff)
tidying up
-rwxr-xr-xconfig.php9
-rwxr-xr-xmap.js1497
-rwxr-xr-xmap.php51
-rwxr-xr-xmap_prepare.php18
-rwxr-xr-xmaps-extra.js6
-rwxr-xr-x[-rw-r--r--]tableKML.php31
6 files changed, 898 insertions, 714 deletions
diff --git a/config.php b/config.php
index b0fe6ed..bf27e46 100755
--- a/config.php
+++ b/config.php
@@ -1,11 +1,18 @@
<?php
-$host="localhost";
+ $host="localhost";
$login="tcdmaps";
$pword="tcdmaps";
$db="googlemaps_db";
+
/*
+$host="wwwdb.tcd.ie";
+$login="gmaps";
+$pword="xpehtWpR";
+$db="googlemaps_db";
+
+
$host="internal-db.s65888.gridserver.com";
$login="db65888_tcd";
$pword="3K4DumV3";
diff --git a/map.js b/map.js
index 748e9ae..169a0ee 100755
--- a/map.js
+++ b/map.js
@@ -1,682 +1,815 @@
-//tool to update dataase: display markers and edit positions
-//http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
-//nb in google maps it says "DIT" in the middle of the provost's stables
-/*
-showPlaces(type)
-showPlace(index)
-
-
-
-*/
-//------------------------------------------------------------------------globals
-var http = getHTTPObject(); //old ajax method
-var markers=[];
-var markertypes=['Building','Parking','Entrances']; //--lat/lng based tables to create markers
-var tables=[];
-var tablenames=['AZ','Lecture_theatres','Pacr','Libraries','Loops','Enabled_toilets']; //--tables reference building table
-var tablescreennames={'Lecture_theatres':"Lecture theatres",'Pacr':"Public access computer rooms",'Libraries':"Libraries",'Loops':"Hearing aid looops",'Enabled_toilets':"Enabled toilets"};
-var icontypes=['Loops','Enabled_toilets'];
-var places=[];
-var placetypes=new Array('Lecture_theatres','Libraries','Pacr');
-var screenplacetypes=new Array('Lecture theatres','Libraries','Public access computer rooms');
-for (i=0;i<placetypes.length;i++) {
- places[placetypes[i]]=[];
- places[placetypes[i]].screenname=screenplacetypes[i];
-}
-var popularplaces=[56,59,198];
-var popularnames=["Old Library","Campanile","Samuel Beckett Theatre"];
-var mainCampus=new G.LatLngBounds(new G.LatLng(53.34,-6.26),new G.LatLng(53.346,-6.2499));
-var show_parking_warning=true;
-var InfoWindow; //points to created infowindows
-
-var directionsService;
-var directionsDisplay;
-
-var do_menu_flag = false;
-//------------------------------------------------------------------------classes
-function place(name,building,info) {
- //represents an entity that can appear in a menu
- this.name=name;
- this.building=building;
- this.info=info;
-}
-//------------------------------------------------------------------------startup
-//NB alert doesn't work within a jquery callback but console.log does
-function onLoad() {
- if(document.getElementById("map")) {
- var mapOptions = {
- center: STARTPOS,
- zoom: 17,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- map = new G.Map(document.getElementById("map"),mapOptions);
- directionsService = new G.DirectionsService();
- directionsDisplay = new G.DirectionsRenderer({Map:map});
- //load data via ajax - chaining other loading functions
- loadTables(tablenames);
-
- }
-}
-function loadTables(t) {
- t.forEach(function(table) {
- $.getJSON("./loadTable.php","table="+table,function(d) {
- $.each(d, function(idx,v) {
- tables[idx]=[];
- for (i in v) {
- tables[idx].push(v[i]);
- }
- if (DEBUG) console.log("loaded table "+Object.keys(tables).length+":"+idx+","+tables[idx].length+" items");
- if (Object.keys(tables).length==tablenames.length) loadMarkers(markertypes);
- });
- });
- });
-}
-//how to know when everything is loaded via ajax and data can be processed
-function loadMarkers(m) { //---------build customised markers from a database table
- m.forEach(function(marker) {
- $.getJSON("./loadTable.php","table="+marker,function(d) {
- $.each(d, function(idx,v) {
- markers[idx]=[];
- for (i in v) {
- markers[idx][i]=makeMarker(v[i],idx);
- //console.log("making "+i+": "+
- }
- markers[idx].visible=false;
- if (DEBUG) console.log("loaded markers "+Object.keys(markers).length+":"+idx+","+markers[idx].length+" items");
- if (Object.keys(markers).length==markertypes.length) {
- prepareData();
- do_menuchoices();
- console.log("search:"+search_posted);
- if (search_posted!="") onsearch(search_posted);
- }
- });
- });
- });
-}
-function makeMarker(data,type) {
- if (DEBUG) console.log(type+":"+data['lat']+","+data['lng']); //alert doesn't work within a jquery callback but console.log does
- var m=new G.Marker({position:new G.LatLng(data['lat'],data['lng']),map:null,draggable:EDITABLE});
- m["type"]=type;
- for (j in data) m[j]=data[j];
- m.places=[];
- m.tabVisible=false;
- m.visible=false;
- if (EDITABLE){
- G.event.addListener(m,"dragend",setMarkerPosition);
- G.event.addListener(m,"click",displayMarkerInfo);
- if (type=="Building"&&m.google_coords==1) {
- m.setIcon(new G.MarkerImage("http://maps.google.com/mapfiles/marker_orange.png"));
- }
- }
- switch (type) {
- case "Parking":
- m.setIcon(new G.MarkerImage("img/marker_parking.png"));
- break;
- case 'Entrances':
- m.setIcon(new G.MarkerImage("img/marker_entrance.png"));
- break;
- case 'Loops':
- m.setIcon(new G.MarkerImage("img/marker_loop.png"));
- break;
- case 'Enabled_toilets':
- m.setIcon(new G.MarkerImage("img/marker_accessible_toilet.png"));
- break;
- case 'Ramps':
- m.setIcon(new G.MarkerImage("img/marker_ramp.png"));
- break;
- default:
- break;
- }
- m.setShadow(new G.MarkerImage("img/marker_shadow.png",new G.Size(30,30),new G.Point(0,0),new G.Point(6,29)));
- if (type=="Building") {
- m.sortPlaces=function() {m.places.sort(function(a,b) {if (a.name<b.name) return -1; else return 1; }); }
- m.show = function (tab){
- if (!this.visible) {
- this.dispphoto=httpexists("./photos/small/"+this.id+".jpg");
- if (this.places.length>1||this.description) { //multi-tab
- this.showtab = function() {
- purgeInfoWindow();
- InfoWindow=new InfoBubble({disableAnimation:true});
- InfoWindow.addTab('Building',this.getPlacesTab());
- InfoWindow.addTab('More',this.getInfoTab());
- InfoWindow.open(map,this);
- this.tabVisible=true;
- }
- } //single tab
- else {
- this.showtab = function() {
- purgeInfoWindow();
- InfoWindow=new InfoBubble({content:this.getPlacesTab(),disableAnimation:true});;
- InfoWindow.open(map,this);
- this.tabVisible=true;
- }
- }
- G.event.addListener(this,"click",this.showtab);
- this.setMap(map);
- var boundscheck=map.getBounds();
- if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
- {
- boundscheck.extend(this.getPosition());
- var newzoom = getZoomByBounds( map, boundscheck );
- map.setZoom(newzoom);
- map.setCenter(boundscheck.getCenter());
-
- }
- this.visible=true;
- }
- if (tab) this.showtab();
- }
- }
- if (type=="Entrances") { //construct tabs
- m.show = function (tab){
- this.showtab = function() {
- purgeInfoWindow();
- InfoWindow=new InfoBubble({content:this.getEntranceTab(),disableAnimation:true});
- InfoWindow.open(map,this);
- this.tabVisible=true;
- }
- G.event.addListener(this,"click",this.showtab);
- this.setMap(map);
- var boundscheck=map.getBounds();
- if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
- {
- boundscheck.extend(this.getPosition());
- var newzoom = getZoomByBounds( map, boundscheck );
- if (newzoom<15) map.setMapType(G_NORMAL_MAP);
- map.setZoom(newzoom);
- map.setCenter(boundscheck.getCenter());
- }
- this.visible=true;
- if (tab) this.showtab();
- }
- }
- if (type=="Enabled_toilets") { //construct tabs
- m.show = function (tab){
- if (this.data !="") {
- this.showtab = function() {
- purgeInfoWindow();
- InfoWindow=new InfoBubble({content:this.getToiletTab(),disableAnimation:true});
- InfoWindow.open(map,this);
- this.tabVisible=true;
- }
- }
- G.event.addListener(this,"click",this.showtab);
- this.setMap(map);
- var boundscheck=map.getBounds();
- if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
- {
- boundscheck.extend(this.getPosition());
- var newzoom = getZoomByBounds( map, boundscheck );
- if (newzoom<15) map.setMapType(G_NORMAL_MAP);
- map.setZoom(newzoom);
- map.setCenter(boundscheck.getCenter());
- }
- this.visible=true;
- if (tab) this.showtab();
- }
- }
- if (type=="Loops"||type=="Parking") {
- m.show = function (tab){
- this.setMap(map);
- var boundscheck=map.getBounds();
- if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
- {
- boundscheck.extend(this.getPosition());
- var newzoom = getZoomByBounds( map, boundscheck );
- if (newzoom<15) map.setMapType(G_NORMAL_MAP);
- map.setZoom(newzoom);
- map.setCenter(boundscheck.getCenter());
- }
- this.visible=true;
- }
- }
- m.hide = function() {
- if (!(this.type=="Loops"||this.type=="Parking")) {
- G.event.clearListeners(this,"click");
- }
- if (this.tabVisible) {
- purgeInfoWindow();
- this.tabVisible=false;
- }
- this.visible=false;
- this.setMap(null);
- }
- m.getPlacesTab=getPlacesTab;
- m.getInfoTab=getInfoTab;
- m.getEntranceTab=getEntranceTab;
- m.getToiletTab=getToiletTab;
- return m;
-}
-//----------------------------------------------------------------------------------functions to populate tabs called from marker
-function getPlacesTab() {
- var popup="<div id='map_building'><h4>"+this.name+"</h4>";
- popup+="<div id='map_building_inner'>";
- if (this.dispphoto) {
- popup+="<div id='map_building_photo'>";
- popup+="<a href='javascript:shadowbox("+this.id+")'><img src='./photos/small/"+this.id+".jpg' style='display:block'; width='40%'; height='40%'></a>";
- popup+="</div>";
- }
- if (this.opening_hours) {
- popup+="<div id='map_building_opening_hours'>";
- popup +='<h5>Building Opening Hours:</h5>';
- popup +='<div>'+this.opening_hours+"</div>";
- popup+="</div>";
- }
- if ((this.accessibility)||(this.accessibility_url)) {
- popup+="<div id='map_building_access'>";
- if (this.accessibility) {
- popup+="<h5>Accessibility: </h5><div>"+this.accessibility+" ";
- if (this.accessibility_url) popup+="(<a href='http://www.tcd.ie/disability/accessibility/Building-check/"+this.accessibility_url+"'>more&nbsp;info</a>)</div>";
-
- }
- else if (this.accessibility_url) popup+="<div><a href='http://www.tcd.ie/disability/accessibility/Building-check/"+this.accessibility_url+"'>Accessibility&nbsp;info</a></div>";
- popup+="</div>";
- }
- popup+="</div>";
-
- popup+="<div id='map_building_permalink'>";
- var linkname;
- linkname=this.name;
- popup+="<a href='map.php?q="+urlencode(linkname)+"' >Permalink</a>";
- lat=this.getPosition().lat();
- lng=this.getPosition().lng();
-
- if (!mainCampus.contains(this.getPosition())) {
- bd='"'+urlencode(this.name)+'"';
- popup+=" <a href='javascript:directions("+lat+","+lng+","+bd+")'>Directions</a> ";
- }
- popup+="</div>";
-
- return popup;
-}
-function getInfoTab() {
- popup="";
- popup+="<div id='map_info'>";
- popup+="<div id='map_info_inner'><bd>"; //<div id='map_popup_inner'>";
- var placeoffset=0;
- if (this.places.length-placeoffset) {
- popup+="<h4>Also in this building</h4><ul>";
- for (i=0;i<this.places.length;i++) {
- if (this.places[i].name) {
- if (this.places[i].info.match(/^\s*http/)) {
- popup +="<li><a href='"+this.places[i].info+"'>"+this.places[i].name+"</a></li>";
- }
- else {
- popup +="<li>"+this.places[i].name+"</li>";
- }
- }
- }
- popup+="</ul>";
- }
- if (this.description) popup+="<h4>Info</h4>"+this.description;
- popup+="</bd></div></div>";
- return popup;
-}
-function getToiletTab() {
- popup="";
- popup+="<div id='map_toilettab'>";
- popup+="<div id='map_toilettab_inner'><bd>";
- popup+="<h4>Enabled toilet</h4>"
- popup+="<br>"+this.data;
- popup+="</bd></div></div>";
- return popup;
-}
-function getEntranceTab() {
- popup="";
- popup+="<div id='map_entrancetab'>";
- popup+="<div id='map_entrancetab_inner'><bd>";
- popup+="<h4>Entrance</h4>"
- popup+="<br> "+this.data;
- popup+="</bd></div></div>";
- return popup;
-}
-//----------------------------------------------------------------------------------Setting up data structures while loading
-function prepareData() {
- //create markers for ref tables
- for (i in icontypes) {
- markers[icontypes[i]]=[];
- for (t in tables[icontypes[i]]) {
- //console.log("building "+tables[icontypes[i]][t].building+":"+markers["Building"][tables[icontypes[i]][t].building].name);
- tables[icontypes[i]][t].lat=markers["Building"][tables[icontypes[i]][t].building].lat;
- tables[icontypes[i]][t].lng=markers["Building"][tables[icontypes[i]][t].building].lng;
- tables[icontypes[i]][t].id=tables[icontypes[i]][t].building;
- markers[icontypes[i]].push(makeMarker(tables[icontypes[i]][t],icontypes[i]));
- }
-
- markers[icontypes[i]].visible=false;
- }
- //process Building and AZ tables
- //create AZ -- is causing problems now for some reason WHERE THERE ARE NO ITEMS
- for (var i=0;i<26;i++) {
- tables[String.fromCharCode(i+65)]=[];
- tables[String.fromCharCode(i+65)].screenname=String.fromCharCode(i+65);
- }
- //Create alphabetical lists of places including exceptions
- for (var i=0;i<tables["AZ"].length;i++)
- {
- if (tables["AZ"][i].info=="") tables["AZ"][i].info=tables["AZ"][i].name;
-
- var j=0;
- var startlet=0;
-
- while (tables["AZ"][i].name.charCodeAt(j) <64) j++; //find 1st non-number
-
- startlet=tables["AZ"][i].name.charCodeAt(j) -65;
- if (startlet>25) startlet-=32; //select small letters (which shouldn't even be there)
-
- if ((startlet==96)||(startlet==128)) startlet=0; //catch Á
- if (startlet==104) startlet=4; //catch É
- if (startlet==108) startlet=8; //catch Í
-
- //find array number of building index as buildingindex number can be non-consecutive
- var bb=tables["AZ"][i].building;
- for (j in markers['Building'])
- {
- if (markers['Building'][j].id==bb) {
- numplaces=tables[String.fromCharCode(startlet+65)].length;
- tables[String.fromCharCode(startlet+65)].push(tables["AZ"][i]); //add reference to place
- tables[String.fromCharCode(startlet+65)][numplaces].building=j; //resolve reference to building array
- tables[String.fromCharCode(startlet+65)][numplaces].index=i; //resolve reference to AZ array
- markers['Building'][j].places.push(tables["AZ"][i]);
- }
- }
-
- if (tables["AZ"][i].name.slice(0,3)=="St.")
- {
- startlet=tables["AZ"][i].name.charCodeAt(4) -65;
- if (startlet>25) startlet-=32; //select small letters
- //we know its doesn't start with ÁÉÍ
- for (j in markers['Building'])
- {
- if (markers['Building'][j].id==bb) {
- numplaces=tables[String.fromCharCode(startlet+65)].length;
- tables[String.fromCharCode(startlet+65)].push(tables["AZ"][i]); //add reference to place
- tables[String.fromCharCode(startlet+65)][numplaces].building=j; //resolve reference to building array
- markers['Building'][j].places.push(tables["AZ"][i]);
- }
- }
- }
- }
- //add buildings
- for (i in markers['Building'])
- {
- if (markers['Building'][i].name) { //trap added 'visible' property
- var j=0;
- var startlet=0;
-
- while (markers['Building'][i].name.charCodeAt(j) <64) j++; //find 1st non-number
-
- startlet=markers['Building'][i].name.charCodeAt(j) -65;
- if (startlet>25) startlet-=32; //select small letters (which shouldn't even be there)
-
- if ((startlet==96)||(startlet==128)) startlet=0; //catch Á
- if (startlet==104) startlet=4; //catch É
- if (startlet==108) startlet=8; //catch Í
-
- numplaces=tables[String.fromCharCode(startlet+65)].length;
- tables[String.fromCharCode(startlet+65)].push(new place(markers['Building'][i].name,i,markers['Building'][i].info));
- tables[String.fromCharCode(startlet+65)][numplaces].building=i; //resolve reference to building array
- }
-
- }
- //sort results alphabetically
- for (i=0;i<26;i++) {
- letter=String.fromCharCode(i+65);
- tables[letter].sort(function(a,b) { if (a.name<b.name) return -1; else return 1;});
- }
- //resolve other tables references
- places.forEach(function(placetable) {
- for (j=0;j<placetable.length;j++) {
- for (k=0; k<markers['Building'].length;k++)
- if (placetable[j].building==markers['Building'][k].num) {
- placetable[j].building=k; //resolve reference to building array
- break;
- }
- }
- placetable.sort(function(a,b) {if (a.name<b.name) return -1; else return 1; });
-
- });
- //create html popups
- for (i in markers['Building']) {
- if (markers['Building'][i].name) {
- markers['Building'][i].sortPlaces();
- }
- }
- for (t in tables) tables[t].screenname=tablescreennames[t];
-}
-function do_menuchoices() {
- var menu="<ul>";
- for (var i=0;i<26;i++) {
- letter=String.fromCharCode(i+65);
- menu+="<li><a href='javascript:do_menu(\""+letter+"\");'>"+letter+" </a></li>";
- }
- menu+="</ul>";
- document.getElementById("searchoptions").innerHTML=menu;
- //action='map.php'
- menu="<form id='form' method='POST' action='javascript:void(0);' onsubmit='quicklink(this.childNodes[0].childNodes[1]);return false'><div><label for='quicklinks'>Quicklinks: </label><select name='quicklinks' id='quicklinks'><option selected='selected'>Search for lectures, libraries, pacr...</option>";
- for (i=0;i<placetypes.length;i++) menu+="<option value='"+placetypes[i]+"'>"+screenplacetypes[i]+"</option>";
- menu+="</select> <input type='submit' value='Go' /></form>";
- document.getElementById("quicklinkswrap").innerHTML=menu;
-}
-//----------------------------------------------------------------------------------Editing markers while authoring
-function setMarkerPosition() {
- if (this.type=="Building") {
- $.ajax({
- url:"setMarkerPos.php",
- data: "table="+this.type+"&id="+this.id+"&lat="+this.getPosition().lat()+"&lng="+this.getPosition().lng()+"&google_coords=1"
- });
- this.setIcon(new G.MarkerImage("http://maps.google.com/mapfiles/marker_orange.png") );
- }
- else {
- $.ajax({
- url:"setMarkerPos.php",
- data: "table="+this.type+"&id="+this.id+"&lat="+this.getPosition().lat()+"&lng="+this.getPosition().lng()
- });
- }
-}
-function displayMarkerInfo(){
- if (this.type=="Building") document.getElementById("info").innerHTML=this.id+": "+this.name;
- else document.getElementById("info").innerHTML=this.id;
-}
-//----------------------------------------------------------------------------------Interaction handlers
-function shadowbox(n) {
- Shadowbox.open({content:"./photos/"+n+".jpg",player: "img",title:markers['Building'][n].name});
-}
-function onsearch(query) {
- tables["search"]=[];
- var foundbuildings=new Array();
- fb=0;
- for (var i=0;i<26;i++) {
- //console.log("checking "+String.fromCharCode(i+65));
- for (j in tables[String.fromCharCode(i+65)]) {
-
-
- if (tables[String.fromCharCode(i+65)][j]!=undefined) {
- //console.log("checking "+j+": "+tables[String.fromCharCode(i+65)][j].name);
-
- if ("name" in tables[String.fromCharCode(i+65)][j]) {
- if (tables[String.fromCharCode(i+65)][j].name.toLowerCase().indexOf(query.toLowerCase())>-1) {
- tables["search"].push(tables[String.fromCharCode(i+65)][j]);
- if (foundbuildings[tables[String.fromCharCode(i+65)][j].building]!="1") fb++;
- foundbuildings[tables[String.fromCharCode(i+65)][j].building]="1";
- }
- }
-
- }
-
- }
- }
- //auto-open if 1 search result
- if (fb==1) {
- clearmarkers();
- markers["Building"][tables["search"][0].building].show(true,tables["search"][0]);
- }
- tables["search"].screenname=query;
- tables["search"].sort(function(a,b) {if (a.name<b.name) return -1; else return 1; });
- do_menu("search");
-}
-function show_markers(type) {
- if (DEBUG) console.log("showing "+type);
- if (!markers[type].visible) {
- for(i in markers[type]) {
- if (markers[type][i].id) {
- markers[type][i].show();
- }
- }
- }
- else {
- for(i in markers[type]) {
- if (markers[type][i].id) {
- markers[type][i].hide();
- }
- }
- }
-
- markers[type].visible=!markers[type].visible;
-}
-function show_place(type,index) {
- show_building(tables[type][index].building);
-}
-function show_building(index) { //funnel through here
- markers['Building'][index].show(true);
-}
-function quicklink(owner) {
- name=owner.options[owner.selectedIndex].value;
- for (i=1;i<markertypes.length;i++) if (name==markertypes[i]) show_markers(name);
- for (i=0;i<placetypes.length;i++) if (name==placetypes[i]) do_menu(name);
- resize_map_and_results();
-}
-function do_menu(type) {
- var title="<h1>"+tables[type].length+" results for ";
- if (type.length==1) title+="letter ";
- if (tables[type].screenname) {
- title+=tables[type].screenname;
- }
- else {
- title+=type;
- }
- title+="</h1>";
- if (DEBUG) console.log("doing menu: "+type);
- if (DEBUG) console.log(tables[type].length+" items");
- if(document.getElementById("searchresulttitle")) {
- document.getElementById("searchresulttitle").innerHTML=title;
- var content="<ul>";
- for(var i=0;i<tables[type].length;i++) {
- content+="<li><a href='javascript:show_place(\""+type+"\","+i+"); '>"+tables[type][i].name+"</a></li>";
- }
- content+="</ul>";
- document.getElementById("searchresults").innerHTML=content;
- if(do_menu_flag) {
- resize_map_and_results();
- }
- else {
- do_menu_flag = true;
- }
- if (DEBUG) alert(content);
- }
-}
-function purgeInfoWindow() {
- if (InfoWindow) {
- //console.log("closing infowindow");
- InfoWindow.close();
- InfoWindow=undefined;
- }
-}
-function clearmarkers() {
- for (i in markers) {
- for (j in markers[i]) {
- if (markers[i][j].name) markers[i][j].hide;
- }
- }
-}
-function directions(lat,lng,place){
- document.getElementById("searchresulttitle").innerHTML="<h1>From Trinity College to "+place+"</h1>";
- document.getElementById("searchresults").innerHTML="";
- var request = {
- origin:new G.LatLng(53.3445,-6.259),
- destination:new G.LatLng(lat,lng),
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- };
- directionsDisplay.setPanel(document.getElementById("searchresults"));
- directionsService.route(request, function(response, status) {
- if (status == G.DirectionsStatus.OK) {
- directionsDisplay.setDirections(response);
- }
- });
-}
-//----------------------------------------------------------------------------------misc utils, legacy ajax stuff to bypass TCD fuzzy filename filter
-//Equivalent of getBoundsZoomLevel() in gmaps api 3
-/**
-* Returns the zoom level at which the given rectangular region fits in the map view.
-* The zoom level is computed for the currently selected map type.
-* @param {google.maps.Map} map
-* @param {google.maps.LatLngBounds} bounds
-* @return {Number} zoom level
-**/
-function getZoomByBounds( map, bounds ){
- var MAX_ZOOM = map.mapTypes.get( map.getMapTypeId() ).maxZoom || 21 ;
- var MIN_ZOOM = map.mapTypes.get( map.getMapTypeId() ).minZoom || 0 ;
-
- var ne= map.getProjection().fromLatLngToPoint( bounds.getNorthEast() );
- var sw= map.getProjection().fromLatLngToPoint( bounds.getSouthWest() );
-
- var worldCoordWidth = Math.abs(ne.x-sw.x);
- var worldCoordHeight = Math.abs(ne.y-sw.y);
-
- //Fit padding in pixels
- var FIT_PAD = 40;
-
- for( var zoom = MAX_ZOOM; zoom >= MIN_ZOOM; --zoom ){
- if( worldCoordWidth*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).width() &&
- worldCoordHeight*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).height() )
- return zoom;
- }
- return 0;
-}
-function urlencode (string) {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
-
- for (var n = 0; n < string.length; n++) {
-
- var c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
-
- }
-
- return escape(utftext);
-}
-function httpexists(url) {
- exists=false;
- http.open("GET",'httpexists-proxy.php?httpexistsurl=' + url, false);
- //http.open("GET", url, false);
- http.send(null);
- if (http.status == 200) {
- exists=true;
- }
- return exists;
-}
-function getHTTPObject() {
- var xmlhttp;
- if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
- try {
- xmlhttp = new XMLHttpRequest();
- } catch (e) {
- xmlhttp = false;
- }
- }
- return xmlhttp;
-}
-
+//tool to update dataase: display markers and edit positions
+//http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
+//nb in google maps it says "DIT" in the middle of the provost's stables
+/*
+showPlaces(type)
+showPlace(index)
+
+Tim Redfern: 20-05-13 -->
+added static display of 'popular places'
+switched permalinks to index by number
+
+*/
+//------------------------------------------------------------------------globals
+var http = getHTTPObject(); //old ajax method
+var markers=[];
+var markertypes=['Building','Parking','Entrances']; //--lat/lng based tables to create markers
+var tables=[];
+var tablenames=['AZ','Lecture_theatres','Pacr','Libraries','Loops','Enabled_toilets']; //--tables reference building table
+var tablescreennames={'Lecture_theatres':"Lecture theatres",'Pacr':"Public access computer rooms",'Libraries':"Libraries",'Loops':"Hearing aid looops",'Enabled_toilets':"Enabled toilets"};
+var icontypes=['Loops','Enabled_toilets'];
+var places=[];
+var placetypes=new Array('Lecture_theatres','Libraries','Pacr');
+var screenplacetypes=new Array('Lecture theatres','Libraries','Public access computer rooms');
+for (i=0;i<placetypes.length;i++) {
+ places[placetypes[i]]=[];
+ places[placetypes[i]].screenname=screenplacetypes[i];
+}
+var popularplaces=[56,59,198];
+var popularnames=["Old Library","Campanile","Samuel Beckett Theatre"];
+var mainCampus=new G.LatLngBounds(new G.LatLng(53.34,-6.26),new G.LatLng(53.346,-6.2499));
+var show_parking_warning=true;
+var InfoWindow; //points to created infowindows
+
+var directionsService;
+var directionsDisplay;
+
+var do_menu_flag = false;
+//------------------------------------------------------------------------classes
+function place(name,building,info) {
+ //represents an entity that can appear in a menu
+ this.name=name;
+ this.building=building;
+ this.info=info;
+}
+//------------------------------------------------------------------------startup
+//NB alert doesn't work within a jquery callback but console.log does
+
+
+// DS added backwards compatibility for browsers that do not natively support String.contains, Array.map and Object.keys
+// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/array/map
+// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/string/contains
+if(!('contains' in String.prototype)) {
+ String.prototype.contains = function(str, startIndex) { return -1!==this.indexOf(str, startIndex); };
+}
+if (!Object.keys) {
+ Object.keys = (function () {
+ var hasOwnProperty = Object.prototype.hasOwnProperty,
+ hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
+ dontEnums = [
+ 'toString',
+ 'toLocaleString',
+ 'valueOf',
+ 'hasOwnProperty',
+ 'isPrototypeOf',
+ 'propertyIsEnumerable',
+ 'constructor'
+ ],
+ dontEnumsLength = dontEnums.length;
+
+ return function (obj) {
+ if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');
+
+ var result = [];
+
+ for (var prop in obj) {
+ if (hasOwnProperty.call(obj, prop)) result.push(prop);
+ }
+
+ if (hasDontEnumBug) {
+ for (var i=0; i < dontEnumsLength; i++) {
+ if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
+ }
+ }
+ return result;
+ }
+ })()
+};
+// Production steps of ECMA-262, Edition 5, 15.4.4.18
+// Reference: http://es5.github.com/#x15.4.4.18
+if ( !Array.prototype.forEach ) {
+
+ Array.prototype.forEach = function forEach( callback, thisArg ) {
+
+ var T, k;
+
+ if ( this == null ) {
+ throw new TypeError( "this is null or not defined" );
+ }
+
+ // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
+ var O = Object(this);
+
+ // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
+ // 3. Let len be ToUint32(lenValue).
+ var len = O.length >>> 0; // Hack to convert O.length to a UInt32
+
+ // 4. If IsCallable(callback) is false, throw a TypeError exception.
+ // See: http://es5.github.com/#x9.11
+ if ( {}.toString.call(callback) !== "[object Function]" ) {
+ throw new TypeError( callback + " is not a function" );
+ }
+
+ // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ if ( thisArg ) {
+ T = thisArg;
+ }
+
+ // 6. Let k be 0
+ k = 0;
+
+ // 7. Repeat, while k < len
+ while( k < len ) {
+
+ var kValue;
+
+ // a. Let Pk be ToString(k).
+ // This is implicit for LHS operands of the in operator
+ // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
+ // This step can be combined with c
+ // c. If kPresent is true, then
+ if ( Object.prototype.hasOwnProperty.call(O, k) ) {
+
+ // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
+ kValue = O[ k ];
+
+ // ii. Call the Call internal method of callback with T as the this value and
+ // argument list containing kValue, k, and O.
+ callback.call( T, kValue, k, O );
+ }
+ // d. Increase k by 1.
+ k++;
+ }
+ // 8. return undefined
+ };
+}
+
+// DS changed to declare map globally to avoid issue in IE8
+//http://stackoverflow.com/questions/10729421/what-is-causing-a-google-maps-error-in-ie8
+var map;
+
+// DS using DOM onload instead of window.onload
+$(function() {
+
+ var mapEl = document.getElementById("map");
+ if(mapEl) {
+ var mapOptions = {
+ center: STARTPOS,
+ zoom: 17,
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+
+ map = new google.maps.Map(document.getElementById("map"), mapOptions);
+ directionsService = new G.DirectionsService();
+ directionsDisplay = new G.DirectionsRenderer({Map:map});
+ //load data via ajax - chaining other loading functions
+ loadTables(tablenames);
+
+ }
+ callback_for_resizing();
+});
+function loadTables(t) {
+ t.forEach(function(table) {
+ $.getJSON("./loadTable.php","table="+table,function(d) {
+ $.each(d, function(idx,v) {
+ tables[idx]=[];
+ for (i in v) {
+// DS to account for forEach polyfill
+ if (i != 'foreach') {
+ tables[idx].push(v[i]);
+ }
+ }
+ if (DEBUG) console.log("loaded table "+Object.keys(tables).length+":"+idx+","+tables[idx].length+" items");
+ if (Object.keys(tables).length==tablenames.length) loadMarkers(markertypes);
+ });
+ });
+ });
+}
+//how to know when everything is loaded via ajax and data can be processed
+function loadMarkers(m) { //---------build customised markers from a database table
+ m.forEach(function(marker) {
+ $.getJSON("./loadTable.php","table="+marker,function(d) {
+ $.each(d, function(idx,v) {
+ markers[idx]=[];
+ for (i in v) {
+// DS to account for forEach polyfill
+ if (i != 'foreach') {
+ markers[idx][i]=makeMarker(v[i],idx);
+ //console.log("making "+i+": "+
+ }
+ }
+ markers[idx].visible=false;
+ if (DEBUG) console.log("loaded markers "+Object.keys(markers).length+":"+idx+","+markers[idx].length+" items");
+ if (Object.keys(markers).length==markertypes.length) {
+ prepareData();
+ do_menuchoices();
+ //console.log("search:"+search_posted);
+ if (search_posted!="") onsearch(search_posted);
+ }
+ });
+ });
+ });
+}
+function makeMarker(data,type) {
+ if (DEBUG) console.log(type+":"+data['lat']+","+data['lng']); //alert doesn't work within a jquery callback but console.log does
+ var m=new G.Marker({position:new G.LatLng(data['lat'],data['lng']),map:null,draggable:EDITABLE});
+ m["type"]=type;
+ for (j in data) m[j]=data[j];
+ m.places=[];
+ m.tabVisible=false;
+ m.visible=false;
+ if (EDITABLE){
+ G.event.addListener(m,"dragend",setMarkerPosition);
+ G.event.addListener(m,"click",displayMarkerInfo);
+ if (type=="Building"&&m.google_coords==1) {
+ m.setIcon(new G.MarkerImage("http://maps.google.com/mapfiles/marker_orange.png"));
+ }
+ }
+ switch (type) {
+ case "Parking":
+ m.setIcon(new G.MarkerImage("img/marker_parking.png"));
+ break;
+ case 'Entrances':
+ m.setIcon(new G.MarkerImage("img/marker_entrance.png"));
+ break;
+ case 'Loops':
+ m.setIcon(new G.MarkerImage("img/marker_loop.png"));
+ break;
+ case 'Enabled_toilets':
+ m.setIcon(new G.MarkerImage("img/marker_accessible_toilet.png"));
+ break;
+ case 'Ramps':
+ m.setIcon(new G.MarkerImage("img/marker_ramp.png"));
+ break;
+ default:
+ break;
+ }
+ m.setShadow(new G.MarkerImage("img/marker_shadow.png",new G.Size(30,30),new G.Point(0,0),new G.Point(6,29)));
+ if (type=="Building") {
+ m.sortPlaces=function() {m.places.sort(function(a,b) {if (a.name<b.name) return -1; else return 1; }); }
+ m.show = function (tab){
+ if (!this.visible) {
+ this.dispphoto=httpexists("./photos/small/"+this.id+".jpg");
+ if (this.places.length>1||this.description) { //multi-tab
+ this.showtab = function() {
+ purgeInfoWindow();
+ InfoWindow=new InfoBubble({disableAnimation:true});
+ InfoWindow.addTab('Building',this.getPlacesTab());
+ InfoWindow.addTab('More',this.getInfoTab());
+ InfoWindow.open(map,this);
+ this.tabVisible=true;
+ }
+ } //single tab
+ else {
+ this.showtab = function() {
+ purgeInfoWindow();
+ InfoWindow=new InfoBubble({content:this.getPlacesTab(),disableAnimation:true});;
+ InfoWindow.open(map,this);
+ this.tabVisible=true;
+ }
+ }
+ G.event.addListener(this,"click",this.showtab);
+ this.setMap(map);
+ var boundscheck=map.getBounds();
+ if (boundscheck && (!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
+ {
+ boundscheck.extend(this.getPosition());
+ var newzoom = getZoomByBounds( map, boundscheck );
+ map.setZoom(newzoom);
+ map.setCenter(boundscheck.getCenter());
+
+ }
+ this.visible=true;
+ }
+ if (tab) this.showtab();
+ }
+ }
+ if (type=="Entrances") { //construct tabs
+ m.show = function (tab){
+ this.showtab = function() {
+ purgeInfoWindow();
+ InfoWindow=new InfoBubble({content:this.getEntranceTab(),disableAnimation:true});
+ InfoWindow.open(map,this);
+ this.tabVisible=true;
+ }
+ G.event.addListener(this,"click",this.showtab);
+ this.setMap(map);
+ var boundscheck=map.getBounds();
+ if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
+ {
+ boundscheck.extend(this.getPosition());
+ var newzoom = getZoomByBounds( map, boundscheck );
+ if (newzoom<15) map.setMapType(G_NORMAL_MAP);
+ map.setZoom(newzoom);
+ map.setCenter(boundscheck.getCenter());
+ }
+ this.visible=true;
+ if (tab) this.showtab();
+ }
+ }
+ if (type=="Enabled_toilets") { //construct tabs
+ m.show = function (tab){
+ if (this.data !="") {
+ this.showtab = function() {
+ purgeInfoWindow();
+ InfoWindow=new InfoBubble({content:this.getToiletTab(),disableAnimation:true});
+ InfoWindow.open(map,this);
+ this.tabVisible=true;
+ }
+ }
+ G.event.addListener(this,"click",this.showtab);
+ this.setMap(map);
+ var boundscheck=map.getBounds();
+ if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
+ {
+ boundscheck.extend(this.getPosition());
+ var newzoom = getZoomByBounds( map, boundscheck );
+ if (newzoom<15) map.setMapType(G_NORMAL_MAP);
+ map.setZoom(newzoom);
+ map.setCenter(boundscheck.getCenter());
+ }
+ this.visible=true;
+ if (tab) this.showtab();
+ }
+ }
+ if (type=="Loops"||type=="Parking") {
+ m.show = function (tab){
+ this.setMap(map);
+ var boundscheck=map.getBounds();
+ if ((!boundscheck.contains(this.getPosition()))&&this.type=="Building") //only zoom to accomodate buildings
+ {
+ boundscheck.extend(this.getPosition());
+ var newzoom = getZoomByBounds( map, boundscheck );
+ if (newzoom<15) map.setMapType(G_NORMAL_MAP);
+ map.setZoom(newzoom);
+ map.setCenter(boundscheck.getCenter());
+ }
+ this.visible=true;
+ }
+ }
+ m.hide = function() {
+ if (!(this.type=="Loops"||this.type=="Parking")) {
+ G.event.clearListeners(this,"click");
+ }
+ if (this.tabVisible) {
+ purgeInfoWindow();
+ this.tabVisible=false;
+ }
+ this.visible=false;
+ this.setMap(null);
+ }
+ m.getPlacesTab=getPlacesTab;
+ m.getInfoTab=getInfoTab;
+ m.getEntranceTab=getEntranceTab;
+ m.getToiletTab=getToiletTab;
+ return m;
+}
+//----------------------------------------------------------------------------------functions to populate tabs called from marker
+function getPlacesTab() {
+ var popup="<div id='map_building'><h4>"+this.name+"</h4>";
+ popup+="<div id='map_building_inner'>";
+ if (this.dispphoto) {
+ popup+="<div id='map_building_photo'>";
+ popup+="<a href='javascript:shadowbox("+this.id+")'><img src='./photos/small/"+this.id+".jpg'></a>";
+ popup+="</div>";
+ }
+ if (this.opening_hours) {
+ popup+="<div id='map_building_opening_hours'>";
+ popup +='<h5>Building Opening Hours:</h5>';
+ popup +='<div>'+this.opening_hours+"</div>";
+ popup+="</div>";
+ }
+ if ((this.accessibility)||(this.accessibility_url)) {
+ popup+="<div id='map_building_access'>";
+ if (this.accessibility) {
+ popup+="<h5>Accessibility: </h5><div>"+this.accessibility+" ";
+ if (this.accessibility_url) popup+="(<a href='http://www.tcd.ie/disability/accessibility/Building-check/"+this.accessibility_url+"'>more&nbsp;info</a>)</div>";
+
+ }
+ else if (this.accessibility_url) popup+="<div><a href='http://www.tcd.ie/disability/accessibility/Building-check/"+this.accessibility_url+"'>Accessibility&nbsp;info</a></div>";
+ popup+="</div>";
+ }
+ popup+="</div>";
+
+ popup+="<div id='map_building_permalink'>";
+ var linkname;
+ linkname=this.name;
+ popup+="<a href='map.php?q="+this.id+"' >Permalink</a>"; //urlencode(linkname)
+ lat=this.getPosition().lat();
+ lng=this.getPosition().lng();
+
+ if (!mainCampus.contains(this.getPosition())) {
+ bd='"'+urlencode(this.name)+'"';
+ popup+=" <a href='javascript:directions("+lat+","+lng+","+bd+")'>Directions</a> ";
+ }
+ popup+="</div>";
+
+ return popup;
+}
+function getInfoTab() {
+ popup="";
+ popup+="<div id='map_info'>";
+ popup+="<div id='map_info_inner'><bd>"; //<div id='map_popup_inner'>";
+ var placeoffset=0;
+ if (this.places.length-placeoffset) {
+ popup+="<h4>Also in this building</h4><ul>";
+ for (i=0;i<this.places.length;i++) {
+ if (this.places[i].name) {
+ if (this.places[i].info.match(/^\s*http/)) {
+ popup +="<li><a href='"+this.places[i].info+"'>"+this.places[i].name+"</a></li>";
+ }
+ else {
+ popup +="<li>"+this.places[i].name+"</li>";
+ }
+ }
+ }
+ popup+="</ul>";
+ }
+ if (this.description) popup+="<h4>Info</h4>"+this.description;
+ popup+="</bd></div></div>";
+ return popup;
+}
+function getToiletTab() {
+ popup="";
+ popup+="<div id='map_toilettab'>";
+ popup+="<div id='map_toilettab_inner'><bd>";
+ popup+="<h4>Enabled toilet</h4>"
+ popup+="<br>"+this.data;
+ popup+="</bd></div></div>";
+ return popup;
+}
+function getEntranceTab() {
+ popup="";
+ popup+="<div id='map_entrancetab'>";
+ popup+="<div id='map_entrancetab_inner'><bd>";
+ popup+="<h4>Entrance</h4>"
+ popup+="<br> "+this.data;
+ popup+="</bd></div></div>";
+ return popup;
+}
+//----------------------------------------------------------------------------------Setting up data structures while loading
+function prepareData() {
+ //create markers for ref tables
+ for (i in icontypes) {
+ markers[icontypes[i]]=[];
+ for (t in tables[icontypes[i]]) {
+
+// DS accounting for forEach
+ if (t != 'forEach') {
+ // DS to avoid an undefined building in IE <= 8
+ if (markers["Building"][tables[icontypes[i]][t].building]) {
+ tables[icontypes[i]][t].lat=markers["Building"][tables[icontypes[i]][t].building].lat;
+ tables[icontypes[i]][t].lng=markers["Building"][tables[icontypes[i]][t].building].lng;
+ tables[icontypes[i]][t].id=tables[icontypes[i]][t].building;
+ markers[icontypes[i]].push(makeMarker(tables[icontypes[i]][t],icontypes[i]));
+ }
+ }
+ }
+
+ markers[icontypes[i]].visible=false;
+ }
+ //process Building and AZ tables
+ //create AZ -- is causing problems now for some reason WHERE THERE ARE NO ITEMS
+ for (var i=0;i<26;i++) {
+ tables[String.fromCharCode(i+65)]=[];
+ tables[String.fromCharCode(i+65)].screenname=String.fromCharCode(i+65);
+ }
+ //Create alphabetical lists of places including exceptions
+ for (var i=0;i<tables["AZ"].length;i++) {
+
+// DS accounting for forEach
+ if (!tables["AZ"][i].call) {
+
+ if (tables["AZ"][i].info=="") tables["AZ"][i].info=tables["AZ"][i].name;
+
+ var j=0;
+ var startlet=0;
+
+ while (tables["AZ"][i].name.charCodeAt(j) <64) j++; //find 1st non-number
+
+ startlet=tables["AZ"][i].name.charCodeAt(j) -65;
+ if (startlet>25) startlet-=32; //select small letters (which shouldn't even be there)
+
+ if ((startlet==96)||(startlet==128)) startlet=0; //catch Á
+ if (startlet==104) startlet=4; //catch É
+ if (startlet==108) startlet=8; //catch Í
+
+ //find array number of building index as buildingindex number can be non-consecutive
+ var bb=tables["AZ"][i].building;
+ for (j in markers['Building'])
+ {
+ if (markers['Building'][j].id==bb) {
+ numplaces=tables[String.fromCharCode(startlet+65)].length;
+ tables[String.fromCharCode(startlet+65)].push(tables["AZ"][i]); //add reference to place
+ tables[String.fromCharCode(startlet+65)][numplaces].building=j; //resolve reference to building array
+ tables[String.fromCharCode(startlet+65)][numplaces].index=i; //resolve reference to AZ array
+ markers['Building'][j].places.push(tables["AZ"][i]);
+ }
+ }
+
+ if (tables["AZ"][i].name.slice(0,3)=="St.")
+ {
+ startlet=tables["AZ"][i].name.charCodeAt(4) -65;
+ if (startlet>25) startlet-=32; //select small letters
+ //we know its doesn't start with ÁÉÍ
+ for (j in markers['Building'])
+ {
+ if (markers['Building'][j].id==bb) {
+ numplaces=tables[String.fromCharCode(startlet+65)].length;
+ tables[String.fromCharCode(startlet+65)].push(tables["AZ"][i]); //add reference to place
+ tables[String.fromCharCode(startlet+65)][numplaces].building=j; //resolve reference to building array
+ markers['Building'][j].places.push(tables["AZ"][i]);
+ }
+ }
+ }
+ }
+ }
+ //add buildings
+ for (i in markers['Building'])
+ {
+ if (markers['Building'][i].name) { //trap added 'visible' property
+ var j=0;
+ var startlet=0;
+
+ while (markers['Building'][i].name.charCodeAt(j) <64) j++; //find 1st non-number
+
+ startlet=markers['Building'][i].name.charCodeAt(j) -65;
+ if (startlet>25) startlet-=32; //select small letters (which shouldn't even be there)
+
+ if ((startlet==96)||(startlet==128)) startlet=0; //catch Á
+ if (startlet==104) startlet=4; //catch É
+ if (startlet==108) startlet=8; //catch Í
+
+ numplaces=tables[String.fromCharCode(startlet+65)].length;
+ tables[String.fromCharCode(startlet+65)].push(new place(markers['Building'][i].name,i,markers['Building'][i].info));
+ tables[String.fromCharCode(startlet+65)][numplaces].building=i; //resolve reference to building array
+ }
+
+ }
+ //sort results alphabetically
+ for (i=0;i<26;i++) {
+ letter=String.fromCharCode(i+65);
+ tables[letter].sort(function(a,b) { if (a.name<b.name) return -1; else return 1;});
+ }
+ //resolve other tables references
+ places.forEach(function(placetable) {
+ for (j=0;j<placetable.length;j++) {
+ for (k=0; k<markers['Building'].length;k++)
+ if (placetable[j].building==markers['Building'][k].num) {
+ placetable[j].building=k; //resolve reference to building array
+ break;
+ }
+ }
+ placetable.sort(function(a,b) {if (a.name<b.name) return -1; else return 1; });
+
+ });
+ //create html popups
+ for (i in markers['Building']) {
+ if (markers['Building'][i].name) {
+ markers['Building'][i].sortPlaces();
+ }
+ }
+ for (t in tables) tables[t].screenname=tablescreennames[t];
+}
+function do_menuchoices() {
+ var menu="<ul>";
+ for (var i=0;i<26;i++) {
+ letter=String.fromCharCode(i+65);
+ menu+="<li><a href='javascript:do_menu(\""+letter+"\");'>"+letter+" </a></li>";
+ }
+ menu+="</ul>";
+ document.getElementById("searchoptions").innerHTML=menu;
+ //action='map.php'
+ menu="<form id='form' method='POST' action='javascript:void(0);' onsubmit='quicklink(this.childNodes[0].childNodes[1]);return false'><div><label for='quicklinks'>Quicklinks: </label><select name='quicklinks' id='quicklinks'><option selected='selected'>Search for lectures, libraries, pacr...</option>";
+ for (i=0;i<placetypes.length;i++) menu+="<option value='"+placetypes[i]+"'>"+screenplacetypes[i]+"</option>";
+ menu+="</select> <input type='submit' value='Go' /></form>";
+ document.getElementById("quicklinkswrap").innerHTML=menu;
+}
+//----------------------------------------------------------------------------------Editing markers while authoring
+function setMarkerPosition() {
+ if (this.type=="Building") {
+ $.ajax({
+ url:"setMarkerPos.php",
+ data: "table="+this.type+"&id="+this.id+"&lat="+this.getPosition().lat()+"&lng="+this.getPosition().lng()+"&google_coords=1"
+ });
+ this.setIcon(new G.MarkerImage("http://maps.google.com/mapfiles/marker_orange.png") );
+ }
+ else {
+ $.ajax({
+ url:"setMarkerPos.php",
+ data: "table="+this.type+"&id="+this.id+"&lat="+this.getPosition().lat()+"&lng="+this.getPosition().lng()
+ });
+ }
+}
+function displayMarkerInfo(){
+ if (this.type=="Building") document.getElementById("info").innerHTML=this.id+": "+this.name;
+ else document.getElementById("info").innerHTML=this.id;
+}
+//----------------------------------------------------------------------------------Interaction handlers
+function shadowbox(n) {
+ Shadowbox.open({content:"./photos/"+n+".jpg",player: "img",title:markers['Building'][n].name});
+}
+function onsearch(query) {
+ if (/^\d/.test(query)) {
+ show_building(query);
+ }
+ else
+ {
+ tables["search"]=[];
+ var foundbuildings=new Array();
+ fb=0;
+ for (var i=0;i<26;i++) {
+ //console.log("checking "+String.fromCharCode(i+65));
+ for (j in tables[String.fromCharCode(i+65)]) {
+
+
+ if (tables[String.fromCharCode(i+65)][j]!=undefined) {
+ //console.log("checking "+j+": "+tables[String.fromCharCode(i+65)][j].name);
+
+ if ("name" in tables[String.fromCharCode(i+65)][j]) {
+ if (tables[String.fromCharCode(i+65)][j].name.toLowerCase().indexOf(query.toLowerCase())>-1) {
+ tables["search"].push(tables[String.fromCharCode(i+65)][j]);
+ if (foundbuildings[tables[String.fromCharCode(i+65)][j].building]!="1") fb++;
+ foundbuildings[tables[String.fromCharCode(i+65)][j].building]="1";
+ }
+ }
+
+ }
+
+ }
+ }
+ //auto-open if 1 search result
+ if (fb==1) {
+ clearmarkers();
+ markers["Building"][tables["search"][0].building].show(true,tables["search"][0]);
+ }
+ tables["search"].screenname=query;
+ tables["search"].sort(function(a,b) {if (a.name<b.name) return -1; else return 1; });
+ do_menu("search");
+ }
+}
+function show_markers(type) {
+ if (DEBUG) console.log("showing "+type);
+ if (!markers[type].visible) {
+ for(i in markers[type]) {
+ if (markers[type][i].id) {
+ markers[type][i].show();
+ }
+ }
+ }
+ else {
+ for(i in markers[type]) {
+ if (markers[type][i].id) {
+ markers[type][i].hide();
+ }
+ }
+ }
+
+ markers[type].visible=!markers[type].visible;
+}
+function show_place(type,index) {
+ show_building(tables[type][index].building);
+}
+function show_building(index) { //funnel through here
+ markers['Building'][index].show(true);
+}
+function quicklink(owner) {
+ name=owner.options[owner.selectedIndex].value;
+ for (i=1;i<markertypes.length;i++) if (name==markertypes[i]) show_markers(name);
+ for (i=0;i<placetypes.length;i++) if (name==placetypes[i]) do_menu(name);
+ resize_map_and_results();
+}
+function do_menu(type) {
+ var title="<h1>"+tables[type].length+" results for ";
+ if (type.length==1) title+="letter ";
+ if (tables[type].screenname) {
+ title+=tables[type].screenname;
+ }
+ else {
+ title+=type;
+ }
+ title+="</h1>";
+ if (DEBUG) console.log("doing menu: "+type);
+ if (DEBUG) console.log(tables[type].length+" items");
+ if(document.getElementById("searchresulttitle")) {
+ document.getElementById("searchresulttitle").innerHTML=title;
+ var content="<ul>";
+ for(var i=0;i<tables[type].length;i++) {
+ content+="<li><a href='javascript:show_place(\""+type+"\","+i+"); '>"+tables[type][i].name+"</a></li>";
+ }
+ content+="</ul>";
+ document.getElementById("searchresults").innerHTML=content;
+ if(do_menu_flag) {
+ resize_map_and_results();
+ }
+ else {
+ do_menu_flag = true;
+ }
+ if (DEBUG) alert(content);
+ }
+}
+function purgeInfoWindow() {
+ if (InfoWindow) {
+ //console.log("closing infowindow");
+ InfoWindow.close();
+ InfoWindow=undefined;
+ }
+}
+function clearmarkers() {
+ for (i in markers) {
+ for (j in markers[i]) {
+ if (markers[i][j] && markers[i][j].name) markers[i][j].hide;
+ }
+ }
+}
+function directions(lat,lng,place){
+ document.getElementById("searchresulttitle").innerHTML="<h1>From Trinity College to "+place+"</h1>";
+ document.getElementById("searchresults").innerHTML="";
+ var request = {
+ origin:new G.LatLng(53.3445,-6.259),
+ destination:new G.LatLng(lat,lng),
+ travelMode: google.maps.DirectionsTravelMode.DRIVING
+ };
+ directionsDisplay.setPanel(document.getElementById("searchresults"));
+ directionsService.route(request, function(response, status) {
+ if (status == G.DirectionsStatus.OK) {
+ directionsDisplay.setDirections(response);
+ }
+ });
+}
+//----------------------------------------------------------------------------------misc utils, legacy ajax stuff to bypass TCD fuzzy filename filter
+//Equivalent of getBoundsZoomLevel() in gmaps api 3
+/**
+* Returns the zoom level at which the given rectangular region fits in the map view.
+* The zoom level is computed for the currently selected map type.
+* @param {google.maps.Map} map
+* @param {google.maps.LatLngBounds} bounds
+* @return {Number} zoom level
+**/
+function getZoomByBounds( map, bounds ){
+ var MAX_ZOOM = map.mapTypes.get( map.getMapTypeId() ).maxZoom || 21 ;
+ var MIN_ZOOM = map.mapTypes.get( map.getMapTypeId() ).minZoom || 0 ;
+
+ var ne= map.getProjection().fromLatLngToPoint( bounds.getNorthEast() );
+ var sw= map.getProjection().fromLatLngToPoint( bounds.getSouthWest() );
+
+ var worldCoordWidth = Math.abs(ne.x-sw.x);
+ var worldCoordHeight = Math.abs(ne.y-sw.y);
+
+ //Fit padding in pixels
+ var FIT_PAD = 40;
+
+ for( var zoom = MAX_ZOOM; zoom >= MIN_ZOOM; --zoom ){
+ if( worldCoordWidth*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).width() &&
+ worldCoordHeight*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).height() )
+ return zoom;
+ }
+ return 0;
+}
+function urlencode (string) {
+ string = string.replace(/\r\n/g,"\n");
+ var utftext = "";
+
+ for (var n = 0; n < string.length; n++) {
+
+ var c = string.charCodeAt(n);
+
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+
+ }
+
+ return escape(utftext);
+}
+function httpexists(url) {
+ exists=false;
+ http.open("GET",'httpexists-proxy.php?httpexistsurl=' + url, false);
+ //http.open("GET", url, false);
+ http.send(null);
+ if (http.status == 200) {
+ exists=true;
+ }
+ return exists;
+}
+function getHTTPObject() {
+ var xmlhttp;
+ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
+ try {
+ xmlhttp = new XMLHttpRequest();
+ } catch (e) {
+ xmlhttp = false;
+ }
+ }
+ return xmlhttp;
+}
+
diff --git a/map.php b/map.php
index d10ae24..e3e0e42 100755
--- a/map.php
+++ b/map.php
@@ -1,3 +1,4 @@
+<?php ini_set('display_errors','1');ini_set('display_startup_errors','1');error_reporting(E_ALL|E_STRICT); ?>
<!DOCTYPE html>
<html lang="en">
<head>
@@ -16,22 +17,22 @@
<!--[if lt IE 8]><link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/m/styles/ie-lt-8-pre.css" media="screen" /><![endif]-->
<link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/m/styles/master.css" media="screen" />
<link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/m/styles/print.css" media="print" />
-<link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/t/college-maps-2/styles-college-maps-2.css" media="screen" />
+<link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/t/college-maps-2/styles-college-maps-2.css?v=1" media="screen" />
<!--[if lt IE 7]><link rel="Stylesheet" type="text/css" href="//www.tcd.ie/tms/m/styles/ie-lt-8.css" media="screen" /><![endif]-->
<!--[if lt IE 7]><script src="//www.tcd.ie/tms/m/scripts/ie7/IE8.js" type="text/javascript"></script><![endif]-->
-<link rel="Stylesheet" type="text/css" href="./styles-working.css" media="screen" />
+<link rel="Stylesheet" type="text/css" href="./styles-working.css?v=2" media="screen" />
<link rel="stylesheet" type="text/css" href="//www.tcd.ie/tms/m/scripts/jquery/shadowbox/build-3.0b/shadowbox.css" />
<script type="text/javascript" src="//www.tcd.ie/tms/m/scripts/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="//www.tcd.ie/tms/m/scripts/jquery/shadowbox/build-3.0b/shadowbox.js"></script>
<?php include "config.php"; ?>
-<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<?php echo $key;?>"></script>
+<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=<?php echo $key;?>"></script>
<?php include "map_prepare.php"; ?>
<script src="infobubble.js" type="text/javascript"></script>
-<script src="maps-extra.js" type="text/javascript"></script>
-<script src="map.js" type="text/javascript"></script>
+<script src="maps-extra.js?v=1" type="text/javascript"></script>
+<script src="map.js?v=3" type="text/javascript"></script>
<?php include '/www.tcd.ie/tms/m/a.php'; // Master content to go before the end of the head element. ?>
</head>
-<body class="t-default " onload="onLoad();callback_for_resizing();" onunload="GUnload()">
+<body class="t-default ">
<div class="wrap">
<div class="core-header">
<h1><a href="http://www.tcd.ie">Trinity College Dublin</a></h1>
@@ -72,7 +73,7 @@
<h1><a href="/Maps/">College Maps</a></h1>
<!-- <div id="facilities"></div>-->
<!--<div id="features"></div>-->
- <form id="headerform" action='javascript:void(0);' onsubmit='onsearch(this.value);return false;'>
+ <form id="headerform">
<div>
<label for="query">Query:</label> <input type="text" id="query" name="q" title="Search the map" size="20" maxlength="2048" />
<input type="submit" id="button" value="Go" />
@@ -86,10 +87,40 @@
<!-- HEADER ENDS-->
<div class="wrap-content"><div class="wrap-content-inner">
<div class="m"><div class="m-inner">
- <div class="building-information"><?php echo $building_information; ?></div>
+ <div class="building-information"><?php //echo $building_information; ?></div>
<div id="searchresultwrap">
- <div id="searchresulttitle"><?php echo $search_title; ?></div>
- <div id="searchresults"><?php echo $search_results; ?></div>
+ <div id="searchresulttitle"><h1>Popular places</h1></div>
+ <div id="searchresults">
+<!-- STATIC COPY - TR 200513-->
+<ul>
+<center>
+<li>
+<a href="javascript:show_building(56);">
+<img src="./photos/thumbs/56.jpg">
+<br>
+Old Library
+</a>
+</li>
+<li>
+<a href="javascript:show_building(59);">
+<img src="./photos/thumbs/59.jpg">
+<br>
+Campanile
+</a>
+</li>
+</li>
+<li>
+<a href="javascript:show_building(198);">
+<img src="./photos/thumbs/198.jpg">
+<br>
+Samuel Beckett Theatre
+</a>
+</li>
+</center>
+<ul>
+<!-- STATIC COPY - TR 200513-->
+
+ </div>
</div>
<div id="mapwrap">
<div id="mapicons"></div>
diff --git a/map_prepare.php b/map_prepare.php
index 288f104..b4d2ea7 100755
--- a/map_prepare.php
+++ b/map_prepare.php
@@ -2,18 +2,20 @@
<script type="text/javascript">
+
var G=google.maps;
- <?php echo"startsearch='".$search."';\n";?>
- <?php echo"startmenu='".$menu."';\n";?>
- <?php echo"startmarkers='".$markers."';\n";?>
+
+ <?php //echo"startsearch='".$search."';\n";?>
+ <?php //echo"startmenu='".$menu."';\n";?>
+ <?php //echo"startmarkers='".$markers."';\n";?>
//security flags for js
- <?php echo "EDITABLE=".$editable."\n";?>
- <?php echo "DEBUG=".$debug."\n";?>
- <?php echo "STARTPOS=new G.LatLng(".$startlat.",".$startlng.")\n";?>
+ <?php echo "EDITABLE=".$editable.";\n";?>
+ <?php echo "DEBUG=".$debug.";\n";?>
+ <?php echo "STARTPOS=new G.LatLng(".$startlat.",".$startlng.");\n";?>
// Pass any POST variables to Javascript, which are then used in maps-extra.js
- var search_posted = '<?php echo $_GET['q']; ?>';
- var quicklinks_posted = '<?php echo $quicklinks_posted; ?>';
+ var search_posted = '<?php echo (isset($_GET['q']) ? str_replace("'", "\'", htmlspecialchars($_GET['q'])) : ''); // DS added htmlspecialchars 2013 May 8 and single quote escaping 2013 May 9 ?>';
+ var quicklinks_posted = '<?php //echo $quicklinks_posted; ?>';
var submit_the_query_form = false;
</script> \ No newline at end of file
diff --git a/maps-extra.js b/maps-extra.js
index e6cc7e1..a2b1f2c 100755
--- a/maps-extra.js
+++ b/maps-extra.js
@@ -37,10 +37,10 @@ $(document).ready(function() {
});
// Set the action when the search box form is submitted.
if ($('#headerform')) {
- $('#headerform').submit(function() {
+ $('#headerform').bind('submit', function() {
var el = document.getElementById('query');
onsearch(el.value);
- return submit_the_query_form;
+ return false;
});
};
// Set the default height for the map.
@@ -156,7 +156,7 @@ function resize_map_and_results() {
$('#searchresults').css('height', diff + 2 + 'px'); // The 2 is a bit random but adjusts the bottom of the results to match the map.
}
- map.setCenter(STARTPOS, 17);
+ //map.setCenter(STARTPOS, 17);
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
diff --git a/tableKML.php b/tableKML.php
index d0daaae..1007f42 100644..100755
--- a/tableKML.php
+++ b/tableKML.php
@@ -1,4 +1,9 @@
+<?php //ini_set('display_errors','1');ini_set('display_startup_errors','1');error_reporting(E_ALL|E_STRICT); ?>
<?php
+
+header("Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8");
+//header("Content-Type: text/html; charset=utf-8");
+
include 'config.php';
mysql_connect($host, $login, $pword) or die(mysql_error());
@@ -11,22 +16,28 @@ $result = mysql_query($query);
#http://stackoverflow.com/questions/1567758/best-way-to-use-jquerys-ajax-function-retrieve-variables-from-a-php-script
-echo "<?xml version='1.0' encoding='UTF-8'?>\n";
-echo "<kml xmlns=\'http://www.opengis.net/kml/2.2\'>\n";
+$output = '';
+$output .= "<?xml version='1.0' encoding='UTF-8'?>\n";
+$output .= "<kml xmlns='http://www.opengis.net/kml/2.2'>\n";
$n=mysql_numrows($result);
$i=0;
+
while ($i < $n) {
$T=mysql_fetch_array($result, MYSQL_ASSOC);
- echo "<Placemark>\n";
- echo "<name>".$T[name]."</name>\n";
- echo "<Point>\n";
- echo "<coordinates>".$T[lat].",".$T[lng].",0</coordinates>\n";
- echo "</Point>\n";
- echo "</Placemark>\n";
- $i+=1;
+ $output .= "<Placemark>\n";
+ $output .= "<name>".str_replace('&', '&amp;', $T['name'])."</name>\n";
+ $output .= "<Point>\n";
+ $output .= "<coordinates>".$T['lat'].",".$T['lng'].",0</coordinates>\n";
+ $output .= "</Point>\n";
+ $output .= "</Placemark>\n";
+ $i +=1;
+
}
mysql_close();
-echo "</kml>\n";
+$output .= "</kml>\n";
+
+echo $output;
+
?>