//'; this.soaphead = soaphead; var soaptail = ''; this.soaptail = soaptail; this.zoomTo(myZp); var soaphost = "http://dialogues.concrete.org.au/dgsoap"; this.soaphost = soaphost; this.updatePos(); GEvent.bind(this.map,"moveend",this,this.updatePos); GEvent.bind(this.map,"zoom",this,this.updatePos); GEvent.bind(this.map,"move",this,this.crossHair); // deal with URL state here this.parseRequestState(); } else { alert("As we use all kinds of crazy javascript here, your browser is not properly compatible with this website. All works are fully accessible, but you won't see the map, so you'll be kind of missing the point. If you can, please try out a Firefox, Safari or recent Internet Explorer, and you'll see the full wonder of the thing."); } } DGMap.prototype.switchView = function (view) { if (view == 'street') { this.map.setMapType(G_NORMAL_MAP); } else if (view == 'satellite') { this.map.setMapType(G_SATELLITE_MAP); } else { view = 'hybrid'; this.map.setMapType(G_HYBRID_MAP); } document.cookie = "dgMapType="+view+";path=/"; } DGMap.prototype.resetView = function () { this.map.centerAndZoom(new GPoint(115.84808349609375, -31.982453066235752),7); } DGMap.prototype.parseRequestState = function () { var reqUri = document.location.href; var reqAnchor = reqUri.lastIndexOf('#'); if (reqAnchor) { var reqState = reqUri.substr((reqAnchor + 1),reqUri.length).split(':'); for (var i = 0; i < reqState.length; i++) { if (reqState[i].match("=")) { var reqString = reqState[i].split("="); reqArg = reqString[0]; reqVal = reqString[1]; } else { reqArg = reqState[i]; reqVal = null; } // alert("running "+reqArg+" with "+reqVal); switch(reqArg) { case "submit" : this.goSubmit(); break; case "work" : this.loadWork(reqVal); } } } } DGMap.prototype.updatePos = function() { this.checkLimits(); coord = document.getElementById('coords'); if (coord) { gc = document.getElementById("withinscope").removeChild(coord); gc = null; } var newpos = this.map.getCenterLatLng(); document.cookie = "dgMapX="+newpos.x+";path=/"; document.cookie = "dgMapY="+newpos.y+";path=/"; this.currentPos = newpos; this.buildMarkers(); this.buildStreets(); } DGMap.prototype.checkLimits = function () { var bounds = this.map.getBoundsLatLng(); if ((bounds.minX < 115) || (bounds.minY > -32) || (bounds.maxX > 118) || (bounds.maxY < -30)) { // alert("Sorry, this project only exists within the bounds of Metropolitan Perth. Nothing to see out here, move along please."); // this.map.recenterOrPanToLatLng(this.currentPos); } } DGMap.prototype.crossHair = function () { if (this.centerMarker) { this.map.removeOverlay(this.centerMarker); this.centerMarker = null; if (document.getElementById('streetForm')) { this.centerMarker = new GMarker(this.map.getCenterLatLng(),crosshair); this.map.addOverlay(this.centerMarker); this.map.recenterOrPanToLatLng(this.map.getCenterLatLng()); } } } function getCookie(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else begin += 2; var end = document.cookie.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin + prefix.length, end)); } DGMap.prototype.readDOMValue = function (val,docEl) { vals = docEl.getElementsByTagName(val); if (vals.length) { if (vals[0].firstChild) { value = vals[0].firstChild.nodeValue; } else { return false; } return value; } else { return false; } } DGMap.prototype.createMarker = function (point,title) { // debug("setting marker at "+point) var marker = new GMarker(point, this.icon); this.map.addOverlay(marker); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(title); }); } DGMap.prototype.handleMarkerResponse = function (response) { if (response.getElementsByTagName('SOAP-ENV:Fault').size) { error("Fault"); } else { this.titles = new Array(); this.points = new Array(); var markers = response.documentElement.getElementsByTagName("item"); for (var i = 0; i < markers.length; i++) { // info ('checking result '+i); lng = parseFloat(this.readDOMValue("lng",markers[i])); lat = parseFloat(this.readDOMValue("lat",markers[i])); title = this.readDOMValue("title",markers[i]); workid = this.readDOMValue("workid",markers[i]); author = this.readDOMValue("author",markers[i]); point = new GPoint(lat,lng); if (point) { // debug("setting marker at "+point) // info("title of piece is "+title); this.titles[workid] = title; this.points[workid] = point; var marker = createMarker(point,i,title,workid,author); this.map.addOverlay(marker); // info("marker set at point "+point); } else { // warn("bad point"); } } // info('all markers set from response'); } } function createMarker(point,i,title,workid,author) { var marker = new GMarker(point,dialogues.icon); // Show this marker's index in the info window when it is clicked this.title = title; var html = "

