Subversion Repositories eFlore/Applications.cel

Rev

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

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