Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 273 | Rev 303 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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