Subversion Repositories eFlore/Applications.cel

Rev

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

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