Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3857 Rev 3953
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
/**
3
/**
4
* Indication de certaines variables ajoutée par php
4
* Indication de certaines variables ajoutée par php
5
* var communeImageUrl ;
5
* var communeImageUrl ;
6
* var pointImageUrl ;
6
* var pointImageUrl ;
7
* var groupeImageUrlTpl ;
7
* var groupeImageUrlTpl ;
8
*/
8
*/
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
10
	pointsOrigine = null,
10
	pointsOrigine = null,
11
	boundsOrigine = null,
11
	boundsOrigine = null,
12
	markerClusterer = null,
12
	markerClusterer = null,
13
	map = null,
13
	map = null,
14
	infoBulle = new google.maps.InfoWindow(),
14
	infoBulle = new google.maps.InfoWindow(),
15
	stations = null,
15
	stations = null,
16
	pointClique = null,
16
	pointClique = null,
17
	carteCentre = new google.maps.LatLng(25, 10),
17
	carteCentre = new google.maps.LatLng(25, 10),
18
	carteOptions = {
18
	carteOptions = {
19
		zoom: 3,
19
		zoom: 3,
20
		center:carteCentre,
20
		center:carteCentre,
21
		mapTypeId: 'OSM',
21
		mapTypeId: 'OSM',
22
		mapTypeControlOptions: {
22
		mapTypeControlOptions: {
23
			mapTypeIds: ['OSM',
23
			mapTypeIds: ['OSM',
24
				google.maps.MapTypeId.ROADMAP, 
24
				google.maps.MapTypeId.ROADMAP, 
25
				google.maps.MapTypeId.HYBRID, 
25
				google.maps.MapTypeId.HYBRID, 
26
				google.maps.MapTypeId.SATELLITE, 
26
				google.maps.MapTypeId.SATELLITE, 
27
				google.maps.MapTypeId.TERRAIN
27
				google.maps.MapTypeId.TERRAIN
28
			],
28
			],
29
			position: google.maps.ControlPosition.RIGHT_TOP
29
			position: google.maps.ControlPosition.RIGHT_TOP
30
		},
30
		},
31
		scaleControl: true,
31
		scaleControl: true,
32
		zoomControlOptions: {
32
		zoomControlOptions: {
33
			style: google.maps.ZoomControlStyle.LARGE,
33
			style: google.maps.ZoomControlStyle.LARGE,
34
			position: google.maps.ControlPosition.LEFT_CENTER
34
			position: google.maps.ControlPosition.LEFT_CENTER
35
		},
35
		},
36
		panControl: false
36
		panControl: false
37
	},
37
	},
38
	osmMapType = new google.maps.ImageMapType({
38
	osmMapType = new google.maps.ImageMapType({
39
		getTileUrl: function(coord, zoom) {
39
		getTileUrl: function(coord, zoom) {
40
			return "https://osm.tela-botanica.org/tuiles/osmfr/" + // cache de tuiles avec nginx
40
			return "https://a.tile.openstreetmap.fr/osmfr/" + // cache de tuiles avec nginx
41
			zoom + "/" + coord.x + "/" + coord.y + ".png";
41
			zoom + "/" + coord.x + "/" + coord.y + ".png";
42
		},
42
		},
43
		tileSize: new google.maps.Size(256, 256),
43
		tileSize: new google.maps.Size(256, 256),
44
		isPng: true,
44
		isPng: true,
45
		alt: "OpenStreetMap",
45
		alt: "OpenStreetMap",
46
		name: "OSM",
46
		name: "OSM",
47
		maxZoom: 19
47
		maxZoom: 19
48
	}),
48
	}),
49
	ctaLayer = null,
49
	ctaLayer = null,
