New file |
0,0 → 1,169 |
var tableau_couleurs = {"Particulier": "#A9582B", "Établissement scolaire" :"#8DC7B8", |
"Association": "#ED9355","Professionnel": "#A7BD5B", |
"Autre": "#FFC730","Inconnu": "#0000FF"}; |
|
var infowindow = new google.maps.InfoWindow(); |
|
function getUrlBaseJrest() { |
return 'http://162.38.234.9/obs_saisons/applications/jrest/'; |
} |
|
function initialiserCarte() { |
|
if($('#map_canvas').length == 0) { |
return; |
} |
|
var latlng = new google.maps.LatLng(47.0504, 2.2347); |
var myOptions = { |
zoom: 5, |
center: latlng, |
mapTypeId: google.maps.MapTypeId.HYBRID |
}; |
|
map = new google.maps.Map(document.getElementById("map_canvas"), |
myOptions); |
|
$('.lien_vers_profil').live('click', function(event) { |
event.preventDefault(); |
window.open($(this).attr('href')); |
return false; |
}); |
|
obtenirStations(); |
} |
|
function obtenirStations() { |
|
$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) { |
|
infos_stations = data; |
|
for(i in infos_stations) { |
creerEtAjouterMarqueur(i, infos_stations[i]); |
} |
}); |
} |
|
function obtenirImagePourChaineCouleur(chaine_couleur) { |
|
chaine_couleur = encodeURIComponent(chaine_couleur); |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur; |
|
return image; |
} |
|
function creerEtAjouterMarqueur(id_marqueur, infos_station) { |
|
latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']); |
|
|
var chaine_couleur = tableau_couleurs[infos_station['type_participant']]; |
|
for(i in infos_stations.especes) { |
|
} |
|
var image = obtenirImagePourChaineCouleur(chaine_couleur); |
|
var marqueur_station = new google.maps.Marker({ |
position: latlng, |
icon:image, |
title:infos_station.station, |
optimized: false |
}); |
|
google.maps.event.addListener(marqueur_station, 'click', function() { |
|
contenu_fenetre = formaterContenuFenetre(infos_station); |
infowindow.close(); |
infowindow.content = contenu_fenetre; |
infowindow.open(map,this); |
}); |
|
marqueur_station.setDraggable(false); |
marqueur_station.setClickable(true); |
|
marqueur_station.setMap(map); |
} |
|
function formaterContenuFenetre(infos_station) { |
|
var contenu_fenetre = ""; |
contenu_fenetre = "<h3> "+infos_station.station+"</h3>"; |
|
contenu_fenetre += '<div class="infos_participant"> Participant : '+construireUrlProfilParticipant(infos_station.id_participant,infos_station.pseudo_participant)+'</div>'; |
|
contenu_fenetre += '<div class="infos_commune"> '; |
if(infos_station.nom_commune != null && infos_station.nom_commune != "") { |
contenu_fenetre += 'Commune : '+infos_station.nom_commune; |
} |
|
if(infos_station.code_commune != null && infos_station.code_commune != "") { |
contenu_fenetre += ' ('+infos_station.code_commune+')'; |
} |
contenu_fenetre += '</div>'; |
|
|
contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station.altitude+' m</div>'; |
|
console.log(infos_station.especes); |
|
contenu_fenetre_espece = ''; |
if(infos_station.especes != null) { |
|
for(var i in infos_station.especes) { |
contenu_fenetre_espece += '<li>'+infos_station.especes[i].nom_vernaculaire+'</li>'; |
} |
|
|
} |
|
if(contenu_fenetre_espece != '') { |
contenu_fenetre += '<div class="infos_especes"> Especes observées :'; |
contenu_fenetre += '<ul>'+contenu_fenetre_espece+'</ul>'; |
contenu_fenetre += '</div>'; |
} |
|
return contenu_fenetre; |
} |
|
function genererLegende() { |
|
chaine_legende = '<div class="critere" id="legende">'; |
|
for(i in tableau_couleurs) { |
chaine_legende += '<span class="legende" style="background-color:'+tableau_couleurs[i]+'"></span>'; |
chaine_legende += '<label for="type_'+i+'">'+i+'</label><br />'; |
} |
|
chaine_legende += '</div>'; |
|
$("#conteneur_legende").html(chaine_legende); |
} |
|
function obtenirImagePourChaineCouleur(chaine_couleur) { |
|
chaine_couleur = encodeURIComponent(chaine_couleur); |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur; |
|
return image; |
} |
|
function construireUrlProfilParticipant(id, pseudo) { |
|
if(id == null && pseudo == null) { |
return "anonyme"; |
} |
|
if(pseudo == null || pseudo == "null") { |
pseudo = id; |
} |
|
return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>'; |
} |
|
$('#map_canvas').ready(function() { |
initialiserCarte(); |
genererLegende(); |
}); |