Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 303 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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