50
	pagineur = {'limite':300, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'},
50
	pagineur = {'limite':300, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'},
51
	station = {'commune':'', 'obsNbre':0},
51
	station = {'commune':'', 'obsNbre':0},
52
	obsStation = new Array(),
52
	obsStation = new Array(),
53
	obsPage = new Array(),
53
	obsPage = new Array(),
54
	taxonsCarte = new Array(),
54
	taxonsCarte = new Array(),
55
	mgr = null,
55
	mgr = null,
56
	marqueursCache = new Array(),
56
	marqueursCache = new Array(),
57
	zonesCache = new Array(),
57
	zonesCache = new Array(),
58
	requeteChargementPoints,
58
	requeteChargementPoints,
59
	urlVars = null;
59
	urlVars = null;
60
 
60
 
61
/*+--------------------------------------------------------------------------------------------------------+*/
61
/*+--------------------------------------------------------------------------------------------------------+*/
62
// INITIALISATION DU CODE
62
// INITIALISATION DU CODE
63
 
63
 
64
//Déclenchement d'actions quand JQuery et le document HTML sont OK
64
//Déclenchement d'actions quand JQuery et le document HTML sont OK
65
$(document).ready(function() {
65
$(document).ready(function() {
66
	initialiserWidget();
66
	initialiserWidget();
67
});
67
});
68
 
68
 
69
function initialiserWidget() {
69
function initialiserWidget() {
70
	urlVars = getUrlVars();
70
	urlVars = getUrlVars();
71
	dimensionnerCarte();
71
	dimensionnerCarte();
72
	definirTailleOverlay();
72
	definirTailleOverlay();
73
	initialiserCarte();
73
	initialiserCarte();
74
	attribuerListenersOverlay();
74
	attribuerListenersOverlay();
75
	centrerTitreEtStats();
75
	centrerTitreEtStats();
76
	initialiserAffichagePanneauLateral();
76
	initialiserAffichagePanneauLateral();
77
	initialiserGestionnaireMarqueurs()
77
	initialiserGestionnaireMarqueurs()
78
	initialiserInfoBulle();
78
	initialiserInfoBulle();
79
	initialiserFormulaireContact();
79
	initialiserFormulaireContact();
80
	chargerLimitesCommunales();
80
	chargerLimitesCommunales();
81
	attribuerListenerCarte();
81
	attribuerListenerCarte();
82
}
82
}
83
 
83
 
84
function getUrlVars() {
84
function getUrlVars() {
85
	var vars = [], hash;
85
	var vars = [], hash;
86
	if (window.location.href.indexOf('?') != -1) {
86
	if (window.location.href.indexOf('?') != -1) {
87
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
87
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
88
		for (var i = 0; i < hashes.length; i++) {
88
		for (var i = 0; i < hashes.length; i++) {
89
			hash = hashes[i].split('=');
89
			hash = hashes[i].split('=');
90
			vars.push(hash[0]);
90
			vars.push(hash[0]);
91
			vars[hash[0]] = hash[1];
91
			vars[hash[0]] = hash[1];
92
		}
92
		}
93
	}
93
	}
94
	return vars;
94
	return vars;
95
}
95
}
96
 
96
 
97
/*+--------------------------------------------------------------------------------------------------------+*/
97
/*+--------------------------------------------------------------------------------------------------------+*/
98
// AFFICHAGE GÉNÉRAL
98
// AFFICHAGE GÉNÉRAL
99
 
99
 
100
function afficherTitreCarteEtStats() {
100
function afficherTitreCarteEtStats() {
101
	if (stations != null && taxonsCarte.length > 0) {
101
	if (stations != null && taxonsCarte.length > 0) {
102
		var obsNbre = stations.stats.observations;
102
		var obsNbre = stations.stats.observations;
103
		var obsNbreFormate = obsNbre;
103
		var obsNbreFormate = obsNbre;
104
		if(obsNbre != 0) {
104
		if(obsNbre != 0) {
105
		    obsNbreFormate = stations.stats.observations.formaterNombre();
105
		    obsNbreFormate = stations.stats.observations.formaterNombre();
106
		}
106
		}
107
		var plteNbre = taxonsCarte.length;
107
		var plteNbre = taxonsCarte.length;
108
		var plteNbreFormate = plteNbre;
108
		var plteNbreFormate = plteNbre;
109
		if (plteNbre != 0) {
109
		if (plteNbre != 0) {
110
			plteNbreFormate = taxonsCarte.length.formaterNombre();
110
			plteNbreFormate = taxonsCarte.length.formaterNombre();
111
		}
111
		}
112
		var communeNbre = stations.stats.communes;
112
		var communeNbre = stations.stats.communes;
113
		var communeNbreFormate = communeNbre;
113
		var communeNbreFormate = communeNbre;
114
		if(communeNbre != 0) {
114
		if(communeNbre != 0) {
115
		   communeNbreFormate = stations.stats.communes.formaterNombre();
115
		   communeNbreFormate = stations.stats.communes.formaterNombre();
116
		}
116
		}
117
		var stationNbre = stations.stats.stations;
117
		var stationNbre = stations.stats.stations;
118
		var stationNbreFormate = stationNbre;
118
		var stationNbreFormate = stationNbre;
119
		if(stationNbre != 0) {
119
		if(stationNbre != 0) {
120
		  	stationNbreFormate = stations.stats.stations.formaterNombre();
120
		  	stationNbreFormate = stations.stats.stations.formaterNombre();
121
		}
121
		}
122
	
122
	
123
		var stats = obsNbreFormate + ' ' + ((obsNbre > 1) ? msg('observations') : msg('observation'));
123
		var stats = obsNbreFormate + ' ' + ((obsNbre > 1) ? msg('observations') : msg('observation'));
124
 
124
 
125
		if (photos != null && photos == 1) {
125
		if (photos != null && photos == 1) {
126
			stats += ' ' + msg('avec photos') + ' ';
126
			stats += ' ' + msg('avec photos') + ' ';
127
		}
127
		}
128
		
128
		
129
		stats += ' ' + msg('sur') + ' ' + (stationNbre+ communeNbre)+' ' + ((stationNbre > 1) ? msg('stations') : msg('station'));
129
		stats += ' ' + msg('sur') + ' ' + (stationNbre+ communeNbre)+' ' + ((stationNbre > 1) ? msg('stations') : msg('station'));
130
		
130
		
131
		if (nt == '*') {
131
		if (nt == '*') {
132
			stats += ' ' + msg('parmi') + ' '+plteNbreFormate+' ' + ((plteNbre > 1) ? msg('taxons') : msg('taxon'));
132
			stats += ' ' + msg('parmi') + ' '+plteNbreFormate+' ' + ((plteNbre > 1) ? msg('taxons') : msg('taxon'));
133
		} else {
133
		} else {
134
			if($('.taxon-actif .taxon').text() != '') {
134
			if($('.taxon-actif .taxon').text() != '') {
135
				var element = $('.taxon-actif .taxon').clone();
135
				var element = $('.taxon-actif .taxon').clone();
136
				element.children().remove();
136
				element.children().remove();
137
				var taxon = element.text();
137
				var taxon = element.text();
138
				stats += ' ' + msg('pour') + ' '+taxon;
138
				stats += ' ' + msg('pour') + ' '+taxon;
139
			} else {
139
			} else {
140
				if (taxonsCarte[0]) {
140
				if (taxonsCarte[0]) {
141
					var taxon = taxonsCarte[0];
141
					var taxon = taxonsCarte[0];
142
					stats += ' ' + msg('pour') + ' ' + taxon.nom;
142
					stats += ' ' + msg('pour') + ' ' + taxon.nom;
143
				}
143
				}
144
			}
144
			}
145
		}
145
		}
146
		
146
		
147
		if(utilisateur != '*') {
147
		if(utilisateur != '*') {
148
			stats += " " + msg("pour l'utilisateur") + " "+utilisateur+' ';
148
			stats += " " + msg("pour l'utilisateur") + " "+utilisateur+' ';
149
		}
149
		}
150
		
150
		
151
		$('#zone-stats').show();
151
		$('#zone-stats').show();
152
	} else {
152
	} else {
153
		stats = msg("aucune-observation");
153
		stats = msg("aucune-observation");
154
	}
154
	}
155
	
155
	
156
	$('#zone-stats > h1').text(stats);
156
	$('#zone-stats > h1').text(stats);
157
	centrerTitreEtStats();
157
	centrerTitreEtStats();
158
}
158
}
159
 
159
 
160
function attribuerListenersOverlay() {
160
function attribuerListenersOverlay() {
161
	$(window).resize(function() {
161
	$(window).resize(function() {
162
		dimensionnerCarte();
162
		dimensionnerCarte();
163
		definirTailleOverlay();
163
		definirTailleOverlay();
164
		centrerTitreEtStats();
164
		centrerTitreEtStats();
165
		programmerRafraichissementCarte();
165
		programmerRafraichissementCarte();
166
		google.maps.event.trigger($('#carte'), 'resize');
166
		google.maps.event.trigger($('#carte'), 'resize');
167
	});
167
	});
168
	
168
	
169
	$('#lien_plein_ecran a').click(function(event) {
169
	$('#lien_plein_ecran a').click(function(event) {
170
		window.open(window.location.href);
170
		window.open(window.location.href);
171
		event.preventDefault();
171
		event.preventDefault();
172
	});
172
	});
173
	
173
	
174
	$('#lien-voir-cc a').click(function(event) {		
174
	$('#lien-voir-cc a').click(function(event) {		
175
		ouvrirPopUp(this, msg('Avertissement'), event);
175
		ouvrirPopUp(this, msg('Avertissement'), event);
176
		event.preventDefault();
176
		event.preventDefault();
177
	});
177
	});
178
}
178
}
179
 
179
 
180
var tailleMaxFiltreUtilisateur;
180
var tailleMaxFiltreUtilisateur;
181
function definirTailleOverlay() {
181
function definirTailleOverlay() {
182
	var largeurViewPort = $(window).width(),
182
	var largeurViewPort = $(window).width(),
183
		taille = '1.6',
183
		taille = '1.6',
184
		tailleMaxLogo = 60,
184
		tailleMaxLogo = 60,
185
		tailleMaxIcones = 10,
185
		tailleMaxIcones = 10,
186
		padding_icones = 8,
186
		padding_icones = 8,
187
		tailleFiltre = 80;
187
		tailleFiltre = 80;
188
	tailleMaxFiltreUtilisateur = 350;
188
	tailleMaxFiltreUtilisateur = 350;
189
	$('#raz-filtre-utilisateur').css('display', 'block');
189
	$('#raz-filtre-utilisateur').css('display', 'block');
190
	if (largeurViewPort <= 450) {
190
	if (largeurViewPort <= 450) {
191
		taille = '1';
191
		taille = '1';
192
		tailleMaxIcones = 10;
192
		tailleMaxIcones = 10;
193
		tailleFiltre = 65;
193
		tailleFiltre = 65;
194
		padding_icones = 2;	
194
		padding_icones = 2;	
195
		var tailleMaxLogo = 50;
195
		var tailleMaxLogo = 50;
196
		$('#raz-filtre-utilisateur').css('display', 'inline');
196
		$('#raz-filtre-utilisateur').css('display', 'inline');
197
	} else if (largeurViewPort <= 500) {
197
	} else if (largeurViewPort <= 500) {
198
		taille = '1.2';
198
		taille = '1.2';
199
		tailleMaxIcones = 10;
199
		tailleMaxIcones = 10;
200
		tailleFiltre = 65;
200
		tailleFiltre = 65;
201
		padding_icones = 2;	
201
		padding_icones = 2;	
202
		var tailleMaxLogo = 50;
202
		var tailleMaxLogo = 50;
203
		tailleMaxFiltreUtilisateur = 200;
203
		tailleMaxFiltreUtilisateur = 200;
204
		$('#raz-filtre-utilisateur').css('display', 'inline');
204
		$('#raz-filtre-utilisateur').css('display', 'inline');
205
	} else if (largeurViewPort > 500 && largeurViewPort <= 800) {
205
	} else if (largeurViewPort > 500 && largeurViewPort <= 800) {
206
		taille = '1.4';
206
		taille = '1.4';
207
		tailleMaxIcones = 15;
207
		tailleMaxIcones = 15;
208
		padding_icones = 6;
208
		padding_icones = 6;
209
		tailleFiltre = 65;
209
		tailleFiltre = 65;
210
		var tailleMaxLogo = 55;
210
		var tailleMaxLogo = 55;
211
		tailleMaxFiltreUtilisateur = 250;
211
		tailleMaxFiltreUtilisateur = 250;
212
	} else if (largeurViewPort > 800) {
212
	} else if (largeurViewPort > 800) {
213
		taille = '1.6';
213
		taille = '1.6';
214
		tailleMaxIcones = 20;
214
		tailleMaxIcones = 20;
215
		padding_icones = 8;
215
		padding_icones = 8;
216
		tailleFiltre = 80;
216
		tailleFiltre = 80;
217
		tailleMaxFiltreUtilisateur = 350;
217
		tailleMaxFiltreUtilisateur = 350;
218
	}
218
	}
219
	
219
	
220
	// Aménagement de la taille de police selon l'écran
220
	// Aménagement de la taille de police selon l'écran
221
	$("#carte-titre").css('font-size', taille+'em');
221
	$("#carte-titre").css('font-size', taille+'em');
222
	
222
	
223
	$("#zone-stats h1").css('font-size', Math.round((taille*0.75*100))/100+'em');
223
	$("#zone-stats h1").css('font-size', Math.round((taille*0.75*100))/100+'em');
224
	$("#zone-stats").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
224
	$("#zone-stats").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
225
	$('#zone-stats').height(tailleMaxIcones*1.5);
225
	$('#zone-stats').height(tailleMaxIcones*1.5);
226
	
226
	
227
	$("#zone-titre h1").css('font-size', (taille)+'em');
227
	$("#zone-titre h1").css('font-size', (taille)+'em');
228
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
228
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
229
	$('#zone-titre').height(tailleMaxIcones*2);
229
	$('#zone-titre').height(tailleMaxIcones*2);
230
	
230
	
231
	$('.icone').height(tailleMaxIcones);
231
	$('.icone').height(tailleMaxIcones);
232
	$('#lien_plein_ecran').css("padding", padding_icones+"px "+padding_icones+"px "+Math.ceil(padding_icones/2)+"px");
232
	$('#lien_plein_ecran').css("padding", padding_icones+"px "+padding_icones+"px "+Math.ceil(padding_icones/2)+"px");
233
	
233
	
234
	$('#lien-voir-cc').css("font-size", taille+"em");
234
	$('#lien-voir-cc').css("font-size", taille+"em");
235
	$('#lien-voir-cc').css("padding", padding_icones+"px");
235
	$('#lien-voir-cc').css("padding", padding_icones+"px");
236
	
236
	
237
	$("#panneau-lateral").css('font-size', (taille*0.9)+'em');
237
	$("#panneau-lateral").css('font-size', (taille*0.9)+'em');
238
	$("#pl-contenu").css('font-size', (taille/2)+'em');
238
	$("#pl-contenu").css('font-size', (taille/2)+'em');
239
	
239
	
240
	$("#panneau-lateral").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
240
	$("#panneau-lateral").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
241
	$('#pl-ouverture').height(((padding_icones*2)+$('#panneau-lateral').height())+"px");
241
	$('#pl-ouverture').height(((padding_icones*2)+$('#panneau-lateral').height())+"px");
242
	$("#panneau-lateral").width(tailleFiltre);
242
	$("#panneau-lateral").width(tailleFiltre);
243
	
243
	
244
	$('#lien-affichage-filtre-utilisateur').width(tailleFiltre);
244
	$('#lien-affichage-filtre-utilisateur').width(tailleFiltre);
245
	$('#lien-affichage-filtre-utilisateur').height(tailleFiltre*0.35);
245
	$('#lien-affichage-filtre-utilisateur').height(tailleFiltre*0.35);
246
	$('#lien-affichage-filtre-utilisateur').css('font-size', (taille*0.9)+'em');
246
	$('#lien-affichage-filtre-utilisateur').css('font-size', (taille*0.9)+'em');
247
	$('#conteneur-filtre-utilisateur').css('max-width',tailleMaxFiltreUtilisateur);
247
	$('#conteneur-filtre-utilisateur').css('max-width',tailleMaxFiltreUtilisateur);
248
		
248
		
249
	dimensionnerLogo(tailleMaxLogo);
249
	dimensionnerLogo(tailleMaxLogo);
250
	dimensionnerImage(largeurViewPort);
250
	dimensionnerImage(largeurViewPort);
251
	redimensionnerControleTypeCarte(largeurViewPort);
251
	redimensionnerControleTypeCarte(largeurViewPort);
252
}
252
}
253
 
253
 
254
function dimensionnerLogo(tailleMaxLogo) {
254
function dimensionnerLogo(tailleMaxLogo) {
255
	// Dimensionnement du logo
255
	// Dimensionnement du logo
256
	hauteurLogo = $('.image-logo').height();
256
	hauteurLogo = $('.image-logo').height();
257
	// Redimensionnement du logo s'il est trop grand
257
	// Redimensionnement du logo s'il est trop grand
258
	// on perd en qualité mais ça vaut mieux que de casser l'affichage
258
	// on perd en qualité mais ça vaut mieux que de casser l'affichage
259
	if (hauteurLogo > tailleMaxLogo) {
259
	if (hauteurLogo > tailleMaxLogo) {
260
		hauteurLogo = tailleMaxLogo;
260
		hauteurLogo = tailleMaxLogo;
261
		$('.image-logo').css("top", "5px");
261
		$('.image-logo').css("top", "5px");
262
		$('.image-logo').height(tailleMaxLogo);
262
		$('.image-logo').height(tailleMaxLogo);
263
	}
263
	}
264
	
264
	
265
	if (hauteurLogo == 0) {
265
	if (hauteurLogo == 0) {
266
		$('.image-logo').load(function(event) {
266
		$('.image-logo').load(function(event) {
267
			definirTailleOverlay();
267
			definirTailleOverlay();
268
		});
268
		});
269
		return;
269
		return;
270
	}
270
	}
271
	
271
	
272
	largeurLogo = $('#logo img').width();
272
	largeurLogo = $('#logo img').width();
273
}
273
}
274
 
274
 
275
function dimensionnerImage(largeurViewPort) {
275
function dimensionnerImage(largeurViewPort) {
276
	// Dimensionnement de l'image
276
	// Dimensionnement de l'image
277
	if (largeurViewPort > 500) {
277
	if (largeurViewPort > 500) {
278
		largeurLogo = 155;
278
		largeurLogo = 155;
279
	} else {
279
	} else {
280
		largeurLogo = 70;
280
		largeurLogo = 70;
281
	}
281
	}
282
	
282
	
283
	$('#image-utilisateur img').width(largeurLogo);
283
	$('#image-utilisateur img').width(largeurLogo);
284
}
284
}
285
 
285
 
286
function redimensionnerControleTypeCarte(largeurViewPort) {
286
function redimensionnerControleTypeCarte(largeurViewPort) {
287
	if (largeurViewPort <= 500) {
287
	if (largeurViewPort <= 500) {
288
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DROPDOWN_MENU;
288
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DROPDOWN_MENU;
289
	} else {
289
	} else {
290
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DEFAULT;
290
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DEFAULT;
291
	}
291
	}
292
	
292
	
293
	if (map != null) {	
293
	if (map != null) {	
294
		map.setOptions(carteOptions);
294
		map.setOptions(carteOptions);
295
	}
295
	}
296
}
296
}
297
 
297
 
298
function centrerTitreEtStats() {
298
function centrerTitreEtStats() {
299
	centrerTitre();
299
	centrerTitre();
300
	centrerStats();
300
	centrerStats();
301
}
301
}
302
 
302
 
303
function centrerTitre() {
303
function centrerTitre() {
304
	var largeurViewPort = $(window).width(),
304
	var largeurViewPort = $(window).width(),
305
		largeurTitre = $('#zone-titre').width(),
305
		largeurTitre = $('#zone-titre').width(),
306
		marge = (largeurViewPort - largeurTitre)/2;
306
		marge = (largeurViewPort - largeurTitre)/2;
307
	$('#zone-titre').css("margin-left",marge);
307
	$('#zone-titre').css("margin-left",marge);
308
	
308
	
309
	var tailleRestante = largeurViewPort - (marge + largeurTitre);
309
	var tailleRestante = largeurViewPort - (marge + largeurTitre);
310
	if (tailleRestante <= 170) {
310
	if (tailleRestante <= 170) {
311
		$('#zone-titre').css("top", "25px");
311
		$('#zone-titre').css("top", "25px");
312
	} else {
312
	} else {
313
		$('#zone-titre').css("top", "5px");
313
		$('#zone-titre').css("top", "5px");
314
	}
314
	}
315
}
315
}
316
 
316
 
317
function centrerStats() {
317
function centrerStats() {
318
	var largeurViewPort = $(window).width(),
318
	var largeurViewPort = $(window).width(),
319
		largeurStats = $('#zone-stats').width(),
319
		largeurStats = $('#zone-stats').width(),
320
		marge = ((largeurViewPort - largeurStats)/2);
320
		marge = ((largeurViewPort - largeurStats)/2);
321
	$('#zone-stats').css("margin-left",marge);
321
	$('#zone-stats').css("margin-left",marge);
322
}
322
}
323
 
323
 
324
/*+--------------------------------------------------------------------------------------------------------+*/
324
/*+--------------------------------------------------------------------------------------------------------+*/
325
// CARTE
325
// CARTE
326
 
326
 
327
function dimensionnerCarte() {
327
function dimensionnerCarte() {
328
	var largeurViewPort = $(window).width();
328
	var largeurViewPort = $(window).width();
329
	var hauteurViewPort = $(window).height();
329
	var hauteurViewPort = $(window).height();
330
	$('#carte').height(hauteurViewPort);
330
	$('#carte').height(hauteurViewPort);
331
	$('#carte').width(largeurViewPort);
331
	$('#carte').width(largeurViewPort);
332
}
332
}
333
 
333
 
334
function initialiserCarte() {
334
function initialiserCarte() {
335
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
335
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
336
	// Ajout de la couche OSM à la carte
336
	// Ajout de la couche OSM à la carte
337
	map.mapTypes.set('OSM', osmMapType);
337
	map.mapTypes.set('OSM', osmMapType);
338
 
338
 
339
	// écouteur sur changement de fond
339
	// écouteur sur changement de fond
340
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
340
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
341
		// licence par défaut
341
		// licence par défaut
342
		var mention = 'Observations du réseau <a href="https://www.tela-botanica.org/site:botanique" ' +
342
		var mention = 'Observations du réseau <a href="https://www.tela-botanica.org/site:botanique" ' +
343
				'onClick="ouvrirNouvelleFenetre(this, event)">' +
343
				'onClick="ouvrirNouvelleFenetre(this, event)">' +
344
				'Tela Botanica' +
344
				'Tela Botanica' +
345
			'</a> ';
345
			'</a> ';
346
		if (map.getMapTypeId() == 'OSM') {
346
		if (map.getMapTypeId() == 'OSM') {
347
			// ajout licence OSM
347
			// ajout licence OSM
348
			mention += ' - Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© ' + msg("contributeurs-osm") + '</a>' +
348
			mention += ' - Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© ' + msg("contributeurs-osm") + '</a>' +
349
				' - Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a>';
349
				' - Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a>';
350
		}
350
		}
351
		$('#origine-donnees').html(mention);
351
		$('#origine-donnees').html(mention);
352
	});
352
	});