"+title+"

Go

by "+author+"

"; GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); return marker; } DGMap.prototype.goSubmit = function() { var submitdiv = document.getElementById('work'); submitdiv.innerHTML = '

Submit Your Work

'; this.submitdiv = submitdiv; if (submitdiv) { document.location.href = "#submit"; document.title = "Concrete Dialogues /:/ Submit Your Work"; var streetSearchF = document.createElement('form'); var searchText = document.createElement('input'); searchText.name="locationQuery"; searchText.type="text"; searchText.setAttribute('id','streetSearch'); // streetSearch.method = "GET"; var goButton = document.createElement('input'); goButton.type = "image"; goButton.src = "http://dialogues.concrete.org.au/graphics/markers/red_triangle.png"; streetSearchF.onsubmit = this.getStreetSearch; searchLabel = document.createElement('p'); searchLabelText = document.createTextNode("Search for Street or Suburb Name: "); searchLabel.appendChild(searchLabelText); streetSearchF.appendChild(searchLabel); streetSearchF.appendChild(searchText); streetSearchF.appendChild(goButton); var streetResults = document.createElement('div'); streetResults.setAttribute('id','streetResults'); var submitbox = document.createElement('div'); submitbox.setAttribute("id","submitbox"); var subform = document.createElement('form'); subform.setAttribute("id","streetForm"); subform.method = "POST"; subform.action = 'http://dialogues.concrete.org.au/'; subform.innerHTML = "Fetching Possible Locations..."; subform.appendChild(logop); var subdesc = document.createElement('p'); var subblurb = document.createTextNode("It's a big city, we know. We need you to tell us where your piece is located in this urban jungle. Or, you know, suburban sprawl, whatever. Just slide around the map until you find the right place - nearby streets will show up just below for you to choose from. If you need a hand, type what you're looking for into the search box and we'll give you links to go straight there on the map. Once you've found the general area, you should zoom in to locate your piece as accurately as possible under the crosshair."); var nextSelect = document.createElement('h2'); nextSelect.className = 'author'; var nextSelText = document.createTextNode('Select a location'); nextSelect.appendChild(nextSelText); subdesc.appendChild(subblurb); subdesc.appendChild(nextSelect); var lat = document.createElement('input'); lat.setAttribute('id','submitLat'); lat.name = "XCoords"; lat.type = 'hidden'; lat.value = getCookie('dgMapX'); var lng = document.createElement('input'); lng.setAttribute('id','submitLng'); lng.name = "YCoords"; lng.type = 'hidden'; lng.value = getCookie('dgMapY'); this.lat = lat; this.lng = lng; searchCont = document.createElement('div'); searchCont.setAttribute('id','streetSearchContainer'); // subdesc.appendChild(subcont); searchCont.appendChild(streetSearchF); searchCont.appendChild(streetResults); submitbox.appendChild(searchCont); submitbox.appendChild(subdesc); submitbox.appendChild(subform); this.buildStreets(); submitdiv.appendChild(submitbox); crosshair = new GIcon(); crosshair.image = "http://dialogues.concrete.org.au/graphics/markers/crosshair.png"; crosshair.shadow = "http://dialogues.concrete.org.au/graphics/markers/crosshair.png"; crosshair.iconSize = new GSize(40, 40); crosshair.shadowSize = new GSize(40, 40); crosshair.iconAnchor = new GPoint(18, 20); this.centerMarker = new GMarker(this.map.getCenterLatLng(),crosshair); this.map.addOverlay(this.centerMarker); } } DGMap.prototype.getStreetSearch= function() { var searchQ = document.getElementById('streetSearch'); var qString = encodeURIComponent(searchQ.value); searchQ.disabled = true; document.getElementById('streetResults').innerHTML = "searching"; document.getElementById('streetResults').appendChild(logoimg); // ajax request to get works within scope searchrequest = new ajaxRequest(); searchrequest.open("GET", "http://dialogues.concrete.org.au//ajaxkeyword/"+qString, true); searchrequest.onreadystatechange = function() { if (searchrequest.readyState == 4) { document.getElementById('streetResults').innerHTML = searchrequest.responseText; document.getElementById('streetSearch').disabled = false; } } searchrequest.send(null); return false; } DGMap.prototype.goSearch= function() { var kSearchQ = document.getElementById('search'); var qString = encodeURIComponent(kSearchQ.value); kSearchQ.disabled = true; document.getElementById('searchResults').innerHTML = "searching"; document.getElementById('searchResults').appendChild(logoimg); // ajax request to get works within scope keySearch = new ajaxRequest(); keySearch.open("GET", "http://dialogues.concrete.org.au//ajaxkeyword/"+qString+"/comprehensive", true); keySearch.onreadystatechange = function() { if (keySearch.readyState == 4) { var res = document.getElementById('searchResults'); res.className = 'nearby'; res.innerHTML = keySearch.responseText; document.getElementById('search').disabled = false; } } keySearch.send(null); return false; } DGMap.prototype.postPiece = function () { workEl = document.getElementById('work'); titleEls = DGGetElementsByAttribute('class','title',workEl); if (titleEls.length) { document.title = "Concrete Dialogues /:/ "+titleEls[0].firstChild.nodeValue; } var x = parseFloat(document.getElementById('workXCoord').firstChild.nodeValue); var y = parseFloat(document.getElementById('workYCoord').firstChild.nodeValue); var myPoint = new GPoint(x,y); this.map.recenterOrPanToLatLng(myPoint); if (!this.historyPoints) { this.historyPoints = new Array(); this.historyPoints.push(myPoint); } else { if (this.historyTrail) { this.map.removeOverlay(this.historyTrail); } this.historyPoints.push(myPoint); this.map.addOverlay(new GPolyline(this.historyPoints)); } var destDiv = document.getElementById('destinations'); if (destDiv) { destDiv.innerHTML = document.getElementById('destinationsBuffer').innerHTML; } this.map.recenterOrPanToLatLng(myPoint); } DGMap.prototype.loadWork = function (id) { if (!id) { id = -1; } this.id = id; var work = document.getElementById('work'); work.innerHTML = "Loading Work"; work.appendChild(logoimg); var fetchwork = new ajaxRequest(); fetchwork.open("GET","http://dialogues.concrete.org.au//ajaxwork/"+id,true); fetchwork.onreadystatechange = function() { if (fetchwork.readyState == 4) { work.innerHTML = fetchwork.responseText; dialogues.postPiece(); dialogues.updateJourney(); } } fetchwork.send(null); document.location.href = '#work='+id; } DGMap.prototype.updateJourney = function () { var fetchjourney = new ajaxRequest(); fetchjourney.open("GET","http://dialogues.concrete.org.au//journey/",true); fetchjourney.onreadystatechange = function() { if (fetchjourney.readyState == 4) { var journey = document.getElementById('journey'); journey.innerHTML = fetchjourney.responseText; } } fetchjourney.send(null); } DGMap.prototype.buildInfoBox = function (title,id) { return "

