Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 270 | Rev 288 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 270 Rev 273
1
var tableau_couleurs = {"Particulier": "#A9582B", "Établissement scolaire" :"#8DC7B8",
1
var tableau_couleurs = {"particulier": "#A9582B", "etablissement_scolaire" :"#8DC7B8",
2
						"Association": "#ED9355","Professionnel": "#A7BD5B",
2
						"association": "#0000FF","professionnel": "#A7BD5B",
3
						"Autre": "#FFC730","Inconnu": "#0000FF"};
3
						"autre": "#FFC730"};
4
 
4
 
-
 
5
var infowindow = new google.maps.InfoWindow();
-
 
6
var types_affiches = new Array();
5
var infowindow = new google.maps.InfoWindow();
7
var marqueurs = new Array();
6
 
8
 
7
function getUrlBaseJrest() {
9
function getUrlBaseJrest() {
8
	return 'http://localhost/obs_saisons/applications/jrest/';
10
	return 'http://localhost/obs_saisons/applications/jrest/';
9
}
11
}
10
 
12
 
11
function initialiserCarte() {
13
function initialiserCarte() {
12
 
14
 
13
	if($('#map_canvas').length == 0) {
15
	if($('#map_canvas').length == 0) {
14
		return;
16
		return;
15
	}
17
	}
16
 
18
 
17
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
19
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
18
	var myOptions = {
20
	var myOptions = {
19
		zoom: 5,
21
		zoom: 5,
20
		center: latlng,
22
		center: latlng,
21
		mapTypeId: google.maps.MapTypeId.HYBRID
23
		mapTypeId: google.maps.MapTypeId.HYBRID
22
	};
24
	};
23
 
25
 
24
	map = new google.maps.Map(document.getElementById("map_canvas"),
26
	map = new google.maps.Map(document.getElementById("map_canvas"),
25
    	myOptions);
27
    	myOptions);
26
	
28
	
27
	$('.lien_vers_profil').live('click', function(event) {
29
	$('.lien_vers_profil').live('click', function(event) {
28
		event.preventDefault();
30
		event.preventDefault();
29
		window.open($(this).attr('href'));
31
		window.open($(this).attr('href'));
30
		return false;
32
		return false;
31
	});
33
	});
32
	
34
	
33
	obtenirStations();
35
	obtenirStations();
34
}
36
}
35
 
37
 
36
function obtenirStations() {
38
function obtenirStations() {
37
	
39
	
38
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
40
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
39
				
41
				
40
		var infos_stations = data.stations;
42
		var infos_stations = data.stations;
41
		var stats = data.stats;
43
		var stats = data.stats;
42
				
44
				
43
		for(i in infos_stations) {
45
		for(i in infos_stations) {
44
			creerEtAjouterMarqueur(i, infos_stations[i]);
46
			creerEtAjouterMarqueur(i, infos_stations[i]);
45
		}
47
		}
46
		mettreAJourStats(stats);
48
		genererLegende(stats);
47
	});
49
	});
48
}
50
}
49
 
51
 
50
function obtenirImagePourChaineCouleur(chaine_couleur) {
52
function obtenirImagePourChaineCouleur(chaine_couleur) {
51
	
53
	
52
	chaine_couleur = encodeURIComponent(chaine_couleur);
54
	chaine_couleur = encodeURIComponent(chaine_couleur);
53
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
55
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
54
    
56
    
55
    return image;
57
    return image;
56
}
58
}
57
 
59
 
-
 
60
function genererLegende(stats) {	
58
function mettreAJourStats(stats) {
61
	chaine_legende = '<div class="critere" id="legende">';	
59
	for(i in stats) {
62
	for(i in stats) {
60
		if(i != 'total') {
63
		if(i != 'total') {
61
			var id_legende = '#type_'+i.removeDiacritics().replace(' ','_');
64
			var intitule_type = i.formaterTypePourBalise();
62
			var legende = $(id_legende).text();
65
			var id_legende = 'type_'+intitule_type;
-
 
66
			var legende = i+' ('+stats[i]+')';
-
 
67
			var couleur = tableau_couleurs[intitule_type];
-
 
68
			chaine_legende += '<input class="selecteur_type" type="checkbox" value="'+intitule_type+'" id="selecteur_'+id_legende+'" />'+
-
 
69
							  '<span class="legende" style="background-color:'+couleur+'"></span>'+
-
 
70
							  '<label id="'+id_legende+'">'+legende+'</label>'+
63
			$(id_legende).text(legende+' ('+stats[i]+')');
71
							  '<br />';
64
		} else {
72
		} else {
65
			$('#conteneur_nb_stations').text(stats[i]+' stations au total');
73
			$('#conteneur_nb_stations').text(stats[i]+' stations au total');
66
		}
74
		}
67
	}
75
	}
-
 
76
	chaine_legende += '</div>';
-
 
77
	$("#conteneur_legende").html(chaine_legende);
-
 
78
	
-
 
79
	$('.selecteur_type').change(function() {
-
 
80
		types_affiches = new Array();
-
 
81
		$('.selecteur_type:checked').each(function(){
-
 
82
			types_affiches.push($(this).attr("id").replace("selecteur_type_",'')); 
-
 
83
		}); 
-
 
84
		afficherMarqueursSelectionnes();
-
 
85
	})
68
}
86
}
69
 
