Subversion Repositories eFlore/Applications.cel

Rev

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

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