var loadedmarkers = [];
function display(type) {
//alert("");
//doNothing();
switch(type)
{
case "Shop":
for (i in loadedmarkers)
{
if (loadedmarkers[i].icon == "/images/tools.png") {
loadedmarkers[i].setVisible(true);
} else if (loadedmarkers[i].icon == "/images/military.png") {
loadedmarkers[i].setVisible(false);
}
}
break;
case "Site":
for (i in loadedmarkers)
{
if (loadedmarkers[i].icon == '/images/tools.png') {
loadedmarkers[i].setVisible(false);
} else if (loadedmarkers[i].icon == '/images/military.png') {
loadedmarkers[i].setVisible(true);
}
}
break;
case "Both":
for (i in loadedmarkers)
{
loadedmarkers[i].setVisible(true);
}
break;
default:
break;
}
return 1;
}
/**
* The HomeControl adds a control to the map that
* returns the user to the control's defined home.
*/
// Define a property to hold the Home state
HomeControl.prototype.home_ = null;
// Define setters and getters for this property
HomeControl.prototype.getHome = function() {
return this.home_;
}
HomeControl.prototype.setHome = function(home) {
this.home_ = home;
}
function HomeControl(map, div, home) {
// Get the control DIV. We'll attach our control
// UI to this DIV.
var controlDiv = div;
// We set up a variable for the 'this' keyword
// since we're adding event listeners later
// and 'this' will be out of scope.
var control = this;
// Set the home property upon construction
control.home_ = home;
// Set CSS styles for the DIV containing the control
// Setting padding to 5 px will offset the control
// from the edge of the map
controlDiv.style.padding = '5px';
// Set CSS for the control border
var goHomeUI = document.createElement('DIV');
goHomeUI.style.backgroundColor = 'white';
goHomeUI.style.borderStyle = 'solid';
goHomeUI.style.borderWidth = '2px';
goHomeUI.style.cursor = 'pointer';
goHomeUI.style.textAlign = 'center';
goHomeUI.title = 'Show only Sites';
controlDiv.appendChild(goHomeUI);
// Set CSS for the control interior
var goHomeText = document.createElement('DIV');
goHomeText.style.fontFamily = 'Arial,sans-serif';
goHomeText.style.fontSize = '12px';
goHomeText.style.paddingLeft = '4px';
goHomeText.style.paddingRight = '4px';
goHomeText.innerHTML = 'Sites';
goHomeUI.appendChild(goHomeText);
// Setup the click event listener for Home:
// simply set the map to the control's current home property.
google.maps.event.addDomListener(goHomeUI, 'click', function() {
if (goHomeText.innerHTML == 'Sites') {
goHomeUI.title = 'Show only Shops';
goHomeText.innerHTML = 'Shops';
display("Site");
}
else if (goHomeText.innerHTML == 'Shops') {
goHomeUI.title = 'Show Sites and Shops';
goHomeText.innerHTML = 'Both';
display("Shop");
}
else if (goHomeText.innerHTML == 'Both'){
goHomeUI.title = 'Show only Sites';
goHomeText.innerHTML = 'Sites';
display("Both");
}
});
}
function load() {
var latlng = new google.maps.LatLng(53.344104,-6.267494);
var contentString = ' ';
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var infoWindow = new google.maps.InfoWindow;
// Create the DIV to hold the control and
// call the HomeControl() constructor passing
// in this DIV.
var homeControlDiv = document.createElement('DIV');
var homeControl = new HomeControl(map, homeControlDiv, latlng);
homeControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
downloadUrl("ias_genxml.php", function(data) {
var xml = parseXml(data);
var markers = xml.documentElement.getElementsByTagName("marker");
var markerBounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
if ((markers[i].getAttribute("type")=='Shop') || (markers[i].getAttribute("type")=='Site')) {
// Setup Title
var Site_Title = markers[i].getAttribute("name");
var this_id = markers[i].getAttribute("id");
// Setup Icons
if (markers[i].getAttribute("type")=='Shop') {
var Site_icon_url = '/images/tools.png';
} else if (markers[i].getAttribute("type")=='Site') {
var Site_icon_url = '/images/military.png';
}
// Setup Long Lat position
var Site_LatLng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
// Setup Site Marker
var Site_Marker = new google.maps.Marker({ position: Site_LatLng , map: map, icon: Site_icon_url, title: Site_Title});
//var Site_Marker = new google.maps.Marker({ position: Site_LatLng , map: map, title: Site_Title, icon: Site_icon_url});
//var beachMarker = new google.maps.Marker({ position: myLatLng, map: map, icon: image});
//http://maps.google.com/maps?saddr=53.146500,-6.828604
var Site_URL_From = 'http://maps.google.com/maps?saddr=' + parseFloat(markers[i].getAttribute("lat")) + ',' + parseFloat(markers[i].getAttribute("lng"));
var Site_URL_To = 'http://maps.google.com/maps?daddr=' + parseFloat(markers[i].getAttribute("lat")) + ',' + parseFloat(markers[i].getAttribute("lng"));
// Keep list of all loaded Markers to be able to access at a later stage
loadedmarkers[i] = Site_Marker;
markerBounds.extend(Site_LatLng);
// Setup Content of InfoWindow
//Website
if (markers[i].getAttribute("websiteURL") == '') {
var Site_Content = Site_Title+'
Directions: <From here> <To here>';
} else {
var Site_Content = ''+Site_Title+'
Directions: <From here> <To here>';
}
/* //Photosite
if (markers[i].getAttribute("photoURL") == '') {
var Site_Content_photosite = '<No Photosite>';
} else {
var Site_Content_photosite = '<Photosite>';
}
*/
//var Site_Content = Site_Title+'
'+ Site_Content_website + ' ' +Site_Content_photosite + '
Directions: <From here> <To here>';
bindInfoWindow(Site_Marker, map, infoWindow, Site_Content);
}
}
});
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
//display("Site");
}
function bindInfoWindow(marker, map, infoWindow, html) {
//alert (html);
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function parseXml(str) {
if (window.ActiveXObject) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
} else if (window.DOMParser) {
return (new DOMParser).parseFromString(str, 'text/xml');
}
}
function doNothing() {}