353
}
353
}
354
 
354
 
355
function initialiserGestionnaireMarqueurs() {
355
function initialiserGestionnaireMarqueurs() {
356
	mgr = new MarkerManager(map);
356
	mgr = new MarkerManager(map);
357
}
357
}
358
 
358
 
359
function chargerLimitesCommunales() {
359
function chargerLimitesCommunales() {
360
	if (urlsLimitesCommunales != null) {
360
	if (urlsLimitesCommunales != null) {
361
		for (urlId in urlsLimitesCommunales) { 
361
		for (urlId in urlsLimitesCommunales) { 
362
			var url = urlsLimitesCommunales[urlId];
362
			var url = urlsLimitesCommunales[urlId];
363
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
363
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
364
			ctaLayer.setMap(map);
364
			ctaLayer.setMap(map);
365
		}
365
		}
366
	}
366
	}
367
}
367
}
368
 
368
 
369
var listener = null, // pourquoi on le conserve, et on met 3 trucs différents dedans ?
369
var listener = null, // pourquoi on le conserve, et on met 3 trucs différents dedans ?
370
	timer = null;
370
	timer = null;
371
 
371
 
372
function attribuerListenerCarte() {
372
function attribuerListenerCarte() {
373
	listener = google.maps.event.addListener(map, 'bounds_changed', function() {
373
	listener = google.maps.event.addListener(map, 'bounds_changed', function() {
374
		programmerRafraichissementCarte();
374
		programmerRafraichissementCarte();
375
	});
375
	});
376
	listener = google.maps.event.addListener(map, 'zoom_changed', function() {
376
	listener = google.maps.event.addListener(map, 'zoom_changed', function() {
377
		programmerRafraichissementCarte();
377
		programmerRafraichissementCarte();
378
	});
378
	});
379
	listener = google.maps.event.addListener(map, 'click', function() {
379
	listener = google.maps.event.addListener(map, 'click', function() {
380
		if (infoBulleOuverte) {
380
		if (infoBulleOuverte) {
381
			infoBulle.close();
381
			infoBulle.close();
382
			surFermetureInfoBulle();
382
			surFermetureInfoBulle();
383
		}
383
		}
384
	});
384
	});
385
}
385
}
386
 
386
 
387
function programmerRafraichissementCarte() {
387
function programmerRafraichissementCarte() {
388
	if (timer != null) {
388
	if (timer != null) {
389
		window.clearTimeout(timer);
389
		window.clearTimeout(timer);
390
	}
390
	}
391
	if (requeteChargementPoints != null) {
391
	if (requeteChargementPoints != null) {
392
		requeteChargementPoints.abort();
392
		requeteChargementPoints.abort();
393
	}
393
	}
394
	timer = window.setTimeout(function() {
394
	timer = window.setTimeout(function() {
395
		if (map.getBounds() != undefined) {
395
		if (map.getBounds() != undefined) {
396
			var zoom = map.getZoom(),
396
			var zoom = map.getZoom(),
397
				lngNE = map.getBounds().getNorthEast().lng(),
397
				lngNE = map.getBounds().getNorthEast().lng(),
398
				lngSW = map.getBounds().getSouthWest().lng()
398
				lngSW = map.getBounds().getSouthWest().lng()
399
			if (map.getBounds().getNorthEast().lng() < map.getBounds().getSouthWest().lng()) {
399
			if (map.getBounds().getNorthEast().lng() < map.getBounds().getSouthWest().lng()) {
400
				lngNE = 176;
400
				lngNE = 176;
401
				lngSW = -156;
401
				lngSW = -156;
402
			}
402
			}
403
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
403
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
404
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
404
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
405
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
405
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
406
		} else {
406
		} else {
407
			programmerRafraichissementCarte();
407
			programmerRafraichissementCarte();
408
		}
408
		}
409
	}, 400);
409
	}, 400);
410
}
410
}
411
 
411
 
412
var marqueurs = new Array();
412
var marqueurs = new Array();
413
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
413
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
414
	cacherMessageAucuneObs();
414
	cacherMessageAucuneObs();
415
	var url = stationsUrl+
415
	var url = stationsUrl+
416
		'&zoom='+zoom+
416
		'&zoom='+zoom+
417
		'&ne='+NELatLng+
417
		'&ne='+NELatLng+
418
		'&sw='+SWLatLng;
418
		'&sw='+SWLatLng;
419
	
419
	
420
	if (infoBulleOuverte) {
420
	if (infoBulleOuverte) {
421
		return;
421
		return;
422
	}
422
	}
423
	
423
	
424
	if (requeteChargementPoints != null) {
424
	if (requeteChargementPoints != null) {
425
		requeteChargementPoints.abort();
425
		requeteChargementPoints.abort();
426
		cacherMessageChargementPoints();
426
		cacherMessageChargementPoints();
427
	}
427
	}
428
	
428
	
429
	afficherMessageChargementPoints();
429
	afficherMessageChargementPoints();
430
	requeteChargementPoints = $.getJSON(url, function(data) {
430
	requeteChargementPoints = $.getJSON(url, function(data) {
431
		rafraichirMarqueurs(data);
431
		rafraichirMarqueurs(data);
432
		cacherMessageChargementPoints();
432
		cacherMessageChargementPoints();
433
	});
433
	});
434
}
434
}
435
 
435
 
436
function centrerDansLaPage(selecteur) {
436
function centrerDansLaPage(selecteur) {
437
	var largeurViewport = $(window).width(),
437
	var largeurViewport = $(window).width(),
438
		hauteurViewport = $(window).height();
438
		hauteurViewport = $(window).height();
439
	selecteur.css('display','block');
439
	selecteur.css('display','block');
440
	var left = (largeurViewport/2) - (selecteur.width())/2,
440
	var left = (largeurViewport/2) - (selecteur.width())/2,
441
		top = (hauteurViewport/2) - (selecteur.height())/2
441
		top = (hauteurViewport/2) - (selecteur.height())/2
442
	selecteur.css('left',left);
442
	selecteur.css('left',left);
443
	selecteur.css('top',top);
443
	selecteur.css('top',top);
444
}
444
}
445
 
445
 
446
function afficherMessageChargementPoints() {
446
function afficherMessageChargementPoints() {
447
	//centrerDansLaPage($('#zone-chargement-point'));
447
	//centrerDansLaPage($('#zone-chargement-point'));
448
	$('#zone-chargement-point').css('display','block');
448
	$('#zone-chargement-point').css('display','block');
449
}
449
}
450
 
450
 
451
function cacherMessageChargementPoints() {
451
function cacherMessageChargementPoints() {
452
	$('#zone-chargement-point').css('display','none');
452
	$('#zone-chargement-point').css('display','none');
453
}
453
}
454
 
454
 
455
function afficherMessageAucuneObs() {
455
function afficherMessageAucuneObs() {
456
	centrerDansLaPage($('#message-aucune-obs'));
456
	centrerDansLaPage($('#message-aucune-obs'));
457
	$('#message-aucune-obs').show();
457
	$('#message-aucune-obs').show();
458
}
458
}
459
 
459
 
460
function cacherMessageAucuneObs() {
460
function cacherMessageAucuneObs() {
461
	centrerDansLaPage($('#message-aucune-obs'));
461
	centrerDansLaPage($('#message-aucune-obs'));
462
	$('#message-aucune-obs').hide();
462
	$('#message-aucune-obs').hide();
463
}
463
}
464
 
464
 
465
premierChargement = true;
465
premierChargement = true;
466
function doitCentrerCarte() {
466
function doitCentrerCarte() {
467
	return premierChargement && urlVars != null && urlVars.length > 0;
467
	return premierChargement && urlVars != null && urlVars.length > 0;
468
}
468
}
469
 
469
 
470
function rafraichirMarqueurs(data) {
470
function rafraichirMarqueurs(data) {
471
	$.each(marqueurs, function(index, marqueur) {
471
	$.each(marqueurs, function(index, marqueur) {
472
		marqueur.setMap(null);
472
		marqueur.setMap(null);
473
	});
473
	});
474
 
474
 
475
	marqueurs = new Array();
475
	marqueurs = new Array();
476
	stations = null;
476
	stations = null;
477
	
477
	
478
	if (data.points.length > 0) {
478
	if (data.points.length > 0) {
479
		marqueurs = new Array();
479
		marqueurs = new Array();
480
		stations = data;
480
		stations = data;
481
		
481
		
482
		$.each(stations.points, function (index, station) {		
482
		$.each(stations.points, function (index, station) {		
483
			if(station != null) {
483
			if(station != null) {
484
				var nouveauMarqueur = creerMarqueur(station);
484
				var nouveauMarqueur = creerMarqueur(station);
485
				marqueurs.push(nouveauMarqueur);
485
				marqueurs.push(nouveauMarqueur);
486
			}
486
			}
487
		});
487
		});
488
		
488
		
489
		if (doitCentrerCarte()) {
489
		if (doitCentrerCarte()) {
490
			premierChargement = false;
490
			premierChargement = false;
491
			var bounds = new google.maps.LatLngBounds(),
491
			var bounds = new google.maps.LatLngBounds(),
492
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
492
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
493
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
493
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
494
			bounds.extend(latMax);
494
			bounds.extend(latMax);
495
			bounds.extend(latMin);
495
			bounds.extend(latMin);
496
			rendrePointsVisibles(bounds);	
496
			rendrePointsVisibles(bounds);	
497
		}
497
		}
498
	}
498
	}
499
	
499
	
500
	afficherTitreCarteEtStats();
500
	afficherTitreCarteEtStats();
501
}
501
}
502
 