"+title+" at "+id+"

"; } DGMap.prototype.buildMarkers = function () { // alert("building markers"); var icon = new GIcon(); this.icon = icon; this.icon.image = "http://dialogues.concrete.org.au/graphics/markers/marker1.png"; this.icon.shadow = "http://dialogues.concrete.org.au/graphics/markers/marker2.png"; this.icon.transparent = "http://dialogues.concrete.org.au/graphics/markers/marker3.png"; this.icon.iconSize = new GSize(15, 23); this.icon.shadowSize = new GSize(22, 23); this.icon.iconAnchor = new GPoint(6, 20); this.icon.infoWindowAnchor = new GPoint(5, 1); // ajax request to get works within scope var request = new ajaxRequest(); request.open("POST", this.soaphost, true); request.onreadystatechange = function() { if (request.readyState == 4) { dialogues.handleMarkerResponse(request.responseXML); } } var bounds = this.map.getBoundsLatLng(); icon = this.icon; xmlqry = this.soaphead+''+bounds.minX+''+bounds.maxX+''+bounds.minY+''+bounds.maxY+''+this.zoomLevel+''+this.soaptail; request.setRequestHeader("Content-Type", "text/xml"); request.setRequestHeader("SOAPAction", "http://dialogues.concrete.org.au//dgsoap/getWorksInMapScope"); // alert('sending query'); request.send(xmlqry); // alert('query sent'); } DGMap.prototype.buildStreets = function () { if (this.submitdiv) { var submitLng = document.getElementById("submitLng"); var submitLat = document.getElementById("submitLat"); if (submitLat) { submitLat.value = this.currentPos.x; submitLng.value = this.currentPos.y; } //info("running buildstreets"); var streetForm = document.getElementById('streetForm'); if (streetForm) { streetForm.innerHTML = "Fetching Possible Locations..."; streetForm.appendChild(logop); } var streetrequest = new ajaxRequest(); streetrequest.open("POST",this.soaphost,true); streetrequest.onreadystatechange = function() { if (streetrequest.readyState == 4) { // debug(streetrequest.responseText); dialogues.handleStreetResponse(streetrequest.responseXML); } } var bounds = this.map.getBoundsLatLng(); xmlqry = this.soaphead+''+bounds.minX+''+bounds.maxX+''+bounds.minY+''+bounds.maxY+''+this.zoomLevel+''+this.soaptail; streetrequest.setRequestHeader("Content-Type", "text/xml"); streetrequest.setRequestHeader("SOAPAction", "http://dialogues.concrete.org.au//dgsoap/getStreetsInThreshold"); // alert(xmlqry); streetrequest.send(xmlqry); } } DGMap.prototype.handleStreetResponse = function (response) { if (response.getElementsByTagName('SOAP-ENV:Fault').size) { error("Fault"); } else { var streets = response.documentElement.getElementsByTagName("item"); // alert(response); var streetForm = document.getElementById("streetForm"); if (streets.length) { streetForm.innerHTML = ""; streetList = document.getElementById('streetList'); if (streetList) { gSl = streetForm.removeChild(streetList); gSl = null; goButton = document.getElementById('gobutton'); if (goButton) { gBut = streetForm.removeChild(goButton); gBut = null; } } if (streetForm) { // fugly hack til i can find out why IE's not let me select radio buttons if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) { inputEl = document.createElement('select'); inputEl.name = 'street'; } else { var streetList = document.createElement('ul'); streetList.setAttribute('id','streetList'); } for (var i = 0; i < streets.length; i++) { street = this.readDOMValue("street",streets[i]); suburb = this.readDOMValue("suburb",streets[i]); // fugly hack til i can find out why IE's not let me select radio buttons if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) { myOption = document.createElement('option'); myOption.text=street+', '+suburb; myOption.value=street+':'+suburb; inputEl.add(myOption); } else { var listitem = document.createElement('li'); inputEl = document.createElement('input'); inputEl.type = 'radio'; inputEl.name = 'street'; inputEl.setAttribute('name','street'); if (i == 0) { inputEl.checked = true; } inputEl.disabled = false; inputEl.value = street+':'+suburb; inputEl.setAttribute('id','street'+i); inputLabel = document.createElement('label'); inputLabel.htmlFor = 'street'+i; inputLabel.innerText = street+', '+suburb; inputLabel.innerHTML = street+', '+suburb; listitem.appendChild(inputEl); listitem.appendChild(inputLabel); streetList.appendChild(listitem); } } // alert(streetList.innerHTML); if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) { streetForm.appendChild(inputEl) } else { streetForm.appendChild(streetList); } goButton = document.createElement('input'); goButton.setAttribute('id','gobutton'); goButton.value = 'Submit Here'; goButton.setAttribute('value','Submit Here'); goButton.name = 'Submit Here'; streetForm.appendChild(this.lat); streetForm.appendChild(this.lng); goButton.type = 'submit'; streetForm.appendChild(goButton); } } else { streetForm.innerHTML = "No Streets Here, please try somewhere else."; } } } DGMap.prototype.panTo = function (compass) { currentPoint = this.map.getCenterLatLng(); viewport = this.map.getBoundsLatLng(); x = currentPoint.x; y = currentPoint.y; // alert(viewport); xtick = x - viewport.minX; ytick = y - viewport.minY; // window.alert(xtick+' and '+ytick); switch (compass) { case 'n' : x = x; y = y + ytick; break; case 'nw' : x = x - xtick; y = y + ytick; break; case 'ne' : x = x + xtick; y = y + ytick; break; case 'nw' : x = x - xtick; y = y + ytick; break; case 's' : x = x; y = y - ytick; break; case 'sw' : x = x - xtick; y = y - ytick; break; case 'se' : x = x + xtick; y = y - ytick; break; case 'e' : x = x + xtick; y = y; break; case 'w' : x = x - xtick; y = y; break; } dest = new GPoint(x,y); this.map.recenterOrPanToLatLng(dest); } DGMap.prototype.slideTo = function (x,y,submit) { newDest = new GPoint(x,y); this.map.recenterOrPanToLatLng(newDest); return false; } DGMap.prototype.zoomTo = function (zoomLevel) { if (zoomLevel == 'in') { zoomLevel = this.zoomLevel - 1; } else if (zoomLevel == 'out') { zoomLevel = this.zoomLevel + 1; } if (zoomLevel > 8) { zoomLevel = 8; } else if (zoomLevel < 1) { zoomLevel = 1; } var zId = zoomLevel; this.zoomLevel = zoomLevel; if (zoomLevel == 1) { zoomLevel = 0; } var zoompics = DGGetElementsByAttribute('class','zoomcontrolpic',document.getElementById('zoombuttons')); for (var i = 0; i < zoompics.length; i++) { var lId = i + 1; if (zId != lId) { zoompics[i].src = 'http://dialogues.concrete.org.au/images/zoomcontrol/zoom'+lId+'.gif'; } else { zoompics[i].src = 'http://dialogues.concrete.org.au/images/zoomcontrol/on_zoom'+lId+'.gif'; } } // alert('zooming to '+zoomLevel); this.map.zoomTo(zoomLevel); document.cookie = "dgMapZoom="+zoomLevel+";path=/"; } DGMap.prototype.showTag = function (tag) { // info("running buildstreets"); var tagResults = document.getElementById('tagResults'); if (tagResults) { tagResults.style.display = "block"; tagResults.innerHTML = "searching for tag "+tag+"..."; tagResults.appendChild(logoimg); } tagReq = new ajaxRequest(); tagReq.open("GET", "http://dialogues.concrete.org.au//tag/"+tag, true); tagReq.onreadystatechange = function() { if (tagReq.readyState == 4) { document.getElementById('tagResults').innerHTML = tagReq.responseText; } } tagReq.send(null); return false; } /** Sends an asynchronous request to a url and alerts on state change (known in the buzzworld as AJAX */ function ajaxRequest() { // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } return xmlhttp; } function goDialogues() { // preload some images logoimg = document.createElement('img'); logoimg.src = 'http://dialogues.concrete.org.au/graphics/loading_circle.gif'; logoimg.width = 40; logoimg.height = 40; logop = document.createElement('p'); logop.appendChild(logoimg); if (document.getElementById("mainmap")) { dialogues = new DGMap(); dialogues.logop = logop; if (self.bufferCoord) { dialogues.postPiece(); } replaceLinks = DGGetElementsByAttribute("class","replaceLink"); for (var i = 0; i < replaceLinks.length; i++) { replaceLinks[i].href = "#"; } } return false; } /** Javascript doesn't have a getElementByClass so lets have a function that gets by any attribute, including class. @param attr name of attribute (eg 'class') @param val attribute value to search for @param container search scope within dom (defaults to document) @return array */ function DGGetElementsByAttribute(attr,val,container) { container = container||document; var all = container.all||container.getElementsByTagName('*'); var arr = []; for(var k=0;k