// Procédures globales du projet
function PGESTIONEARTH_LOD(event){{PGESTIONEARTH_ge=0}}
function GoogleEarthinitialisation(sNomChamp)
{
	google.earth.createInstance(sNomChamp, initCB, failureCB);

}

function initCB(instance)
{
	ge = instance;
	ge.getWindow().setVisibility(true);
	ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
}

function failureCB(errorCode)
{
}

function GoogleEarthAfficherCarte()
{
	google.setOnLoadCallback(GoogleEarthinitialisation);
}

function GoogleEarthCreerMarqueur(lat,long,NomMarqueur,zoom)
{
	//Création du marqueur
	var placemark = ge.createPlacemark('');
	placemark.setName(NomMarqueur);
	
	//Positionnement du marqueur
	var point = ge.createPoint('');
	point.setLatitude(lat);
	point.setLongitude(long);
	placemark.setGeometry(point);
	
	// Création style pour la carte.
	var styleMap = ge.createStyleMap('');
	
	// style normal pour la carte.
	var normalStyle = ge.createStyle('');
	var normalIcon = ge.createIcon('');
	normalIcon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
	normalStyle.getIconStyle().setIcon(normalIcon);
	
	var highlightStyle = ge.createStyle('');
	var highlightIcon = ge.createIcon('');
	highlightIcon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
	highlightStyle.getIconStyle().setIcon(highlightIcon);
	highlightStyle.getIconStyle().setScale(1.5); // 1.0 : 100%
	
	styleMap.setNormalStyle(normalStyle);
	styleMap.setHighlightStyle(highlightStyle);
	
	// Application du style pour le marqueur.
	placemark.setStyleSelector(styleMap);
	
	//Add the placemark to Earth.
	ge.getFeatures().appendChild(placemark);
	
	// positionnement de la caméra.
	//Récupération de la vue courante.
	var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	
	// Changement de la latitude et longitude.
	lookAt.setLatitude(lat);
	lookAt.setLongitude(long);
	// Zoom
	lookAt.setRange(zoom);
	
	// Mise à jour de la vue dans Google Earth.
	ge.getView().setAbstractView(lookAt);
	
}

function GoogleEarthAfficherKMLDepuisURL(sURL)
{
	var link = ge.createLink('');
	var href = sURL;
	link.setHref(href);
	
	var networkLink = ge.createNetworkLink('');
	networkLink.set(link, true, true); // Sets the link, refreshVisibility, and flyToView
	
	ge.getFeatures().appendChild(networkLink);
}

function GoogleEarthOptions(Type,bval)
{
	var layerRoot = ge.getLayerRoot();
	switch (Type){
		case 1:
			layerRoot.enableLayerById(ge.LAYER_TERRAIN, bval);
			break;
		case 2:
			layerRoot.enableLayerById(ge.LAYER_ROADS, bval);
			break;
		case 3:
			layerRoot.enableLayerById(ge.LAYER_BUILDINGS, bval);
			break;
		case 4:
			layerRoot.enableLayerById(ge.LAYER_BORDERS, bval);
			break;
	};
	ge.getOptions().setFlyToSpeed(.50); 
	
}
function GoogleEarthGrilleCoordonnees(bb)
{
	// grille des coordonnées
	ge.getOptions().setGridVisibility(bb); 
}
function GoogleEarthBarreStatus(bb)
{
	//position géographique + altitude
	ge.getOptions().setStatusBarVisibility(bb); 
}

function GoogleEarthMiniMap(bb)
{
	// mini map du monde en bas à droite de la carte
	ge.getOptions().setOverviewMapVisibility(bb);
}

function GoogleEarthEchelle(bb)
{
	// l'échelle en bas à gauche
	ge.getOptions().setScaleLegendVisibility(bb); 
}

function GoogleEarthAtmosphere(bb)
{
	// affiche l'atmosphère
	ge.getOptions().setAtmosphereVisibility(bb); 
}

function GestionNavigationControl(Mode)
{
	switch (Mode) {
		case 1 : 
			ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
			break;
		case 2 :
			ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
			break;
		case 3 :
			ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
			break;
	}
}

function GoogleEarthSupporte()
{
	return google.earth.isSupported();
	
}

function GoogleEarthEstInstalle()
{
	return google.earth.isInstalled();	
}