87
 
70
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
88
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
71
	
89
	
72
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
90
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
73
		
-
 
-
 
91
	var intitule_type = infos_station['type_participant'].formaterTypePourBalise();
74
	var chaine_couleur = tableau_couleurs[infos_station['type_participant']];	
92
	var chaine_couleur = tableau_couleurs[intitule_type];	
75
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
93
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
76
    var nom_station = infos_station['nom'];
94
    var nom_station = infos_station['nom'];
77
    	
95
    	
78
 	var marqueur_station = new google.maps.Marker({
96
 	var marqueur_station = new google.maps.Marker({
79
	      position: latlng,
97
	      position: latlng,
80
	      icon:image,
98
	      icon:image,
-
 
99
	      code:intitule_type,
81
	      title:nom_station,
100
	      title:nom_station,
82
	      optimized: true
101
	      optimized: true
83
	});
102
	});
84
 
103
 
85
	google.maps.event.addListener(marqueur_station, 'click', function() {
104
	google.maps.event.addListener(marqueur_station, 'click', function() {
86
		
105
		
87
		contenu_fenetre = formaterContenuFenetre(infos_station);
106
		contenu_fenetre = formaterContenuFenetre(infos_station);
88
		infowindow.close();
107
		infowindow.close();
89
		infowindow.content = contenu_fenetre;
108
		infowindow.content = contenu_fenetre;
90
		infowindow.open(map,this);
109
		infowindow.open(map,this);
91
	});
110
	});
92
	
111
	
93
 	marqueur_station.setDraggable(false);
112
 	marqueur_station.setDraggable(false);
94
 	marqueur_station.setClickable(true);
113
 	marqueur_station.setClickable(true);
95
		
114
		
-
 
115
 	marqueur_station.setMap(map); 	
-
 
116
 	marqueurs.push(marqueur_station);
-
 
117
}
-
 
118
 
-
 
119
function afficherMarqueursSelectionnes() {
-
 
120
	for(i in marqueurs) {
-
 
121
		var afficher = (types_affiches.length == 0 || jQuery.inArray(marqueurs[i].code, types_affiches) > -1) ? true : false;
-
 
122
		marqueurs[i].setVisible(afficher);
96
 	marqueur_station.setMap(map); 
123
	}
97
}
124
}
98
 
125
 
99
function formaterContenuFenetre(infos_station) {
126
function formaterContenuFenetre(infos_station) {
100
	
127
	
101
	var contenu_fenetre = "";
128
	var contenu_fenetre = "";
102
	contenu_fenetre = "<h3> "+infos_station['nom']+"</h3>";
129
	contenu_fenetre = "<h3> "+infos_station['nom']+"</h3>";
103
	contenu_fenetre += '<div class="infos_participant"> Participant  : '+construireUrlProfilParticipant(infos_station['participant'])+'</div>';
130
	contenu_fenetre += '<div class="infos_participant"> Participant  : '+construireUrlProfilParticipant(infos_station['participant'])+'</div>';
104
	contenu_fenetre += '<div class="infos_commune"> ';
131
	contenu_fenetre += '<div class="infos_commune"> ';
105
	if(infos_station['nom_commune'] != null && infos_station['nom_commune'] != "") {
132
	if(infos_station['nom_commune'] != null && infos_station['nom_commune'] != "") {
106
		contenu_fenetre += 'Commune : '+infos_station['nom_commune'];
133
		contenu_fenetre += 'Commune : '+infos_station['nom_commune'];
107
	}
134
	}
108
	
135
	
109
	if(infos_station['code_commune'] != null && infos_station['code_commune'] != "") {
136
	if(infos_station['code_commune'] != null && infos_station['code_commune'] != "") {
110
		contenu_fenetre += ' ('+infos_station['code_commune']+')';
137
		contenu_fenetre += ' ('+infos_station['code_commune']+')';
111
	}
138
	}
112
	contenu_fenetre += '</div>';
139
	contenu_fenetre += '</div>';
113
	contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station['altitude']+' m</div>';
140
	contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station['altitude']+' m</div>';
114
 
141
 
115
	
142
	
116
	return contenu_fenetre;
143
	return contenu_fenetre;
117
}
144
}
118
 