502
 
503
function creerMarqueur(station) {
503
function creerMarqueur(station) {
504
	var titre = '';
504
	var titre = '';
505
	if (station.nbreMarqueur) {
505
	if (station.nbreMarqueur) {
506
		titre = station.nbreMarqueur+' ' + ('points-renseignes');
506
		titre = station.nbreMarqueur+' ' + ('points-renseignes');
507
	} else {
507
	} else {
508
		if(station.nom) {
508
		if(station.nom) {
509
			titre = station.nom;
509
			titre = station.nom;
510
		}
510
		}
511
	}
511
	}
512
	
512
	
513
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']),
513
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']),
514
		latLng = new google.maps.LatLng(station['lat'], station['lng']),
514
		latLng = new google.maps.LatLng(station['lat'], station['lng']),
515
			marqueur = new google.maps.Marker({
515
			marqueur = new google.maps.Marker({
516
				position: latLng,
516
				position: latLng,
517
				icon: icone,
517
				icon: icone,
518
				title: ''+titre,
518
				title: ''+titre,
519
				map: map,
519
				map: map,
520
				stationInfos: station
520
				stationInfos: station
521
			});
521
			});
522
	attribuerListenerClick(marqueur, station['id']);
522
	attribuerListenerClick(marqueur, station['id']);
523
	marqueur.setMap(map);
523
	marqueur.setMap(map);
524
	return marqueur;
524
	return marqueur;
525
}
525
}
526
 
526
 
527
function rendrePointsVisibles(bounds) {
527
function rendrePointsVisibles(bounds) {
528
	map.setCenter(bounds.getCenter());
528
	map.setCenter(bounds.getCenter());
529
	map.fitBounds(bounds);
529
	map.fitBounds(bounds);
530
}
530
}
531
 
531
 
532
function attribuerImageMarqueur(id, nbreMarqueur) {
532
function attribuerImageMarqueur(id, nbreMarqueur) {
533
	var marqueurImage = null;
533
	var marqueurImage = null;
534
	if (etreMarqueurCommune(id)) {
534
	if (etreMarqueurCommune(id)) {
535
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
535
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
536
	} else if (etreMarqueurStation(id)) {
536
	} else if (etreMarqueurStation(id)) {
537
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
537
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
538
	} else if (etreMarqueurGroupe(id)) {
538
	} else if (etreMarqueurGroupe(id)) {
539
		var type = 0,
539
		var type = 0,
540
			largeur = 0,
540
			largeur = 0,
541
			hauteur = 0;
541
			hauteur = 0;
542
		if (nbreMarqueur != null) {
542
		if (nbreMarqueur != null) {
543
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
543
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
544
				type = '1';
544
				type = '1';
545
				largeur = 53;
545
				largeur = 53;
546
				hauteur = 52;
546
				hauteur = 52;
547
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
547
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
548
				type = '2';
548
				type = '2';
549
				largeur = 56;
549
				largeur = 56;
550
				hauteur = 55;
550
				hauteur = 55;
551
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
551
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
552
				type = '3';
552
				type = '3';
553
				largeur = 66;
553
				largeur = 66;
554
				hauteur = 65;
554
				hauteur = 65;
555
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
555
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
556
				type = '4';
556
				type = '4';
557
				largeur = 78;
557
				largeur = 78;
558
				hauteur = 77;
558
				hauteur = 77;
559
			} else if (nbreMarqueur >= 20000) {
559
			} else if (nbreMarqueur >= 20000) {
560
				type = '5';
560
				type = '5';
561
				largeur = 66;
561
				largeur = 66;
562
				hauteur = 65;
562
				hauteur = 65;
563
			}
563
			}
564
		}
564
		}
565
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
565
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
566
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
566
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
567
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
567
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
568
	}
568
	}
569
	return marqueurImage
569
	return marqueurImage
570
}
570
}
571
 
571
 
572
function attribuerListenerClick(marqueur, id) {
572
function attribuerListenerClick(marqueur, id) {
573
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
573
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
574
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
574
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
575
	} else if (etreMarqueurGroupe(id)) {
575
	} else if (etreMarqueurGroupe(id)) {
576
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
576
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
577
	}
577
	}
578
}
578
}
579
 
579
 
580
var pointCentreAvantAffichageInfoBulle = null;
580
var pointCentreAvantAffichageInfoBulle = null;
581
function surClickMarqueur(event) {
581
function surClickMarqueur(event) {
582
	pointCentreAvantAffichageInfoBulle = map.getCenter();
582
	pointCentreAvantAffichageInfoBulle = map.getCenter();
583
 
583
 
584
	if(infoBulleOuverte) {
584
	if(infoBulleOuverte) {
585
		infoBulle.close();
585
		infoBulle.close();
586
	}
586
	}
587
 
587
 
588
	pointClique = this;
588
	pointClique = this;
589
	infoBulle.open(map, this);
589
	infoBulle.open(map, this);
590
	actualiserPagineur();
590
	actualiserPagineur();
591
 
591
 
592
	var limites = map.getBounds(),
592
	var limites = map.getBounds(),
593
		centre = limites.getCenter(),
593
		centre = limites.getCenter(),
594
		nordEst = limites.getNorthEast(),
594
		nordEst = limites.getNorthEast(),
595
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
595
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
596
	map.panTo(centreSudLatLng);
596
	map.panTo(centreSudLatLng);
597
	
597
	
598
	afficherInfoBulle();
598
	afficherInfoBulle();
599
}
599
}
600
 
600
 
601
function surClickGroupe() {
601
function surClickGroupe() {
602
	map.setCenter(this.getPosition());
602
	map.setCenter(this.getPosition());
603
	var nouveauZoom = map.getZoom() + 2;
603
	var nouveauZoom = map.getZoom() + 2;
604
	map.setZoom(nouveauZoom);
604
	map.setZoom(nouveauZoom);
605
	mgr.clearMarkers();
605
	mgr.clearMarkers();
606
}
606
}
607
 
607
 
608
function etreMarqueurGroupe(id) {
608
function etreMarqueurGroupe(id) {
609
	var groupe = false,
609
	var groupe = false,
610
		motif = /^GROUPE/;
610
		motif = /^GROUPE/;
611
	if (motif.test(id)) {
611
	if (motif.test(id)) {
612
		groupe = true;
612
		groupe = true;
613
	}
613
	}
614
	return groupe;
614
	return groupe;
615
}
615
}
616
 
616
 
617
function etreMarqueurCommune(id) {
617
function etreMarqueurCommune(id) {
618
	var commune = false,
618
	var commune = false,
619
		motif = /^COMMUNE:/;
619
		motif = /^COMMUNE:/;
620
	if (motif.test(id)) {
620
	if (motif.test(id)) {
621
		commune = true;
621
		commune = true;
622
	}
622
	}
623
	return commune;
623
	return commune;
624
}
624
}
625
 
625
 
626
function etreMarqueurStation(id) {
626
function etreMarqueurStation(id) {
627
	var station = false,
627
	var station = false,
628
		motif = /^STATION:/;
628
		motif = /^STATION:/;
629
	if (motif.test(id)) {
629
	if (motif.test(id)) {
630
		station = true;
630
		station = true;
631
	}
631
	}
632
	return station;
632
	return station;
633
}
633
}
634
 
634
 
635
function deplacerCarteSurPointClique() {
635
function deplacerCarteSurPointClique() {
636
	map.panTo(pointClique.position);
636
	map.panTo(pointClique.position);
637
}
637
}
638
 
638
 
639
/*+--------------------------------------------------------------------------------------------------------+*/
639
/*+--------------------------------------------------------------------------------------------------------+*/
640
// INFO BULLE
640
// INFO BULLE
641
var infoBulleOuverte = false;
641
var infoBulleOuverte = false;
642
function initialiserInfoBulle() {
642
function initialiserInfoBulle() {
643
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
643
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
644
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
644
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
645
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
645
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
646
	attribuerListenerLienSaisie();
646
	attribuerListenerLienSaisie();
647
}
647
}
648
 
648
 
649
function attribuerListenerLienSaisie() {
649
function attribuerListenerLienSaisie() {
650
	$('.lien-widget-saisie').live('click', function(event) {
650
	$('.lien-widget-saisie').live('click', function(event) {
651
		event.preventDefault();
651
		event.preventDefault();
652
		window.open($(this).attr('href'), '_blank');
652
		window.open($(this).attr('href'), '_blank');
653
		return false;
653
		return false;
654
	});
654
	});
655
}
655
}
656
 
656
 
657
function surFermetureInfoBulle() {
657
function surFermetureInfoBulle() {
658
	infoBulleOuverte = false;
658
	infoBulleOuverte = false;
659
	map.panTo(pointCentreAvantAffichageInfoBulle);
659
	map.panTo(pointCentreAvantAffichageInfoBulle);
660
	programmerRafraichissementCarte();
660
	programmerRafraichissementCarte();
661
}
661
}
662
 
662
 
663
function centrerInfoBulle() {
663
function centrerInfoBulle() {
664
	var limites = map.getBounds(),
664
	var limites = map.getBounds(),
665
		centre = limites.getCenter(),
665
		centre = limites.getCenter(),
666
		nordEst = limites.getNorthEast(),
666
		nordEst = limites.getNorthEast(),
667
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
667
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
668
	map.panTo(centreSudLatLng);
668
	map.panTo(centreSudLatLng);
669
}
669
}
670
 
670
 
671
function afficherInfoBulle() {
671
function afficherInfoBulle() {
672
	var obsHtml = $('#tpl-obs').html(),
672
	var obsHtml = $('#tpl-obs').html(),
673
		largeur = definirLargeurInfoBulle(),
673
		largeur = definirLargeurInfoBulle(),
674
		taillePolice = definirTaillePoliceInfoBulle();
674
		taillePolice = definirTaillePoliceInfoBulle();
675
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
675
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
676
	infoBulle.setContent(obsHtml);
676
	infoBulle.setContent(obsHtml);
677
	$('#observations').css('font-size', taillePolice + 'em');
677
	$('#observations').css('font-size', taillePolice + 'em');
678
	chargerObs(0, 0);
678
	chargerObs(0, 0);
679
	infoBulleOuverte = true;
679
	infoBulleOuverte = true;
680
}
680
}
681
 
681
 
682
//TODO utiliser cette fonction lors des remplacements de 
682
//TODO utiliser cette fonction lors des remplacements de 
683
//paramètres url sur changement de filtre
683
//paramètres url sur changement de filtre
684
function parserFiltre(filtre) {
684
function parserFiltre(filtre) {
685
	var nvpair = {},
685
	var nvpair = {},
686
		qs = filtre.replace('?', ''),
686
		qs = filtre.replace('?', ''),
687
		pairs = qs.split('&');
687
		pairs = qs.split('&');
688
	$.each(pairs, function(i, v){
688
	$.each(pairs, function(i, v){
689
		var pair = v.split('=');
689
		var pair = v.split('=');
690
		nvpair[pair[0]] = pair[1];
690
		nvpair[pair[0]] = pair[1];
691
	});
691
	});
692
	return nvpair;
692
	return nvpair;
693
}
693
}
694
 
694
 
