Subversion Repositories eFlore/Applications.cel

Rev

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

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