-
 
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>';
-
 
125
		chaine_legende += '<label id="type_'+i.removeDiacritics().replace(' ','_')+'">'+i+'</label><br />';
-
 
126
	}
-
 
127
	
-
 
128
	chaine_legende += '</div>';
-
 
129
	
-
 
130
	$("#conteneur_legende").html(chaine_legende);
-
 
131
}
-
 
132
 
145
 
133
function obtenirImagePourChaineCouleur(chaine_couleur) {
146
function obtenirImagePourChaineCouleur(chaine_couleur) {
134
	
147
	
135
	chaine_couleur = encodeURIComponent(chaine_couleur);
148
	chaine_couleur = encodeURIComponent(chaine_couleur);
136
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
149
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
137
    
150
    
138
    return image;
151
    return image;
139
}
152
}
140
 
153
 
141
function construireUrlProfilParticipant(participant) {
154
function construireUrlProfilParticipant(participant) {
142
	
155
	
143
	if(participant['id'] == null && participant['nom'] == null) {
156
	if(participant['id'] == null && participant['nom'] == null) {
144
		return "anonyme";
157
		return "anonyme";
145
	}
158
	}
146
	
159
	
147
	var id = participant['id'];
160
	var id = participant['id'];
148
	
161
	
149
	if(participant['nom'] == null || participant['nom'] == "null") {
162
	if(participant['nom'] == null || participant['nom'] == "null") {
150
		var pseudo = participant['id'];
163
		var pseudo = participant['id'];
151
	} else {
164
	} else {
152
		var pseudo = participant['nom'];
165
		var pseudo = participant['nom'];
153
	}
166
	}
154
	
167
	
155
	return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
168
	return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
156
}
169
}
157
 
170
 
158
$('#map_canvas').ready(function() {
171
$('#map_canvas').ready(function() {
159
	initialiserCarte();
172
	initialiserCarte();
160
	genererLegende();
-
 
161
});
173
});
-
 
174
 
-
 
175
String.prototype.formaterTypePourBalise = function() {
-
 
176
	var s = this;
-
 
177
	return s.removeDiacritics().replace(' ','_').toLowerCase();
-
 
178
}
162
 
179
 
163
String.prototype.removeDiacritics = function() {
180
String.prototype.removeDiacritics = function() {
164
	var diacritics = [
181
	var diacritics = [
165
	    [/[\300-\306]/g, 'A'],
182
	    [/[\300-\306]/g, 'A'],
166
	    [/[\340-\346]/g, 'a'],
183
	    [/[\340-\346]/g, 'a'],
167
	    [/[\310-\313]/g, 'E'],
184
	    [/[\310-\313]/g, 'E'],
168
	    [/[\350-\353]/g, 'e'],
185
	    [/[\350-\353]/g, 'e'],
169
	    [/[\314-\317]/g, 'I'],
186
	    [/[\314-\317]/g, 'I'],
170
	    [/[\354-\357]/g, 'i'],
187
	    [/[\354-\357]/g, 'i'],
171
	    [/[\322-\330]/g, 'O'],
188
	    [/[\322-\330]/g, 'O'],
172
	    [/[\362-\370]/g, 'o'],
189
	    [/[\362-\370]/g, 'o'],
173
	    [/[\331-\334]/g, 'U'],
190
	    [/[\331-\334]/g, 'U'],
174
	    [/[\371-\374]/g, 'u'],
191
	    [/[\371-\374]/g, 'u'],
175
	    [/[\321]/g, 'N'],
192
	    [/[\321]/g, 'N'],
176
	    [/[\361]/g, 'n'],
193
	    [/[\361]/g, 'n'],
177
	    [/[\307]/g, 'C'],
194
	    [/[\307]/g, 'C'],
178
	    [/[\347]/g, 'c'],
195
	    [/[\347]/g, 'c'],
179
	];
196
	];
180
	var s = this;
197
	var s = this;
181
	for (var i = 0; i < diacritics.length; i++) {
198
	for (var i = 0; i < diacritics.length; i++) {
182
	    s = s.replace(diacritics[i][0], diacritics[i][1]);
199
	    s = s.replace(diacritics[i][0], diacritics[i][1]);
183
	}
200
	}
184
	return s;
201
	return s;
185
}
202
}