/** * Filename : map.js * Copyright : Transport for London 2005 * * Author : Phil Maskell * **/ var origZIndex; var currentPopup; var popupId = 0; AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { 'autoSize': true }); function escapeHTML(strTemp) { return strTemp.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } function plotActivityGeometry(data) { if(data != "ERROR") { data = escapeHTML(data); if(data.indexOf('$') > 0) { clearLayer("activityCanvas"); var points = data.split('|'); if(points[0] == "1") { document.getElementById("messageContainer").innerHTML = "
There is "+points[0]+" result currently displayed on the map.
"; } else { document.getElementById("messageContainer").innerHTML = "
There are "+points[0]+" results currently displayed on the map.
"; } plotGeometry(data, "activityCanvas", new OpenLayers.Size(34,34)); } else { document.getElementById("activityCanvas").innerHTML = ""; if(currentPopup!= null) { map.removePopup(currentPopup); clearLayer("highlightMarker"); currentPopup = null; } if(data == "0") { document.getElementById("messageContainer").innerHTML = "
There are "+data+" results. Please zoom out or widen your search criteria.
"; } else { document.getElementById("messageContainer").innerHTML = "
There are "+data+" results, which are too many to display. Please zoom in or narrow your search until there are fewer than 500 results."; } } } else { window.location.href = "error"; } } function plotGeometry(data, layer, size) { data = escapeHTML(data); var geometry = data.split('|'); var plotCanvas = document.getElementById(layer); var pointsInnerHtml = new Array(); var offset = new OpenLayers.Pixel(-(size.w/2), -(size.h/2)); clearLayer("highlightMarker"); for (i = 1; i < geometry.length; i++) { var pointPoly = geometry[i].split('$'); if (pointPoly.length > 2) { var point = pointPoly[0].split(','); var pixel = map.getPixelFromLonLat(new OpenLayers.LonLat(point[0], point[1])); var x = pixel.x; var y = pixel.y; var left = x + offset.x; var top = y + offset.y; pointsInnerHtml.push("\"Works"); } } if(pointsInnerHtml.length > 0) { var innerHtml = pointsInnerHtml.join(""); plotCanvas.style.display = 'none'; plotCanvas.innerHTML = innerHtml; plotCanvas.style.display = ''; } } function mouseover(img, url) { img.src = url; origZIndex = img.style.zIndex; img.style.zIndex = 1000; } function mouseout(img, url) { img.src = url; img.style.zIndex = origZIndex; } function mouseclick(ref) { if(currentPopup != null && popupId != 0) { map.removePopup(currentPopup); clearLayer("highlightMarker"); currentPopup = null; if(popupId != ref) { popupId = ref; AjaxFunctions.getInfo(ref, mouseinfo); } else { popupId = 0; } } else { popupId = ref; AjaxFunctions.getInfo(ref, mouseinfo); } } function viewOnMap(x, y, z, worksRef) { init(x, y, z); if (browser.isLessThanIE6) { //nowt } else { mouseclick(worksRef); } } function mouseinfo(data) { if(data == "ERROR") { window.location.href = "error"; } else { if (!browser.isKonqueror) { overview.minimizeControl(); } var tmp = data.split('|'); var ll = new OpenLayers.LonLat(tmp[0],tmp[1]); popupClass = AutoSizeFramedCloud; popupContentHTML = '
'+tmp[3]+'
'; clearLayer("highlightMarker"); addMarker(ll, tmp[2], popupClass, popupContentHTML, true); } } /** * Function: addMarker * Add a new marker to the markers layer given the following lonlat, * popupClass, and popup contents HTML. Also allow specifying * whether or not to give the popup a close box. * * Parameters: * ll - {} Where to place the marker * popupClass - {} Which class of popup to bring up * when the marker is clicked. * popupContentHTML - {String} What to put in the popup * closeBox - {Boolean} Should popup have a close box? * overflow - {Boolean} Let the popup overflow scrollbars? */ function addMarker(ll, image, popupClass, popupContentHTML, closeBox, overflow) { var feature = new OpenLayers.Feature(highlightMarker, ll); feature.closeBox = closeBox; feature.popupClass = popupClass; feature.data.popupContentHTML = popupContentHTML; feature.data.overflow = (overflow) ? "auto" : "hidden"; var marker = feature.createMarker(); var size = new OpenLayers.Size(34,34); var offset = new OpenLayers.Pixel(-((size.w/2)-1), -(size.h/2)); var icon = new OpenLayers.Icon(image, size, offset); marker.icon = icon; highlightMarker.addMarker(marker); if(currentPopup!= null) { map.removePopup(currentPopup); } currentPopup = feature.createPopup(closeBox); map.addPopup(currentPopup); currentPopup.show(); }