﻿//          ________
//          |/\/\/\|
//          | o o  |
//-----oOOO---(_---OOOo---------------------------------------------------------------------------------------
//
// Auteur      : Chanh T.Do [Thoransoft - 2008.04.08]
// Description : fichier contenant les fonctions de la google map
// JScript File
//------------------------------------------------------------------------------------------------------------

/**
* @fileOverview
  gmap.js [JScript File]: <br>
  Scripts de fonctions globales utilisées dans le site de l'ATR pour afficher les cartes des résions<br>
  @author: Chanh T.Do [www.thoransoft.com - 2008.05.16] <br>
  Version 1.0 */

/** objectMap pour google */
map = "";

/** Fonction permettant de créer une map google de type GMap2 et la placer dans un container
    de type DIV.
    @param {string} mapID - ID du container */
function initGMap(mapID)
{
  map = new GMap2(document.getElementById(mapID));    //Instancier une map google
}


/** Fonction permettant de créer un point d'intérêt.
    @param {object} point - Objet contenant la longitude et la latitude
    @param {string} text - Texte que l'on veut afficher dans l'info-bulle
    @return objet marker
    @type object */
function createMarker(point,text) 
{
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });
  return marker;    //Fonction qui affiche l'info bulle légende sur le marqueur
}


/** Fonction permettant d'instancier la google Map 
    @param {string} mapID - ID du conteneur de la map (à l'occurence ID du DIV) 
    @param {int} Lat - Latitude
    @param {int} Lng - Longitude
    @param {int} Zoom - Zoom de la map (entre 1 et 16)
    @param {string} TextAffiche - Texte à afficher dans l'info-bulle 
    @param {bool} optAffiche - True or false (True = affiche l'info-bulle au load) */
function loadGmapByLatLng(Lat, Lng, Zoom, TextAffiche, optAffiche)
{
  if (GBrowserIsCompatible()) 
  {
    //javascript:void(prompt('',gApplication.getMap().getCenter()));
    //Utiliser la ligne de commande ci-dessus dans google map pour obtenir la longitude et latitude d'une adresse
    	
	map.setCenter(new GLatLng(Lat,Lng),Zoom );              //Affiche la carte au lieu précis (centrer)
	map.setCenter(point,Zoom );                             //Affiche la carte au lieu précis (centrer)
	map.addControl(new GSmallMapControl());                 //Affiche le curseur de zoom
	map.addControl(new GMapTypeControl());                  //Affiche le curseur de déplacement
	 
	var point = new GLatLng(Lat,Lng);
	var marker = createMarker(point,TextAffiche);
	map.addOverlay(marker);                         
	
	//Afficher l'info-bulle au load si l'option optAffiche true
	if (optAffiche) { marker.openInfoWindowHtml(TextAffiche); }
  }
}


/** Fonction permettant d'obtenir la latitude et longitude par l'adresse
    @param {string} adr - contient l'adresse (exemple: 1600 Amphitheatre Parkway, Mountain View, CA) 
    @param {int} zoom - Zoom de la map (entre 1 et 16) 
    @param {bool} bmarker - True si on veut un marker et false si on n'en veut pas */
function loadMapByAdr(title, adr, zoom, bmarker)
{
  var geocoder = new GClientGeocoder();
  geocoder.getLatLng(adr, 
                     function (point) 
                     { if (!point) { /*alert("Google message: " + adr + " not found");*/ } 
                       else { map.setCenter(point, zoom); 
                              map.addControl(new GSmallMapControl());   //Affiche le curseur de zoom
                              map.addControl(new GMapTypeControl());    //Affiche le curseur de déplacement
                              if (bmarker)
                              {
                                var marker = createMarker(point, "<br>" + title + "<br>" + adr);
                                map.addOverlay(marker);
                              }
                            }
                     });
}