695
function mettreAJourUrlSaisie(obs) {
695
function mettreAJourUrlSaisie(obs) {
696
	if (obs.observations.length > 0) {
696
	if (obs.observations.length > 0) {
697
		var filtreTableau = parserFiltre(filtreCommun),
697
		var filtreTableau = parserFiltre(filtreCommun),
698
			filtresGardes = new Array()
698
			filtresGardes = new Array()
699
			idObs = obs.observations[0].idObs;
699
			idObs = obs.observations[0].idObs;
700
		filtre = '';
700
		filtre = '';
701
		for (i in filtreTableau) {
701
		for (i in filtreTableau) {
702
			if (filtreTableau[i] != undefined && filtreTableau[i] != '' && decodeURIComponent(filtreTableau[i]) != '*') {
702
			if (filtreTableau[i] != undefined && filtreTableau[i] != '' && decodeURIComponent(filtreTableau[i]) != '*') {
703
				filtresGardes.push(i + '=' + filtreTableau[i]);
703
				filtresGardes.push(i + '=' + filtreTableau[i]);
704
			}
704
			}
705
		}
705
		}
706
		filtresGardes.push('id-obs=' + idObs);
706
		filtresGardes.push('id-obs=' + idObs);
707
		if (filtresGardes.length > 0) {
707
		if (filtresGardes.length > 0) {
708
			filtre = '?' + filtresGardes.join('&');
708
			filtre = '?' + filtresGardes.join('&');
709
		}
709
		}
710
		var urlAvecFiltre = urlWidgetSaisie + filtre;
710
		var urlAvecFiltre = urlWidgetSaisie + filtre;
711
		$('.lien-widget-saisie').attr('href', urlAvecFiltre).parents('.conteneur-lien-saisie').show();
711
		$('.lien-widget-saisie').attr('href', urlAvecFiltre).parents('.conteneur-lien-saisie').show();
712
	}
712
	}
713
}
713
}
714
 
714
 
715
function definirLargeurInfoBulle() {
715
function definirLargeurInfoBulle() {
716
	var largeurViewPort = $(window).width(),
716
	var largeurViewPort = $(window).width(),
717
		largeurInfoBulle = null;
717
		largeurInfoBulle = null;
718
	if (largeurViewPort < 400) {
718
	if (largeurViewPort < 400) {
719
		largeurInfoBulle = 300;
719
		largeurInfoBulle = 300;
720
	} else if (largeurViewPort < 800) {
720
	} else if (largeurViewPort < 800) {
721
		largeurInfoBulle = 400;
721
		largeurInfoBulle = 400;
722
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
722
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
723
		largeurInfoBulle = 500;
723
		largeurInfoBulle = 500;
724
	} else if (largeurViewPort >= 1200) {
724
	} else if (largeurViewPort >= 1200) {
725
		largeurInfoBulle = 600;
725
		largeurInfoBulle = 600;
726
	}
726
	}
727
	return largeurInfoBulle;
727
	return largeurInfoBulle;
728
}
728
}
729
 
729
 
730
function definirTaillePoliceInfoBulle() {
730
function definirTaillePoliceInfoBulle() {
731
	var largeurViewPort = $(window).width(),
731
	var largeurViewPort = $(window).width(),
732
		taillePolice = null;
732
		taillePolice = null;
733
	if (largeurViewPort < 400) {
733
	if (largeurViewPort < 400) {
734
		taillePolice = 0.8;
734
		taillePolice = 0.8;
735
	} else if (largeurViewPort < 800) {
735
	} else if (largeurViewPort < 800) {
736
		taillePolice = 1;
736
		taillePolice = 1;
737
	}
737
	}
738
	return taillePolice;
738
	return taillePolice;
739
}
739
}
740
 
740
 
741
function afficherMessageChargement(element) {
741
function afficherMessageChargement(element) {
742
	if ($('#chargement').get() == '') {
742
	if ($('#chargement').get() == '') {
743
		$('#tpl-chargement').tmpl().appendTo(element);
743
		$('#tpl-chargement').tmpl().appendTo(element);
744
	}
744
	}
745
}
745
}
746
 
746
 
747
function afficherMessageChargementTitreInfoBulle() {
747
function afficherMessageChargementTitreInfoBulle() {
748
	$("#obs-station-titre").text(msg("chargement-observations"));	
748
	$("#obs-station-titre").text(msg("chargement-observations"));	
749
}
749
}
750
 
750
 
751
function supprimerMessageChargement() {
751
function supprimerMessageChargement() {
752
	$('#chargement').remove();
752
	$('#chargement').remove();
753
}
753
}
754
 
754
 
755
function chargerObs(depart, total) {
755
function chargerObs(depart, total) {
756
	if (depart == 0 || depart < total) {
756
	if (depart == 0 || depart < total) {
757
		var limite = 300;
757
		var limite = 300;
758
		if (depart == 0) {
758
		if (depart == 0) {
759
			viderTableauObs();
759
			viderTableauObs();
760
		}
760
		}
761
		
761
		
762
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
762
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
763
		urlObs = urlObs.replace(/\{stationId\}/g, encodeURIComponent(pointClique.stationInfos.id));
763
		urlObs = urlObs.replace(/\{stationId\}/g, encodeURIComponent(pointClique.stationInfos.id));
764
		if (pointClique.stationInfos.type_emplacement == 'communes') {
764
		if (pointClique.stationInfos.type_emplacement == 'communes') {
765
			urlObs = urlObs.replace(/commune=%2A/g, formaterParametreCommunePourRequete(pointClique.stationInfos.nom));
765
			urlObs = urlObs.replace(/commune=%2A/g, formaterParametreCommunePourRequete(pointClique.stationInfos.nom));
766
		}
766
		}
767
		// Ajout de la zone geo
767
		// Ajout de la zone geo
768
		if (pointClique.stationInfos.zonegeo) {
768
		if (pointClique.stationInfos.zonegeo) {
769
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
769
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
770
		}
770
		}
771
 
771
 
772
		urlObs = urlObs.replace(/\{nt\}/g, nt);
772
		urlObs = urlObs.replace(/\{nt\}/g, nt);
773
		urlObs = urlObs.replace(/\{start\}/g, depart);
773
		urlObs = urlObs.replace(/\{start\}/g, depart);
774
		
774
		
775
		$.getJSON(urlObs, function(observations){
775
		$.getJSON(urlObs, function(observations){
776
			surRetourChargementObs(observations, depart, total);
776
			surRetourChargementObs(observations, depart, total);
777
			chargerObs(depart+limite, observations.total);
777
			chargerObs(depart+limite, observations.total);
778
		});
778
		});
779
	}
779
	}
780
}
780
}
781
 
781
 
782
function formaterParametreCommunePourRequete(nomCommune) {
782
function formaterParametreCommunePourRequete(nomCommune) {
783
	var chaineRequete = "";
783
	var chaineRequete = "";
784
	if(nomCommune.indexOf("(", 0) !== false) {
784
	if(nomCommune.indexOf("(", 0) !== false) {
785
		var infosCommune = nomCommune.split("(");
785
		var infosCommune = nomCommune.split("(");
786
		var commune = infosCommune[0];
786
		var commune = infosCommune[0];
787
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
787
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
788
	} else {
788
	} else {
789
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
789
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
790
	}
790
	}
791
	return chaineRequete;
791
	return chaineRequete;
792
}
792
}
793
 
793
 
794
function viderTableauObs() {
794
function viderTableauObs() {
795
	obsStation = new Array();	
795
	obsStation = new Array();	
796
	surClicPagePagination(0, null);
796
	surClicPagePagination(0, null);
797
}
797
}
798
 
798
 
799
function surRetourChargementObs(observations, depart, total) {
799
function surRetourChargementObs(observations, depart, total) {
800
	obsStation = obsStation.concat(observations.observations);
800
	obsStation = obsStation.concat(observations.observations);
801
	if (depart == 0) {
801
	if (depart == 0) {
802
		actualiserInfosStation(observations);
802
		actualiserInfosStation(observations);
803
		creerTitreInfoBulle();
803
		creerTitreInfoBulle();
804
		surClicPagePagination(0, null);
804
		surClicPagePagination(0, null);
805
		mettreAJourUrlSaisie(observations);
805
		mettreAJourUrlSaisie(observations);
806
	}
806
	}
807
	
807
	
808
	afficherPagination();
808
	afficherPagination();
809
	actualiserPagineur();
809
	actualiserPagineur();
810
	selectionnerOnglet("#obs-vue-"+pagineur.format);
810
	selectionnerOnglet("#obs-vue-"+pagineur.format);
811
}
811
}
812
 
812
 
813
function actualiserInfosStation(infos) {
813
function actualiserInfosStation(infos) {
814
	pointClique.stationInfos.commune = infos.commune;
814
	pointClique.stationInfos.commune = infos.commune;
815
	pointClique.stationInfos.obsNbre = infos.total;
815
	pointClique.stationInfos.obsNbre = infos.total;
816
}
816
}
817
 
817
 
818
function creerTitreInfoBulle() {
818
function creerTitreInfoBulle() {
819
	$('#obs-total').text(station.obsNbre);
819
	$('#obs-total').text(station.obsNbre);
820
	$('#obs-commune').text(station.commune);
820
	$('#obs-commune').text(station.commune);
821
	var titre = '';
821
	var titre = '';
822
	titre += pointClique.stationInfos.obsNbre+' ' + msg('observation');
822
	titre += pointClique.stationInfos.obsNbre+' ' + msg('observation');
823
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
823
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
824
	titre += ' ' + msg('pour') + ' ';
824
	titre += ' ' + msg('pour') + ' ';
825
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
825
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
826
		nomStation = msg('la-commune') + ' : ';
826
		nomStation = msg('la-commune') + ' : ';
827
	} else {
827
	} else {
828
		nomStation = msg('la-station') + ' : ';
828
		nomStation = msg('la-station') + ' : ';
829
	}
829
	}
830
	titre += pointClique.stationInfos.nom;
830
	titre += pointClique.stationInfos.nom;
831
	$('#obs-station-titre').text(titre);
831
	$('#obs-station-titre').text(titre);
832
}
832
}
833
 
833
 
834
function actualiserPagineur() {
834
function actualiserPagineur() {
835
	pagineur.stationId = pointClique.stationInfos.id;
835
	pagineur.stationId = pointClique.stationInfos.id;
836
	pagineur.total = pointClique.stationInfos.obsNbre;
836
	pagineur.total = pointClique.stationInfos.obsNbre;
837
	// Si on est en mode photo on reste en mode liste quelque soit le 
837
	// Si on est en mode photo on reste en mode liste quelque soit le 
838
	// nombre de résultats
838
	// nombre de résultats
839
	if (pagineur.total > 4 && photos != 1) {
839
	if (pagineur.total > 4 && photos != 1) {
840
		pagineur.format = 'tableau';
840
		pagineur.format = 'tableau';
841
	} else {
841
	} else {
842
		pagineur.format = 'liste';
842
		pagineur.format = 'liste';
843
	}
843
	}
844
}
844
}
845
 
845
 
846
function afficherPagination(observations) {
846
function afficherPagination(observations) {
847
	$('.navigation').pagination(pagineur.total, {
847
	$('.navigation').pagination(pagineur.total, {
848
		items_per_page:pagineur.limite,
848
		items_per_page:pagineur.limite,
849
		callback:surClicPagePagination,
849
		callback:surClicPagePagination,
850
		next_text: msg('Suivant'),
850
		next_text: msg('Suivant'),
851
		prev_text: msg('Precedent'),
851
		prev_text: msg('Precedent'),
852
		prev_show_always:false,
852
		prev_show_always:false,
853
		num_edge_entries:1,
853
		num_edge_entries:1,
854
		num_display_entries:4,
854
		num_display_entries:4,
855
		load_first_page:true
855
		load_first_page:true
856
	});
856
	});
857
}
857
}
858
 
858
 
859
function surClicPagePagination(pageIndex, paginationConteneur) {
859
function surClicPagePagination(pageIndex, paginationConteneur) {
860
	var index = pageIndex * pagineur.limite,
860
	var index = pageIndex * pagineur.limite,
861
		indexMax = index + pagineur.limite;
861
		indexMax = index + pagineur.limite;
862
	pagineur.depart = index;
862
	pagineur.depart = index;
863
	obsPage = new Array();
863
	obsPage = new Array();
864
	for (index; index < indexMax; index++) {
864
	for (index; index < indexMax; index++) {
865
		obsPage.push(obsStation[index]);
865
		obsPage.push(obsStation[index]);
866
	}
866
	}
867
 
867
 
868
	supprimerMessageChargement();
868
	supprimerMessageChargement();
869
	mettreAJourObservations();
869
	mettreAJourObservations();
870
	return false;
870
	return false;
871
}
871
}
872
 
872
 
