Subversion Repositories eFlore/Applications.cel

Rev

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

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