247 |
aurelien |
1 |
var tableau_couleurs = {"Particulier": "#A9582B", "Établissement scolaire" :"#8DC7B8",
|
|
|
2 |
"Association": "#ED9355","Professionnel": "#A7BD5B",
|
|
|
3 |
"Autre": "#FFC730","Inconnu": "#0000FF"};
|
|
|
4 |
|
|
|
5 |
var infowindow = new google.maps.InfoWindow();
|
|
|
6 |
|
245 |
aurelien |
7 |
function getUrlBaseJrest() {
|
|
|
8 |
return 'http://162.38.234.9/obs_saisons/applications/jrest/';
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
function initialiserCarte() {
|
|
|
12 |
|
|
|
13 |
if($('#map_canvas').length == 0) {
|
|
|
14 |
return;
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
var latlng = new google.maps.LatLng(47.0504, 2.2347);
|
|
|
18 |
var myOptions = {
|
|
|
19 |
zoom: 5,
|
|
|
20 |
center: latlng,
|
|
|
21 |
mapTypeId: google.maps.MapTypeId.HYBRID
|
|
|
22 |
};
|
|
|
23 |
|
|
|
24 |
map = new google.maps.Map(document.getElementById("map_canvas"),
|
|
|
25 |
myOptions);
|
|
|
26 |
|
|
|
27 |
$('.lien_vers_profil').live('click', function(event) {
|
|
|
28 |
event.preventDefault();
|
|
|
29 |
window.open($(this).attr('href'));
|
|
|
30 |
return false;
|
|
|
31 |
});
|
|
|
32 |
|
|
|
33 |
obtenirStations();
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
function obtenirStations() {
|
|
|
37 |
|
|
|
38 |
$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {
|
|
|
39 |
|
|
|
40 |
infos_stations = data;
|
|
|
41 |
|
|
|
42 |
for(i in infos_stations) {
|
|
|
43 |
creerEtAjouterMarqueur(i, infos_stations[i]);
|
|
|
44 |
}
|
|
|
45 |
});
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function obtenirImagePourChaineCouleur(chaine_couleur) {
|
|
|
49 |
|
|
|
50 |
chaine_couleur = encodeURIComponent(chaine_couleur);
|
|
|
51 |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
|
|
|
52 |
|
|
|
53 |
return image;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
|
|
|
57 |
|
|
|
58 |
latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
|
|
|
59 |
|
247 |
aurelien |
60 |
|
|
|
61 |
var chaine_couleur = tableau_couleurs[infos_station['type_participant']];
|
|
|
62 |
|
245 |
aurelien |
63 |
for(i in infos_stations.especes) {
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
var image = obtenirImagePourChaineCouleur(chaine_couleur);
|
247 |
aurelien |
68 |
|
245 |
aurelien |
69 |
var marqueur_station = new google.maps.Marker({
|
|
|
70 |
position: latlng,
|
|
|
71 |
icon:image,
|
|
|
72 |
title:infos_station.station,
|
|
|
73 |
optimized: false
|
|
|
74 |
});
|
|
|
75 |
|
247 |
aurelien |
76 |
google.maps.event.addListener(marqueur_station, 'click', function() {
|
245 |
aurelien |
77 |
|
247 |
aurelien |
78 |
contenu_fenetre = formaterContenuFenetre(infos_station);
|
245 |
aurelien |
79 |
infowindow.close();
|
|
|
80 |
infowindow.content = contenu_fenetre;
|
|
|
81 |
infowindow.open(map,this);
|
247 |
aurelien |
82 |
});
|
245 |
aurelien |
83 |
|
|
|
84 |
marqueur_station.setDraggable(false);
|
|
|
85 |
marqueur_station.setClickable(true);
|
|
|
86 |
|
|
|
87 |
marqueur_station.setMap(map);
|
247 |
aurelien |
88 |
}
|
245 |
aurelien |
89 |
|
247 |
aurelien |
90 |
function formaterContenuFenetre(infos_station) {
|
|
|
91 |
|
|
|
92 |
var contenu_fenetre = "";
|
|
|
93 |
contenu_fenetre = "<h3> "+infos_station.station+"</h3>";
|
|
|
94 |
|
|
|
95 |
contenu_fenetre += '<div class="infos_participant"> Participant : '+construireUrlProfilParticipant(infos_station.id_participant,infos_station.pseudo_participant)+'</div>';
|
|
|
96 |
|
|
|
97 |
contenu_fenetre += '<div class="infos_commune"> ';
|
|
|
98 |
if(infos_station.nom_commune != null && infos_station.nom_commune != "") {
|
|
|
99 |
contenu_fenetre += 'Commune : '+infos_station.nom_commune;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
if(infos_station.code_commune != null && infos_station.code_commune != "") {
|
|
|
103 |
contenu_fenetre += ' ('+infos_station.code_commune+')';
|
|
|
104 |
}
|
|
|
105 |
contenu_fenetre += '</div>';
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station.altitude+' m</div>';
|
|
|
109 |
|
|
|
110 |
console.log(infos_station.especes);
|
|
|
111 |
|
|
|
112 |
contenu_fenetre_espece = '';
|
|
|
113 |
if(infos_station.especes != null) {
|
|
|
114 |
|
|
|
115 |
for(var i in infos_station.especes) {
|
|
|
116 |
contenu_fenetre_espece += '<li>'+infos_station.especes[i].nom_vernaculaire+'</li>';
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
if(contenu_fenetre_espece != '') {
|
|
|
123 |
contenu_fenetre += '<div class="infos_especes"> Especes observées :';
|
|
|
124 |
contenu_fenetre += '<ul>'+contenu_fenetre_espece+'</ul>';
|
|
|
125 |
contenu_fenetre += '</div>';
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
return contenu_fenetre;
|
245 |
aurelien |
129 |
}
|
|
|
130 |
|
247 |
aurelien |
131 |
function genererLegende() {
|
|
|
132 |
|
|
|
133 |
chaine_legende = '<div class="critere" id="legende">';
|
|
|
134 |
|
|
|
135 |
for(i in tableau_couleurs) {
|
|
|
136 |
chaine_legende += '<span class="legende" style="background-color:'+tableau_couleurs[i]+'"></span>';
|
|
|
137 |
chaine_legende += '<label for="type_'+i+'">'+i+'</label><br />';
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
chaine_legende += '</div>';
|
|
|
141 |
|
|
|
142 |
$("#conteneur_legende").html(chaine_legende);
|
|
|
143 |
}
|
|
|
144 |
|
245 |
aurelien |
145 |
function obtenirImagePourChaineCouleur(chaine_couleur) {
|
|
|
146 |
|
|
|
147 |
chaine_couleur = encodeURIComponent(chaine_couleur);
|
|
|
148 |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
|
|
|
149 |
|
|
|
150 |
return image;
|
|
|
151 |
}
|
|
|
152 |
|
247 |
aurelien |
153 |
function construireUrlProfilParticipant(id, pseudo) {
|
|
|
154 |
|
|
|
155 |
if(id == null && pseudo == null) {
|
|
|
156 |
return "anonyme";
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
if(pseudo == null || pseudo == "null") {
|
|
|
160 |
pseudo = id;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
|
|
|
164 |
}
|
|
|
165 |
|
245 |
aurelien |
166 |
$('#map_canvas').ready(function() {
|
|
|
167 |
initialiserCarte();
|
247 |
aurelien |
168 |
genererLegende();
|
245 |
aurelien |
169 |
});
|