873
function mettreAJourObservations() {
873
function mettreAJourObservations() {
874
	$('#obs-'+pagineur.format+'-lignes').empty();
874
	$('#obs-'+pagineur.format+'-lignes').empty();
875
	$('#obs-vue-'+pagineur.format).css('display', 'block');
875
	$('#obs-vue-'+pagineur.format).css('display', 'block');
876
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
876
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
877
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
877
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
878
	
878
	
879
	// Actualisation de Fancybox
879
	// Actualisation de Fancybox
880
	ajouterFormulaireContact('a.contact');
880
	ajouterFormulaireContact('a.contact');
881
	if (pagineur.format == 'liste') {
881
	if (pagineur.format == 'liste') {
882
		ajouterGaleriePhoto('a.cel-img');
882
		ajouterGaleriePhoto('a.cel-img');
883
	}
883
	}
884
}
884
}
885
 
885
 
886
function initialiserContenuInfoBulle() {
886
function initialiserContenuInfoBulle() {
887
	afficherMessageChargement('#observations');
887
	afficherMessageChargement('#observations');
888
	cacherContenuOnglets();
888
	cacherContenuOnglets();
889
	afficherOnglets();
889
	afficherOnglets();
890
	ajouterTableauTriable('#obs-tableau');
890
	ajouterTableauTriable('#obs-tableau');
891
	afficherTextStationId();
891
	afficherTextStationId();
892
	corrigerLargeurInfoWindow();
892
	corrigerLargeurInfoWindow();
893
}
893
}
894
 
894
 
895
function cacherContenuOnglets() {
895
function cacherContenuOnglets() {
896
	$('#obs-vue-tableau').css('display', 'none');
896
	$('#obs-vue-tableau').css('display', 'none');
897
	$('#obs-vue-liste').css('display', 'none');
897
	$('#obs-vue-liste').css('display', 'none');
898
}
898
}
899
 
899
 
900
function afficherOnglets() {
900
function afficherOnglets() {
901
	var $tabs = $('#obs').tabs();
901
	var $tabs = $('#obs').tabs();
902
	$('#obs').bind('tabsselect', function(event, ui) {
902
	$('#obs').bind('tabsselect', function(event, ui) {
903
		if (ui.panel.id == 'obs-vue-tableau') {
903
		if (ui.panel.id == 'obs-vue-tableau') {
904
			surClicAffichageTableau();
904
			surClicAffichageTableau();
905
		} else if (ui.panel.id == 'obs-vue-liste') {
905
		} else if (ui.panel.id == 'obs-vue-liste') {
906
			surClicAffichageListe();
906
			surClicAffichageListe();
907
		}
907
		}
908
	});
908
	});
909
	if (pointClique.stationInfos.nbre > 4) {
909
	if (pointClique.stationInfos.nbre > 4) {
910
		$tabs.tabs('select', "#obs-vue-tableau");
910
		$tabs.tabs('select', "#obs-vue-tableau");
911
	} else {
911
	} else {
912
		$tabs.tabs('select', "#obs-vue-liste");
912
		$tabs.tabs('select', "#obs-vue-liste");
913
	}
913
	}
914
	
914
	
915
}
915
}
916
 
916
 
917
function selectionnerOnglet(onglet) {
917
function selectionnerOnglet(onglet) {
918
	$(onglet).css('display', 'block');
918
	$(onglet).css('display', 'block');
919
	$('#obs').tabs('select', onglet);
919
	$('#obs').tabs('select', onglet);
920
}
920
}
921
 
921
 
922
function afficherTextStationId() {
922
function afficherTextStationId() {
923
	$('#obs-station-id').text(pointClique.stationInfos.id);
923
	$('#obs-station-id').text(pointClique.stationInfos.id);
924
}
924
}
925
 
925
 
926
function corrigerLargeurInfoWindow() {
926
function corrigerLargeurInfoWindow() {
927
	$("#info-bulle").width($("#info-bulle").width() - 17);
927
	$("#info-bulle").width($("#info-bulle").width() - 17);
928
}
928
}
929
 
929
 
930
function surClicAffichageTableau(event) {
930
function surClicAffichageTableau(event) {
931
	pagineur.format = 'tableau';
931
	pagineur.format = 'tableau';
932
	mettreAJourObservations();
932
	mettreAJourObservations();
933
	mettreAJourTableauTriable("#obs-tableau");
933
	mettreAJourTableauTriable("#obs-tableau");
934
}
934
}
935
 
935
 
936
function surClicAffichageListe(event) {
936
function surClicAffichageListe(event) {
937
	pagineur.format = 'liste';
937
	pagineur.format = 'liste';
938
	mettreAJourObservations();
938
	mettreAJourObservations();
939
	ajouterGaleriePhoto("a.cel-img");
939
	ajouterGaleriePhoto("a.cel-img");
940
}
940
}
941
 
941
 
942
function ajouterTableauTriable(element) {
942
function ajouterTableauTriable(element) {
943
	// add parser through the tablesorter addParser method 
943
	// add parser through the tablesorter addParser method 
944
	$.tablesorter.addParser({ 
944
	$.tablesorter.addParser({ 
945
		// Définition d'un id unique pour ce parsseur 
945
		// Définition d'un id unique pour ce parsseur 
946
		id: 'date_cel', 
946
		id: 'date_cel', 
947
		is: function(s) { 
947
		is: function(s) { 
948
			// doit retourner false si le parsseur n'est pas autodétecté
948
			// doit retourner false si le parsseur n'est pas autodétecté
949
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
949
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
950
		}, 
950
		}, 
951
		format: function(date) { 
951
		format: function(date) { 
952
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
952
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
953
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
953
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
954
			// Remplace la date par un nombre de millisecondes pour trier numériquement
954
			// Remplace la date par un nombre de millisecondes pour trier numériquement
955
			return $.tablesorter.formatFloat(new Date(date).getTime());
955
			return $.tablesorter.formatFloat(new Date(date).getTime());
956
		}, 
956
		}, 
957
		// set type, either numeric or text 
957
		// set type, either numeric or text 
958
		type: 'numeric' 
958
		type: 'numeric' 
959
	});
959
	});
960
	$(element).tablesorter({ 
960
	$(element).tablesorter({ 
961
		headers: { 
961
		headers: { 
962
			1: { 
962
			1: { 
963
				sorter: 'date_cel' 
963
				sorter: 'date_cel' 
964
			} 
964
			} 
965
		}
965
		}
966
	});
966
	});
967
}
967
}
968
 
968
 
969
function mettreAJourTableauTriable(element) {
969
function mettreAJourTableauTriable(element) {
970
	$(element).trigger('update');
970
	$(element).trigger('update');
971
}
971
}
972
 
972
 
973
function ajouterGaleriePhoto(element) {
973
function ajouterGaleriePhoto(element) {
974
	$(element).fancybox({
974
	$(element).fancybox({
975
		transitionIn: 'elastic',
975
		transitionIn: 'elastic',
976
		transitionOut: 'elastic',
976
		transitionOut: 'elastic',
977
		speedIn: 600, 
977
		speedIn: 600, 
978
		speedOut: 200,
978
		speedOut: 200,
979
		overlayShow: true,
979
		overlayShow: true,
980
		titleShow: true,
980
		titleShow: true,
981
		titlePosition: 'inside',
981
		titlePosition: 'inside',
982
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
982
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
983
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
983
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
984
			motif.exec(titre);
984
			motif.exec(titre);
985
			var id = RegExp.$1,
985
			var id = RegExp.$1,
986
				info = $('#cel-info-'+id).clone().html(),
986
				info = $('#cel-info-'+id).clone().html(),
987
				tpl = 
987
				tpl = 
988
					'<div class="cel-legende">'+
988
					'<div class="cel-legende">'+
989
					'<p class="cel-legende-vei">'+ msg('Image-n') + ' ' + (currentIndex + 1) + ' ' + msg('sur') + ' ' + currentArray.length +'<\/p>'+	
989
					'<p class="cel-legende-vei">'+ msg('Image-n') + ' ' + (currentIndex + 1) + ' ' + msg('sur') + ' ' + currentArray.length +'<\/p>'+	
990
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
990
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
991
					'<\/div>';
991
					'<\/div>';
992
			return tpl;
992
			return tpl;
993
		}
993
		}
994
	}).live('click', function(e) {
994
	}).live('click', function(e) {
995
		if (e.stopPropagation) {
995
		if (e.stopPropagation) {
996
			e.stopPropagation();
996
			e.stopPropagation();
997
		}
997
		}
998
		return false;
998
		return false;
999
	});
999
	});
1000
}
1000
}
1001
 
1001
 
1002
function ajouterFormulaireContact(element) {
1002
function ajouterFormulaireContact(element) {
1003
	$(element).fancybox({
1003
	$(element).fancybox({
1004
		transitionIn:'elastic',
1004
		transitionIn:'elastic',
1005
		transitionOut:'elastic',
1005
		transitionOut:'elastic',
1006
		speedIn	:600, 
1006
		speedIn	:600, 
1007
		speedOut:200,
1007
		speedOut:200,
1008
		scrolling: 'no',
1008
		scrolling: 'no',
1009
		titleShow: false,
1009
		titleShow: false,
1010
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
1010
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
1011
			var element = selectedArray[selectedIndex];
1011
			var element = selectedArray[selectedIndex];
1012
			var motif = / contributeur-([0-9]+)$/;
1012
			var motif = / contributeur-([0-9]+)$/;
1013
			motif.exec($(element).attr('class'));
1013
			motif.exec($(element).attr('class'));
1014
			// si la classe ne contient pas d'id contributeur
1014
			// si la classe ne contient pas d'id contributeur
1015
			// alors il faut stocker le numéro d'observation
1015
			// alors il faut stocker le numéro d'observation
1016
			var id = RegExp.$1;
1016
			var id = RegExp.$1;
1017
			if(id == "") {
1017
			if(id == "") {
1018
				$("#fc_type_envoi").attr('value', 'non-inscrit');
1018
				$("#fc_type_envoi").attr('value', 'non-inscrit');
1019
				var motif = / obs-([0-9]+)$/;
1019
				var motif = / obs-([0-9]+)$/;
1020
				motif.exec($(element).attr('class'));
1020
				motif.exec($(element).attr('class'));
1021
				var id = RegExp.$1;
1021
				var id = RegExp.$1;
1022
			} else {
1022
			} else {
1023
				$("#fc_type_envoi").attr('value', 'inscrit');
1023
				$("#fc_type_envoi").attr('value', 'inscrit');
1024
			}
1024
			}
1025
 
1025
 
1026
			$("#fc_destinataire_id").attr('value', id);
1026
			$("#fc_destinataire_id").attr('value', id);
1027
		
1027
		
1028
			var motif = / obs-([0-9]+)/;
1028
			var motif = / obs-([0-9]+)/;
1029
			motif.exec($(element).attr('class'));
1029
			motif.exec($(element).attr('class'));
1030
			var id = RegExp.$1;
1030
			var id = RegExp.$1;
1031
			//console.log('Obs id : '+id);
1031
			//console.log('Obs id : '+id);
1032
			chargerInfoObsPourMessage(id);
1032
			chargerInfoObsPourMessage(id);
1033
		},
1033
		},
1034
		onCleanup: function() {
1034
		onCleanup: function() {
1035
			//console.log('Avant fermeture fancybox');
1035
			//console.log('Avant fermeture fancybox');
1036
			$("#fc_destinataire_id").attr('value', '');
1036
			$("#fc_destinataire_id").attr('value', '');
1037
			$("#fc_sujet").attr('value', '');
1037
			$("#fc_sujet").attr('value', '');
1038
			$("#fc_message").text('');
1038
			$("#fc_message").text('');
1039
		},
1039
		},
1040
		onClosed: function(e) {
1040
		onClosed: function(e) {
1041
			//console.log('Fermeture fancybox');
1041
			//console.log('Fermeture fancybox');
1042
			if (e.stopPropagation) {
1042
			if (e.stopPropagation) {
1043
				e.stopPropagation();
1043
				e.stopPropagation();
1044
			}
1044
			}
1045
			return false;
1045
			return false;
1046
		}
1046
		}
1047
	});
1047
	});
1048
}
1048
}
1049
 
1049
 
