/***************************************************************************************
/*
/*	Code nécessaire pour l'affichage de la cartographie Google et GeoPortail
/*
/**************************************************************************************/


// Crée le marqueur avec l'étiquette
function createMarker(point, nom, imageURL)
{
	var IconPoint = new GIcon();
	IconPoint.image = "http://www.infotbc.com/img/carto/" + imageURL;
	IconPoint.iconSize = new GSize(20, 20);
	IconPoint.shadowSize = new GSize(20, 20);
	IconPoint.iconAnchor = new GPoint(6, 20);
	IconPoint.infoWindowAnchor = new GPoint(5, 1);
	var marker = new GMarker(point, IconPoint);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(nom);
	});
	return marker;
}
    
// Crée un rectange de vue, afin de recupérer la valeur du zoom
function Bound(x1, y1, x2, y2) {
	var pointSW = new GLatLng(Math.min(y1,y2), Math.min(x1,x2));
	var pointNE = new GLatLng(Math.max(y1,y2), Math.max(x1,x2));
	var Bound = new GLatLngBounds(pointSW, pointNE);
	return Bound;
}
    
// Charge Google Maps
function load(CartoType, x1, y1, nom1, x2, y2, nom2)
{
switch (CartoType)
	{
	case "Google":
		if (GBrowserIsCompatible())
		{
		var map = new GMap2(document.getElementById("map"));
		// Configure l'interface
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
		// Centre la vue
		map.setCenter(new GLatLng(y1, x1), 15);
		// Ajoute le 1er marqueur
		        
		        
		if (x2!="0" || y2!="0")
			{	
					
				// Ajoute le 1er marqueur : marqueur de départ
				var point2 = new GLatLng(y2, x2);
				map.addOverlay(createMarker(point2, nom2, "start_stop.gif"));
				// Ajoute le 2eme marqueur : marqueur d'arrivé
				var point1 = new GLatLng(y1, x1);
				map.addOverlay(createMarker(point1, nom1, "end_stop.gif"));
						

						
				map.openInfoWindow(point2, nom2);
				// Centre la vue
				map.setCenter(new GLatLng((y1+y2)/2, (x1+x2)/2), map.getBoundsZoomLevel(Bound(x1,y1,x2,y2))-1);	
			}
		else
			{
				// Ajoute le marqueur d'arrêt
				var point1 = new GLatLng(y1, x1);
				map.addOverlay(createMarker(point1, nom1, "stop.gif"));
				map.openInfoWindow(point1, nom1);
			}
		}
	break;
	case "GeoPortail":
		// Code Geoportail à insérer
		alert("Le service de Geoportail sera prochainement disponible.")
	break;
	}

}
