var map = null;
var showCoord = true;
var mapMarker = null;
var mapCenter = new Array();
/* GlocalSearch is to be used for UK maps */
var localSearch = new GlocalSearch();
mapCenter['Beijing 2008 lat'] = 39.93;
mapCenter['Beijing 2008 lng'] = 116.400001;
mapCenter['Beijing 2008 zoom'] = 11;
mapCenter['Beijing 2008 type'] = G_NORMAL_MAP;
mapCenter['Vancouver 2010 lat'] = 49.250494;
mapCenter['Vancouver 2010 lng'] = -123.111934;
mapCenter['Vancouver 2010 zoom'] = 11;
mapCenter['Vancouver 2010 type'] = G_NORMAL_MAP;
mapCenter['Whistler 2010 lat'] = 50.11557;
mapCenter['Whistler 2010 lng'] = -122.959156;
mapCenter['Whistler 2010 zoom'] = 11;
mapCenter['Whistler 2010 type'] = G_NORMAL_MAP;
mapCenter['Other Areas 2010 lat'] = 49.621387;
mapCenter['Other Areas 2010 lng'] = -122.398682;
mapCenter['Other Areas 2010 zoom'] = 7;
mapCenter['Other Areas 2010 type'] = G_NORMAL_MAP;
mapCenter['London 2012 lat'] = 51.500197;
mapCenter['London 2012 lng'] = -0.126197;
mapCenter['London 2012 zoom'] = 11;
mapCenter['London 2012 type'] = G_NORMAL_MAP;
/* Initialise icons */
var ihouse32 = new GIcon();
var ivenue32 = new GIcon();
ihouse32.image = "images/home-32.png";
ihouse32.iconSize = new GSize(25, 25);
ihouse32.iconAnchor = new GPoint(12, 12);
ihouse32.infoWindowAnchor = new GPoint(20, 5);
ivenue32.image = "images/venue-32.png";
ivenue32.iconSize = new GSize(32, 32);
ivenue32.iconAnchor = new GPoint(12, 12);
ivenue32.infoWindowAnchor = new GPoint(20, 5);
/* ********************************************************* */
/* Function to call to initialize the map */
/* ********************************************************* */
function loadMap(gameName, gameId, est_id, loadMarkers, showCoord) {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
var url = "genMarkersXML.php?gam_id=" + gameId;
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.addMapType(G_PHYSICAL_MAP);
if (est_id == null){
map.setCenter(new GLatLng(mapCenter[gameName + ' lat'] , mapCenter[gameName + ' lng']), mapCenter[gameName + ' zoom']);
}else{
map.setCenter(new GLatLng(mapCenter[gameName + ' lat'] , mapCenter[gameName + ' lng']), mapCenter[gameName + ' zoom']);
url = url + "&est_id=" + est_id + "&show=true";
}
if (showCoord) {
GEvent.addListener(map, "click", ratg_mapClicked);
}
if (loadMarkers == true) {
// alert("url: " + url);
GDownloadUrl(url, function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var type=markers[i].getAttribute("type");
if (type == "house"){
var title = markers[i].getAttribute("title");
var id = markers[i].getAttribute("id");
var bedroom = markers[i].getAttribute("bedroom");
var bathroom = markers[i].getAttribute("bathroom");
var sqft = markers[i].getAttribute("sqft");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = '' + title + '
- ' + bedroom +' bedroom(s)
- ' + bathroom + ' bathroom(s)
- ' + sqft + 'sq/ft';
var marker = createMarker(point, html, {icon:ihouse32});
if (est_id != null && parseFloat(markers[i].getAttribute("lat")) != 0 && parseFloat(markers[i].getAttribute("lng")) != 0){
map.setCenter(point, 13);
}else{
map.setCenter(new GLatLng(mapCenter[gameName + ' lat'] , mapCenter[gameName + ' lng']), mapCenter[gameName + ' zoom']);
}
map.addOverlay(marker);
}else if (type == "venue"){
var venue = markers[i].getAttribute("venue");
var URL = markers[i].getAttribute("url");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = '
' + venue + '';
var marker = createMarker(point, html, {icon:ivenue32});
map.addOverlay(marker);
}
}
});
}
}
}
function createMarker(point, html, type) {
var marker = new GMarker(point, type);
/*
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
*/
GEvent.addListener(marker, "mouseover", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
/* ************************************** */
/* Center map on given game */
/* ************************************** */
function centerMapForGame(gameName)
{
map.setCenter(new GLatLng(mapCenter[gameName + ' lat'] , mapCenter[gameName + ' lng']), mapCenter[gameName + ' zoom']);
map.setMapType(mapCenter[gameName + ' type']);
}
/* ************************************** */
/* Callback when map is clicked */
/* ************************************** */
function ratg_mapClicked(marker, point) {
if (marker) {
var point1 = marker.getPoint();
marker.openInfoWindowHtml(infoWindow[point1.lat() + ',' + point1.lng()]);
}else{
if (showCoord){
if (mapMarker == null){
mapMarker = new GMarker(point,{icon:ihouse32});
}else{
mapMarker.setPoint(point,{icon:ihouse32});
}
map.addOverlay(mapMarker);
mapMarker.openInfoWindowHtml("New coordinates:
latitude: " + point.lat() + "
longitude: " + point.lng() + "");
document.estate.est_lat.value = point.lat();
document.estate.est_lng.value = point.lng();
}
}
}
/* ************************************* */
/* Return a GPoint from address */
/* ************************************* */
function searchGoogleMaps(address) {
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
showFullAddressInfo(address, false, point);
}else{
alert("address not found!");
}
});
localSearch.execute(address);
}
/* ***************************************** */
/* Show the full address info on the map and
display an info window with the geocodes */
/* ***************************************** */
function showFullAddressInfo(address, showCoord, point)
{
if (!point) {
alert("Address not found");
} else {
var coord = "";
map.setCenter(point, 13);
if (mapMarker == null){
mapMarker = new GMarker(point,{icon:ihouse32});
}else{
mapMarker.setPoint(point,{icon:ihouse32});
}
map.addOverlay(mapMarker);
if (showCoord) {
coord = "
" + "lat: " + point.lat() + "
long: " + point.lng();
}
var html = "
" + address + coord + "";
mapMarker.openInfoWindowHtml(html);
document.estate.est_lat.value = point.lat();
document.estate.est_lng.value = point.lng();
}
}