1050
function chargerInfoObsPourMessage(idObs) {
1050
function chargerInfoObsPourMessage(idObs) {
1051
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
1051
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
1052
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1052
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1053
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1053
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1054
	var sujet = "Observation #"+idObs+" de "+nomSci;
1054
	var sujet = "Observation #"+idObs+" de "+nomSci;
1055
	var message = "\n\n\n\n\n\n\n\n--\n" + msg('concerne-l-observation') + " \""+nomSci+'" ' + msg('du') + ' "'+date+'" ' + msg('au-lieu') + ' "'+lieu+'".';
1055
	var message = "\n\n\n\n\n\n\n\n--\n" + msg('concerne-l-observation') + " \""+nomSci+'" ' + msg('du') + ' "'+date+'" ' + msg('au-lieu') + ' "'+lieu+'".';
1056
	$("#fc_sujet").attr('value', sujet);
1056
	$("#fc_sujet").attr('value', sujet);
1057
	$("#fc_message").text(message);
1057
	$("#fc_message").text(message);
1058
}
1058
}
1059
 
1059
 
1060
function initialiserFormulaireContact() {
1060
function initialiserFormulaireContact() {
1061
	//console.log('Initialisation du form contact');
1061
	//console.log('Initialisation du form contact');
1062
	$("#form-contact").validate({
1062
	$("#form-contact").validate({
1063
		rules: {
1063
		rules: {
1064
			fc_sujet : "required",
1064
			fc_sujet : "required",
1065
			fc_message : "required",
1065
			fc_message : "required",
1066
			fc_utilisateur_courriel : {
1066
			fc_utilisateur_courriel : {
1067
				required : true,
1067
				required : true,
1068
				email : true}
1068
				email : true}
1069
		}
1069
		}
1070
	});
1070
	});
1071
	$("#form-contact").bind("submit", envoyerCourriel);
1071
	$("#form-contact").bind("submit", envoyerCourriel);
1072
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1072
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1073
	
1073
	
1074
}
1074
}
1075
 
1075
 
1076
function envoyerCourriel() {
1076
function envoyerCourriel() {
1077
	//console.log('Formulaire soumis');
1077
	//console.log('Formulaire soumis');
1078
	if ($("#form-contact").valid()) {
1078
	if ($("#form-contact").valid()) {
1079
		//console.log('Formulaire valide');
1079
		//console.log('Formulaire valide');
1080
		//$.fancybox.showActivity();
1080
		//$.fancybox.showActivity();
1081
		var destinataireId = $("#fc_destinataire_id").attr('value');
1081
		var destinataireId = $("#fc_destinataire_id").attr('value');
1082
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1082
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1083
		if(typeEnvoi == "non-inscrit") {
1083
		if(typeEnvoi == "non-inscrit") {
1084
			// l'envoi au non inscrits passe par le service intermédiaire du cel
1084
			// l'envoi au non inscrits passe par le service intermédiaire du cel
1085
			// qui va récupérer le courriel associé à l'obs indiquée
1085
			// qui va récupérer le courriel associé à l'obs indiquée
1086
			var urlMessage = baseURLServicesCelTpl.replace('%s', 'celMessage/obs/'+destinataireId);
1086
			var urlMessage = baseURLServicesCelTpl.replace('%s', 'celMessage/obs/'+destinataireId);
1087
		} else {
1087
		} else {
1088
			var urlMessage = baseURLServicesAnnuaireTpl.replace('%s', 'Utilisateur/'+destinataireId+'/message');
1088
			var urlMessage = baseURLServicesAnnuaireTpl.replace('%s', 'Utilisateur/'+destinataireId+'/message');
1089
		}
1089
		}
1090
		var erreurMsg = "";
1090
		var erreurMsg = "";
1091
		var donnees = new Array();
1091
		var donnees = new Array();
1092
		$.each($(this).serializeArray(), function (index, champ) {
1092
		$.each($(this).serializeArray(), function (index, champ) {
1093
			var cle = champ.name;
1093
			var cle = champ.name;
1094
			cle = cle.replace(/^fc_/, '');
1094
			cle = cle.replace(/^fc_/, '');
1095
			
1095
			
1096
			if (cle == 'sujet') {
1096
			if (cle == 'sujet') {
1097
				champ.value += " - Carnet en ligne - Tela Botanica";
1097
				champ.value += " - Carnet en ligne - Tela Botanica";
1098
			}
1098
			}
1099
			if (cle == 'message') {
1099
			if (cle == 'message') {
1100
				champ.value += "\n--\n"+
1100
				champ.value += "\n--\n"+
1101
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
1101
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
1102
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1102
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1103
					"https://www.tela-botanica.org/widget:cel:cartoPoint";
1103
					"https://www.tela-botanica.org/widget:cel:cartoPoint";
1104
			}
1104
			}
1105
			
1105
			
1106
			donnees[index] = {'name':cle,'value':champ.value};
1106
			donnees[index] = {'name':cle,'value':champ.value};
1107
		});
1107
		});
1108
		$.ajax({
1108
		$.ajax({
1109
			type : "POST",
1109
			type : "POST",
1110
			cache : false,
1110
			cache : false,
1111
			url : urlMessage,
1111
			url : urlMessage,
1112
			data : donnees,
1112
			data : donnees,
1113
			beforeSend : function() {
1113
			beforeSend : function() {
1114
				$(".msg").remove();
1114
				$(".msg").remove();
1115
			},
1115
			},
1116
			success : function(data) {
1116
			success : function(data) {
1117
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1117
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1118
			},
1118
			},
1119
			error : function(jqXHR, textStatus, errorThrown) {
1119
			error : function(jqXHR, textStatus, errorThrown) {
1120
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1120
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1121
				reponse = jQuery.parseJSON(jqXHR.responseText);
1121
				reponse = jQuery.parseJSON(jqXHR.responseText);
1122
				if (reponse != null) {
1122
				if (reponse != null) {
1123
					$.each(reponse, function (cle, valeur) {
1123
					$.each(reponse, function (cle, valeur) {
1124
						erreurMsg += valeur + "\n";
1124
						erreurMsg += valeur + "\n";
1125
					});
1125
					});
1126
				}				
1126
				}				
1127
			},
1127
			},
1128
			complete : function(jqXHR, textStatus) {
1128
			complete : function(jqXHR, textStatus) {
1129
				var debugMsg = '';
1129
				var debugMsg = '';
1130
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1130
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1131
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1131
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1132
					if (debugInfos != null) {
1132
					if (debugInfos != null) {
1133
						$.each(debugInfos, function (cle, valeur) {
1133
						$.each(debugInfos, function (cle, valeur) {
1134
							debugMsg += valeur + "\n";
1134
							debugMsg += valeur + "\n";
1135
						});
1135
						});
1136
					}
1136
					}
1137
				}
1137
				}
1138
				if (erreurMsg != '') {
1138
				if (erreurMsg != '') {
1139
					$("#fc-zone-dialogue").append('<p class="msg">'+
1139
					$("#fc-zone-dialogue").append('<p class="msg">'+
1140
							msg('erreur-transmission-message') +'<br />'+
1140
							msg('erreur-transmission-message') +'<br />'+
1141
							msg('signaler-dysfonctionnement') + ' <a href="'+
1141
							msg('signaler-dysfonctionnement') + ' <a href="'+
1142
							'mailto:cel@tela-botanica.org'+'?'+
1142
							'mailto:cel@tela-botanica.org'+'?'+
1143
							'subject=Disfonctionnement du widget carto'+
1143
							'subject=Disfonctionnement du widget carto'+
1144
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1144
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1145
							'">cel@tela-botanica.org</a>.'+
1145
							'">cel@tela-botanica.org</a>.'+
1146
							'</p>');
1146
							'</p>');
1147
				}
1147
				}
1148
				if (DEBUG) {
1148
				if (DEBUG) {
1149
					console.log('Débogage : '+debugMsg);
1149
					console.log('Débogage : '+debugMsg);
1150
				}
1150
				}
1151
				//console.log('Débogage : '+debugMsg);
1151
				//console.log('Débogage : '+debugMsg);
1152
				//console.log('Erreur : '+erreurMsg);
1152
				//console.log('Erreur : '+erreurMsg);
1153
			}
1153
			}
1154
		});
1154
		});
1155
	}
1155
	}
1156
	return false;
1156
	return false;
1157
}
1157
}
1158
/*+--------------------------------------------------------------------------------------------------------+*/
1158
/*+--------------------------------------------------------------------------------------------------------+*/
1159
// PANNEAU LATÉRAL
1159
// PANNEAU LATÉRAL
1160
var nbTaxons = 0;
1160
var nbTaxons = 0;
1161
function initialiserAffichagePanneauLateral() {	
1161
function initialiserAffichagePanneauLateral() {	
1162
	if (nt == '*') {
1162
	if (nt == '*') {
1163
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1163
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1164
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1164
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1165
	} else {
1165
	} else {
1166
		$('#panneau-lateral').width(0);
1166
		$('#panneau-lateral').width(0);
1167
		$('#carte').width('100%');
1167
		$('#carte').width('100%');
1168
	}
1168
	}
1169
	attribuerListenersFiltreUtilisateur();
1169
	attribuerListenersFiltreUtilisateur();
1170
}
1170
}
1171
 
1171
 
1172
function attribuerListenersFiltreUtilisateur() {
1172
function attribuerListenersFiltreUtilisateur() {
1173
	$('#valider-filtre-utilisateur').click(function() {
1173
	$('#valider-filtre-utilisateur').click(function() {
1174
		var utilisateur = $('#filtre-utilisateur').val();
1174
		var utilisateur = $('#filtre-utilisateur').val();
1175
		filtrerParUtilisateur(utilisateur);
1175
		filtrerParUtilisateur(utilisateur);
1176
		$('#raz-filtre-utilisateur').show();
1176
		$('#raz-filtre-utilisateur').show();
1177
	});
1177
	});
1178
	
1178
	
1179
	$('#filtre-utilisateur').keypress(function(e) {
1179
	$('#filtre-utilisateur').keypress(function(e) {
1180
		if (e.which == 13) {
1180
		if (e.which == 13) {
1181
			var utilisateur = $('#filtre-utilisateur').val();
1181
			var utilisateur = $('#filtre-utilisateur').val();
1182
			filtrerParUtilisateur(utilisateur);
1182
			filtrerParUtilisateur(utilisateur);
1183
			$('#raz-filtre-utilisateur').show();
1183
			$('#raz-filtre-utilisateur').show();
1184
		}
1184
		}
1185
	});
1185
	});
1186
	
1186
	
1187
	$('#raz-filtre-utilisateur').click(function() {
1187
	$('#raz-filtre-utilisateur').click(function() {
1188
		$('#filtre-utilisateur').val('');
1188
		$('#filtre-utilisateur').val('');
1189
		filtrerParUtilisateur('*');
1189
		filtrerParUtilisateur('*');
1190
		afficherCacherFiltreUtilisateur();
1190
		afficherCacherFiltreUtilisateur();
1191
		$('#raz-filtre-utilisateur').hide();
1191
		$('#raz-filtre-utilisateur').hide();
1192
	});
1192
	});
1193
	
1193
	
1194
	$('#lien-affichage-filtre-utilisateur').click(function() {
1194
	$('#lien-affichage-filtre-utilisateur').click(function() {
1195
		afficherCacherFiltreUtilisateur();
1195
		afficherCacherFiltreUtilisateur();
1196
	});
1196
	});
1197
 
1197
 
1198
	$('#raz-filtre-utilisateur').hide();
1198
	$('#raz-filtre-utilisateur').hide();
1199
	$('#formulaire-filtre-utilisateur').hide();
1199
	$('#formulaire-filtre-utilisateur').hide();
1200
}
1200
}
1201
 
1201
 
1202
function afficherCacherFiltreUtilisateur() {
1202
function afficherCacherFiltreUtilisateur() {
1203
	$('#formulaire-filtre-utilisateur').slideToggle();
1203
	$('#formulaire-filtre-utilisateur').slideToggle();
1204
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1204
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1205
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1205
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1206
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1206
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1207
	} else {
1207
	} else {
1208
		$('#conteneur-filtre-utilisateur').width('auto');
1208
		$('#conteneur-filtre-utilisateur').width('auto');
1209
	}
1209
	}
1210
}
1210
}
1211
 
