| 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() {
|
| 270 |
aurelien |
8 |
return 'http://localhost/obs_saisons/applications/jrest/';
|
| 245 |
aurelien |
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 |
|
| 270 |
aurelien |
40 |
var infos_stations = data.stations;
|
|
|
41 |
var stats = data.stats;
|
| 245 |
aurelien |
42 |
|
|
|
43 |
for(i in infos_stations) {
|
|
|
44 |
creerEtAjouterMarqueur(i, infos_stations[i]);
|
|
|
45 |
}
|
| 270 |
aurelien |
46 |
mettreAJourStats(stats);
|
| 245 |
aurelien |
47 |
});
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
function obtenirImagePourChaineCouleur(chaine_couleur) {
|
|
|
51 |
|
|
|
52 |
chaine_couleur = encodeURIComponent(chaine_couleur);
|
|
|
53 |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
|
|
|
54 |
|
|
|
55 |
return image;
|
|
|
56 |
}
|
|
|
57 |
|
| 270 |
aurelien |
58 |
function mettreAJourStats(stats) {
|
|
|
59 |
for(i in stats) {
|
|
|
60 |
if(i != 'total') {
|
|
|
61 |
var id_legende = '#type_'+i.removeDiacritics().replace(' ','_');
|
|
|
62 |
var legende = $(id_legende).text();
|
|
|
63 |
$(id_legende).text(legende+' ('+stats[i]+')');
|
|
|
64 |
} else {
|
|
|
65 |
$('#conteneur_nb_stations').text(stats[i]+' stations au total');
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
| 245 |
aurelien |
70 |
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
|
|
|
71 |
|
|
|
72 |
latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
|
|
|
73 |
|
| 270 |
aurelien |
74 |
var chaine_couleur = tableau_couleurs[infos_station['type_participant']];
|
| 245 |
aurelien |
75 |
var image = obtenirImagePourChaineCouleur(chaine_couleur);
|
| 270 |
aurelien |
76 |
var nom_station = infos_station['nom'];
|
| 247 |
aurelien |
77 |
|
| 245 |
aurelien |
78 |
var marqueur_station = new google.maps.Marker({
|
|
|
79 |
position: latlng,
|
|
|
80 |
icon:image,
|
| 270 |
aurelien |
81 |
title:nom_station,
|
|
|
82 |
optimized: true
|
| 245 |
aurelien |
83 |
});
|
|
|
84 |
|
| 247 |
aurelien |
85 |
google.maps.event.addListener(marqueur_station, 'click', function() {
|
| 245 |
aurelien |
86 |
|
| 247 |
aurelien |
87 |
contenu_fenetre = formaterContenuFenetre(infos_station);
|
| 245 |
aurelien |
88 |
infowindow.close();
|
|
|
89 |
infowindow.content = contenu_fenetre;
|
|
|
90 |
infowindow.open(map,this);
|
| 247 |
aurelien |
91 |
});
|
| 245 |
aurelien |
92 |
|
|
|
93 |
marqueur_station.setDraggable(false);
|
|
|
94 |
marqueur_station.setClickable(true);
|
|
|
95 |
|
|
|
96 |
marqueur_station.setMap(map);
|
| 247 |
aurelien |
97 |
}
|
| 245 |
aurelien |
98 |
|
| 247 |
aurelien |
99 |
function formaterContenuFenetre(infos_station) {
|
|
|
100 |
|
|
|
101 |
var contenu_fenetre = "";
|
| 270 |
aurelien |
102 |
contenu_fenetre = "<h3> "+infos_station['nom']+"</h3>";
|
|
|
103 |
contenu_fenetre += '<div class="infos_participant"> Participant : '+construireUrlProfilParticipant(infos_station['participant'])+'</div>';
|
| 247 |
aurelien |
104 |
contenu_fenetre += '<div class="infos_commune"> ';
|
| 270 |
aurelien |
105 |
if(infos_station['nom_commune'] != null && infos_station['nom_commune'] != "") {
|
|
|
106 |
contenu_fenetre += 'Commune : '+infos_station['nom_commune'];
|
| 247 |
aurelien |
107 |
}
|
|
|
108 |
|
| 270 |
aurelien |
109 |
if(infos_station['code_commune'] != null && infos_station['code_commune'] != "") {
|
|
|
110 |
contenu_fenetre += ' ('+infos_station['code_commune']+')';
|
| 247 |
aurelien |
111 |
}
|
|
|
112 |
contenu_fenetre += '</div>';
|
| 270 |
aurelien |
113 |
contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station['altitude']+' m</div>';
|
| 247 |
aurelien |
114 |
|
|
|
115 |
|
|
|
116 |
return contenu_fenetre;
|
| 245 |
aurelien |
117 |
}
|
|
|
118 |
|
| 247 |
aurelien |
119 |
function genererLegende() {
|
|
|
120 |
|
|
|
121 |
chaine_legende = '<div class="critere" id="legende">';
|
|
|
122 |
|
|
|
123 |
for(i in tableau_couleurs) {
|
|
|
124 |
chaine_legende += '<span class="legende" style="background-color:'+tableau_couleurs[i]+'"></span>';
|
| 270 |
aurelien |
125 |
chaine_legende += '<label id="type_'+i.removeDiacritics().replace(' ','_')+'">'+i+'</label><br />';
|
| 247 |
aurelien |
126 |
}
|
|
|
127 |
|
|
|
128 |
chaine_legende += '</div>';
|
|
|
129 |
|
|
|
130 |
$("#conteneur_legende").html(chaine_legende);
|
|
|
131 |
}
|
|
|
132 |
|
| 245 |
aurelien |
133 |
function obtenirImagePourChaineCouleur(chaine_couleur) {
|
|
|
134 |
|
|
|
135 |
chaine_couleur = encodeURIComponent(chaine_couleur);
|
|
|
136 |
var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
|
|
|
137 |
|
|
|
138 |
return image;
|
|
|
139 |
}
|
|
|
140 |
|
| 270 |
aurelien |
141 |
function construireUrlProfilParticipant(participant) {
|
| 247 |
aurelien |
142 |
|
| 270 |
aurelien |
143 |
if(participant['id'] == null && participant['nom'] == null) {
|
| 247 |
aurelien |
144 |
return "anonyme";
|
|
|
145 |
}
|
|
|
146 |
|
| 270 |
aurelien |
147 |
var id = participant['id'];
|
|
|
148 |
|
|
|
149 |
if(participant['nom'] == null || participant['nom'] == "null") {
|
|
|
150 |
var pseudo = participant['id'];
|
|
|
151 |
} else {
|
|
|
152 |
var pseudo = participant['nom'];
|
| 247 |
aurelien |
153 |
}
|
|
|
154 |
|
|
|
155 |
return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
|
|
|
156 |
}
|
|
|
157 |
|
| 245 |
aurelien |
158 |
$('#map_canvas').ready(function() {
|
|
|
159 |
initialiserCarte();
|
| 247 |
aurelien |
160 |
genererLegende();
|
| 270 |
aurelien |
161 |
});
|
|
|
162 |
|
|
|
163 |
String.prototype.removeDiacritics = function() {
|
|
|
164 |
var diacritics = [
|
|
|
165 |
[/[\300-\306]/g, 'A'],
|
|
|
166 |
[/[\340-\346]/g, 'a'],
|
|
|
167 |
[/[\310-\313]/g, 'E'],
|
|
|
168 |
[/[\350-\353]/g, 'e'],
|
|
|
169 |
[/[\314-\317]/g, 'I'],
|
|
|
170 |
[/[\354-\357]/g, 'i'],
|
|
|
171 |
[/[\322-\330]/g, 'O'],
|
|
|
172 |
[/[\362-\370]/g, 'o'],
|
|
|
173 |
[/[\331-\334]/g, 'U'],
|
|
|
174 |
[/[\371-\374]/g, 'u'],
|
|
|
175 |
[/[\321]/g, 'N'],
|
|
|
176 |
[/[\361]/g, 'n'],
|
|
|
177 |
[/[\307]/g, 'C'],
|
|
|
178 |
[/[\347]/g, 'c'],
|
|
|
179 |
];
|
|
|
180 |
var s = this;
|
|
|
181 |
for (var i = 0; i < diacritics.length; i++) {
|
|
|
182 |
s = s.replace(diacritics[i][0], diacritics[i][1]);
|
|
|
183 |
}
|
|
|
184 |
return s;
|
|
|
185 |
}
|