1211
 
1212
function filtrerParUtilisateur(utilisateurFiltre) {
1212
function filtrerParUtilisateur(utilisateurFiltre) {
1213
	if (utilisateurFiltre == '') {	
1213
	if (utilisateurFiltre == '') {	
1214
		utilisateurFiltre = '*';
1214
		utilisateurFiltre = '*';
1215
	}
1215
	}
1216
	utilisateur = utilisateurFiltre;
1216
	utilisateur = utilisateurFiltre;
1217
	var pattern = /utilisateur=[^&]*/i,
1217
	var pattern = /utilisateur=[^&]*/i,
1218
		utilisateurCourant = pattern.exec(stationsUrl);
1218
		utilisateurCourant = pattern.exec(stationsUrl);
1219
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1219
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1220
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1220
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1221
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1221
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1222
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1222
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1223
	programmerRafraichissementCarte();
1223
	programmerRafraichissementCarte();
1224
}
1224
}
1225
 
1225
 
1226
 
1226
 
1227
 
1227
 
1228
var largeurPanneauLateralFerme = null;
1228
var largeurPanneauLateralFerme = null;
1229
function afficherPanneauLateral() {
1229
function afficherPanneauLateral() {
1230
	// fixer la hauteur
1230
	// fixer la hauteur
1231
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top - 30);
1231
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top - 30);
1232
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1232
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1233
	$('#panneau-lateral').width(300);
1233
	$('#panneau-lateral').width(300);
1234
	$('#pl-contenu').css('display', 'block');
1234
	$('#pl-contenu').css('display', 'block');
1235
	$('#pl-ouverture').css('display', 'none');
1235
	$('#pl-ouverture').css('display', 'none');
1236
	$('#pl-fermeture').css('display', 'block');
1236
	$('#pl-fermeture').css('display', 'block');
1237
	// correction pour la taille de la liste des taxons
1237
	// correction pour la taille de la liste des taxons
1238
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1238
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1239
 
1239
 
1240
	google.maps.event.trigger(map, 'resize');
1240
	google.maps.event.trigger(map, 'resize');
1241
};
1241
};
1242
 
1242
 
1243
function cacherPanneauLateral() {
1243
function cacherPanneauLateral() {
1244
	$('#panneau-lateral').height(25 + 'px');
1244
	$('#panneau-lateral').height(25 + 'px');
1245
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1245
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1246
	$('#pl-contenu').css('display', 'none');
1246
	$('#pl-contenu').css('display', 'none');
1247
	$('#pl-ouverture').css('display', 'block');
1247
	$('#pl-ouverture').css('display', 'block');
1248
	$('#pl-fermeture').css('display', 'none');
1248
	$('#pl-fermeture').css('display', 'none');
1249
	
1249
	
1250
	google.maps.event.trigger(map, 'resize');
1250
	google.maps.event.trigger(map, 'resize');
1251
};
1251
};
1252
 
1252
 
1253
function viderFiltreTaxon() {
1253
function viderFiltreTaxon() {
1254
	$('.taxon-actif .taxon').click();
1254
	$('.taxon-actif .taxon').click();
1255
}
1255
}
1256
 
1256
 
1257
function filtrerParTaxon() {
1257
function filtrerParTaxon() {
1258
	var ntAFiltrer = $('.nt', this).text();
1258
	var ntAFiltrer = $('.nt', this).text();
1259
	infoBulle.close();
1259
	infoBulle.close();
1260
	var zoom = map.getZoom();
1260
	var zoom = map.getZoom();
1261
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1261
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1262
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1262
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1263
	
1263
	
1264
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1264
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1265
	$('#taxon-'+nt).removeClass('taxon-actif');
1265
	$('#taxon-'+nt).removeClass('taxon-actif');
1266
	
1266
	
1267
	if (nt == ntAFiltrer) {
1267
	if (nt == ntAFiltrer) {
1268
		nt = '*';
1268
		nt = '*';
1269
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1269
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1270
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1270
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1271
	} else {
1271
	} else {
1272
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1272
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1273
		url = stationsUrl;
1273
		url = stationsUrl;
1274
		url += '&zoom='+zoom+
1274
		url += '&zoom='+zoom+
1275
			'&ne='+NELatLng+
1275
			'&ne='+NELatLng+
1276
			'&sw='+SWLatLng;
1276
			'&sw='+SWLatLng;
1277
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1277
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1278
			stations = stationsFiltrees;
1278
			stations = stationsFiltrees;
1279
			nt = ntAFiltrer;
1279
			nt = ntAFiltrer;
1280
			$('#taxon-'+nt).addClass('taxon-actif');
1280
			$('#taxon-'+nt).addClass('taxon-actif');
1281
			rafraichirMarqueurs(stations);
1281
			rafraichirMarqueurs(stations);
1282
		});
1282
		});
1283
	}
1283
	}
1284
};
1284
};
1285
 
1285
 
1286
/*+--------------------------------------------------------------------------------------------------------+*/
1286
/*+--------------------------------------------------------------------------------------------------------+*/
1287
// FONCTIONS UTILITAIRES
1287
// FONCTIONS UTILITAIRES
1288
 
1288
 
1289
function ouvrirPopUp(element, nomPopUp, event) {
1289
function ouvrirPopUp(element, nomPopUp, event) {
1290
	var options = 
1290
	var options = 
1291
		'width=650,'+
1291
		'width=650,'+
1292
		'height=600,'+
1292
		'height=600,'+
1293
		'scrollbars=yes,'+
1293
		'scrollbars=yes,'+
1294
		'directories=no,'+
1294
		'directories=no,'+
1295
		'location=no,'+
1295
		'location=no,'+
1296
		'menubar=no,'+
1296
		'menubar=no,'+
1297
		'status=no,'+
1297
		'status=no,'+
1298
		'toolbar=no';
1298
		'toolbar=no';
1299
	var popUp = window.open(element.href, nomPopUp, options);
1299
	var popUp = window.open(element.href, nomPopUp, options);
1300
	if (window.focus) {
1300
	if (window.focus) {
1301
		popUp.focus();
1301
		popUp.focus();
1302
	}
1302
	}
1303
	return arreter(event);
1303
	return arreter(event);
1304
};
1304
};
1305
 
1305
 
1306
function ouvrirNouvelleFenetre(element, event) {
1306
function ouvrirNouvelleFenetre(element, event) {
1307
	window.open(element.href);
1307
	window.open(element.href);
1308
	return arreter(event);
1308
	return arreter(event);
1309
}
1309
}
1310
 
1310
 
1311
function arreter(event) {
1311
function arreter(event) {
1312
	if (event.stopPropagation) {
1312
	if (event.stopPropagation) {
1313
		event.stopPropagation();
1313
		event.stopPropagation();
1314
	} else if (window.event) {
1314
	} else if (window.event) {
1315
		window.event.cancelBubble = true;
1315
		window.event.cancelBubble = true;
1316
	}
1316
	}
1317
	if (event.preventDefault) {
1317
	if (event.preventDefault) {
1318
		event.preventDefault();
1318
		event.preventDefault();
1319
	}
1319
	}
1320
	event.returnValue = false;
1320
	event.returnValue = false;
1321
	return false;
1321
	return false;
1322
}
1322
}
1323
 
1323
 
1324
/**
1324
/**
1325
 * +-------------------------------------+
1325
 * +-------------------------------------+
1326
 * Number.prototype.formaterNombre
1326
 * Number.prototype.formaterNombre
1327
 * +-------------------------------------+
1327
 * +-------------------------------------+
1328
 * Params (facultatifs):
1328
 * Params (facultatifs):
1329
 * - Int decimales: nombre de decimales (exemple: 2)
1329
 * - Int decimales: nombre de decimales (exemple: 2)
1330
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1330
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1331
 * - String separateurMilliers: comme son nom l'indique
1331
 * - String separateurMilliers: comme son nom l'indique
1332
 * Returns:
1332
 * Returns:
1333
 * - String chaine formatee
1333
 * - String chaine formatee
1334
 * @author	::mastahbenus::
1334
 * @author	::mastahbenus::
1335
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
1335
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
1336
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
1336
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
1337
 */
1337
 */
1338
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1338
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1339
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1339
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1340
	
1340
	
1341
	function is_int(nbre) {
1341
	function is_int(nbre) {
1342
		nbre = nbre.replace(',', '.');
1342
		nbre = nbre.replace(',', '.');
1343
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1343
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1344
	}
1344
	}
1345
 
1345
 
1346
	if (decimales == undefined) {
1346
	if (decimales == undefined) {
1347
		if (is_int(_sNombre)) {
1347
		if (is_int(_sNombre)) {
1348
			decimales = 0;
1348
			decimales = 0;
1349
		} else {
1349
		} else {
1350
			decimales = 2;
1350
			decimales = 2;
1351
		}
1351
		}
1352
	}
1352
	}
1353
	if (signe == undefined) {
1353
	if (signe == undefined) {
1354
		if (is_int(_sNombre)) {
1354
		if (is_int(_sNombre)) {
1355
			signe = '';
1355
			signe = '';
1356
		} else {
1356
		} else {
1357
			signe = '.';
1357
			signe = '.';
1358
		}
1358
		}
1359
	}
1359
	}
1360
	if (separateurMilliers == undefined) {
1360
	if (separateurMilliers == undefined) {
1361
		separateurMilliers = ' ';
1361
		separateurMilliers = ' ';
1362
	}
1362
	}
1363
	
1363
	
1364
	function separeMilliers (sNombre) {
1364
	function separeMilliers (sNombre) {
1365
		var sRetour = "";
1365
		var sRetour = "";
1366
		while (sNombre.length % 3 != 0) {
1366
		while (sNombre.length % 3 != 0) {
1367
			sNombre = "0"+sNombre;
1367
			sNombre = "0"+sNombre;
1368
		}
1368
		}
1369
		for (i = 0; i < sNombre.length; i += 3) {
1369
		for (i = 0; i < sNombre.length; i += 3) {
1370
			if (i == sNombre.length-1) separateurMilliers = '';
1370
			if (i == sNombre.length-1) separateurMilliers = '';
1371
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1371
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1372
		}
1372
		}
1373
		while (sRetour.substr(0, 1) == "0") {
1373
		while (sRetour.substr(0, 1) == "0") {
1374
			sRetour = sRetour.substr(1);
1374
			sRetour = sRetour.substr(1);
1375
		}
1375
		}
1376
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1376
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1377
	}
1377
	}
1378
	
1378
	
1379
	if (_sNombre.indexOf('.') == -1) {
1379
	if (_sNombre.indexOf('.') == -1) {
1380
		for (i = 0; i < decimales; i++) {
1380
		for (i = 0; i < decimales; i++) {
1381
			_sDecimales += '0';
1381
			_sDecimales += '0';
1382
		}
1382
		}
1383
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1383
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1384
	} else {
1384
	} else {
1385
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1385
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1386
		if (sDecimalesTmp.length > decimales) {
1386
		if (sDecimalesTmp.length > decimales) {
1387
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1387
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1388
			var nDiv = 1;
1388
			var nDiv = 1;
1389
			for (i = 0; i < nDecimalesManquantes; i++) {
1389
			for (i = 0; i < nDecimalesManquantes; i++) {
1390
				nDiv *= 10;
1390
				nDiv *= 10;
1391
			}
1391
			}
1392
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1392
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1393
		}
1393
		}
1394
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1394
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1395
	}
1395
	}
1396
	return _sRetour;
1396
	return _sRetour;
1397
}
1397
}
1398
 
1398
 
1399
function debug(objet) {
1399
function debug(objet) {
1400
	var msg = '';
1400
	var msg = '';
1401
	if (objet != null) {
1401
	if (objet != null) {
1402
		$.each(objet, function (cle, valeur) {
1402
		$.each(objet, function (cle, valeur) {
1403
			msg += cle+':'+valeur + "\n";
1403
			msg += cle+':'+valeur + "\n";
1404
		});
1404
		});
1405
	} else {
1405
	} else {
1406
		msg = 'La variable vaut null.';
1406
		msg = 'La variable vaut null.';
1407
	}
1407
	}
1408
	console.log(msg);
1408
	console.log(msg);
1409
}
1409
}