Subversion Repositories eFlore/Applications.cel

Rev

Rev 1044 | Rev 2286 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1044 Rev 1799
Line 1... Line -...
1
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
2
// PARAMÊTRES et CONSTANTES
-
 
3
// Mettre à true pour afficher les messages de débogage
-
 
4
var DEBUG = false; 
-
 
5
/**
-
 
6
 * Indication de certaines variables ajoutée par php
-
 
7
* var communeImageUrl ;
-
 
8
* var pointImageUrl ;
-
 
9
* var groupeImageUrlTpl ;
-
 
10
*/
-
 
11
var pointsOrigine = null;
-
 
12
var boundsOrigine = null;
-
 
13
var markerClusterer = null;
-
 
14
var map = null;
-
 
15
var infoBulle = new google.maps.InfoWindow();
-
 
16
var stations = null;
-
 
17
var pointClique = null;
-
 
18
var carteCentre = new google.maps.LatLng(25, 10);
-
 
19
var carteOptions = {
-
 
20
	zoom: 3,
-
 
21
	center:carteCentre,
-
 
22
	mapTypeId: google.maps.MapTypeId.ROADMAP,
-
 
23
	mapTypeControlOptions: {
-
 
24
		mapTypeIds: ['OSM', 
-
 
25
		             google.maps.MapTypeId.ROADMAP, 
-
 
26
		             google.maps.MapTypeId.HYBRID, 
-
 
27
		             google.maps.MapTypeId.SATELLITE, 
-
 
28
		             google.maps.MapTypeId.TERRAIN]
-
 
29
	}
-
 
30
};			
-
 
31
var osmMapType = new google.maps.ImageMapType({
-
 
32
	getTileUrl: function(coord, zoom) {
-
 
33
		return "http://tile.openstreetmap.org/" +
-
 
34
		zoom + "/" + coord.x + "/" + coord.y + ".png";
-
 
35
	},
-
 
36
	tileSize: new google.maps.Size(256, 256),
-
 
37
	isPng: true,
-
 
38
	alt: "OpenStreetMap",
-
 
39
	name: "OSM",
-
 
40
	maxZoom: 19
-
 
41
});
-
 
42
var ctaLayer = null;
-
 
43
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
-
 
44
var station = {'commune':'', 'obsNbre':0};
-
 
45
var obsStation = new Array();
-
 
46
var obsPage = new Array();
-
 
47
var taxonsCarte = new Array();
-
 
48
var mgr = null;
-
 
49
var marqueursCache = new Array();
-
 
50
var zonesCache = new Array();
-
 
51
var requeteChargementPoints;
-
 
52
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
53
// INITIALISATION DU CODE
-
 
54
 
-
 
55
//Déclenchement d'actions quand JQuery et le document HTML sont OK
-
 
56
$(document).ready(function() {
-
 
57
	initialiserWidget();
-
 
58
});
-
 
59
 
-
 
60
function initialiserWidget() {
-
 
61
	definirTailleTitre();
-
 
62
	initialiserAffichageCarte();
-
 
63
	initialiserAffichagePanneauLateral();
-
 
64
	initialiserCarte();
-
 
65
	initialiserGestionnaireMarqueurs()
-
 
66
	initialiserInfoBulle();
-
 
67
	initialiserFormulaireContact();
-
 
68
	chargerLimitesCommunales();
-
 
69
	attribuerListenerCarte();
-
 
70
	programmerRafraichissementCarte();
-
 
71
}
-
 
72
 
-
 
73
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
74
// AFFICHAGE GÉNÉRAL
-
 
75
 
-
 
76
function afficherTitreCarte() {
-
 
77
	if (stations != null && taxonsCarte.length > 0) {
-
 
78
		var obsNbre = stations.stats.observations;
-
 
79
		var obsNbreFormate = stations.stats.observations.formaterNombre();
-
 
80
		var plteNbre = taxonsCarte.length;
-
 
81
		var plteNbreFormate = taxonsCarte.length.formaterNombre();
-
 
82
		var communeNbre = stations.stats.communes;
-
 
83
		var communeNbreFormate = stations.stats.communes.formaterNombre();
-
 
84
	
-
 
85
		var titre = obsNbreFormate+' observation';
-
 
86
		titre += (obsNbre > 1) ? 's' : '' ;
-
 
87
		
-
 
88
		if (nt == '*') {
-
 
89
			titre += ' de '+plteNbreFormate+' plante';
-
 
90
			titre += (plteNbre > 1) ? 's' : '' ;
-
 
91
		} else {
-
 
92
			if (taxonsCarte[0]) {
-
 
93
				var taxon = taxonsCarte[0];
-
 
94
				titre += ' pour '+taxon.nom;
-
 
95
			}
-
 
96
		}
-
 
97
		
-
 
98
		titre += ' sur '+communeNbreFormate+' commune';
-
 
99
		titre += (communeNbre > 1) ? 's' : '' ;
-
 
100
		
-
 
101
		$('#carte-titre-infos').text(titre);
-
 
102
	}
-
 
103
}
-
 
104
 
-
 
105
function definirTailleTitre() {
-
 
106
	var largeurViewPort = $(window).width();
-
 
107
	var taille = null;
-
 
108
	if (largeurViewPort < 400) {
-
 
109
		taille = '0.8';
-
 
110
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
-
 
111
		taille = '1.0';
-
 
112
	} else if (largeurViewPort >= 800) {
-
 
113
		taille = '1.6';
-
 
114
	}
-
 
115
	$("#carte-titre").css('font-size', taille+'em');
-
 
116
}
-
 
117
 
-
 
118
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
119
// CARTE
-
 
120
 
-
 
121
function initialiserAffichageCarte() {
-
 
122
	$('#carte').height($(window).height() - 35);
-
 
123
	$('#carte').width($(window).width() - 24);
-
 
124
 
-
 
125
	if (nt != '*') {
-
 
126
		$('#carte').css('left', 0);
-
 
127
	}
-
 
128
}
-
 
129
 
-
 
130
function initialiserCarte() {
-
 
131
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
-
 
132
	// Ajout de la couche OSM à la carte
-
 
133
	map.mapTypes.set('OSM', osmMapType);
-
 
134
}
-
 
135
 
-
 
136
function initialiserGestionnaireMarqueurs() {
-
 
137
	mgr = new MarkerManager(map);
-
 
138
}
-
 
139
 
-
 
140
function chargerLimitesCommunales() {
-
 
141
	if (urlsLimitesCommunales != null) {
-
 
142
		for (urlId in urlsLimitesCommunales) { 
-
 
143
			var url = urlsLimitesCommunales[urlId];
-
 
144
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: false});
-
 
145
			ctaLayer.setMap(map);
-
 
146
		}
-
 
147
	}
-
 
148
}
-
 
149
 
-
 
150
var listener = null;
-
 
151
var timer = null;
-
 
152
function attribuerListenerCarte() {
-
 
153
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
-
 
154
		programmerRafraichissementCarte();
-
 
155
	});
-
 
156
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
-
 
157
		programmerRafraichissementCarte();
-
 
158
	});
-
 
159
}
-
 
160
function programmerRafraichissementCarte() {
-
 
161
	if(timer != null) {
-
 
162
        window.clearTimeout(timer);
-
 
163
    }
-
 
164
	if(requeteChargementPoints != null) {
-
 
165
		requeteChargementPoints.abort();
-
 
166
	}
-
 
167
	timer = window.setTimeout(function() {
-
 
168
		var zoom = map.getZoom();
-
 
169
		var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(map.getBounds().getNorthEast().lng());
-
 
170
		var SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(map.getBounds().getSouthWest().lng());
-
 
171
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
-
 
172
    }, 400);		
-
 
173
}
-
 
174
 
-
 
175
var marqueurs = new Array();
-
 
176
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
-
 
177
	var url = stationsUrl+
-
 
178
		'&zoom='+zoom+
-
 
179
		'&ne='+NELatLng+
-
 
180
		'&sw='+SWLatLng;
-
 
181
	
-
 
182
	if(infoBulleOuverte) {
-
 
183
		return;
-
 
184
	}
-
 
185
	
-
 
186
	if(requeteChargementPoints != null) {
-
 
187
		requeteChargementPoints.abort();
-
 
188
		cacherMessageChargementPoints();
-
 
189
	}
-
 
190
	
-
 
191
	afficherMessageChargementPoints();
-
 
192
	requeteChargementPoints = $.getJSON(url, function(data) {
-
 
193
		rafraichirMarqueurs(data);
-
 
194
		cacherMessageChargementPoints();
-
 
195
	});
-
 
196
}
-
 
197
 
-
 
198
function afficherMessageChargementPoints() {
-
 
199
	$('#zone-chargement-point').css('display','block');
-
 
200
}
-
 
201
 
-
 
202
function cacherMessageChargementPoints() {
-
 
203
	$('#zone-chargement-point').css('display','none');
-
 
204
}
-
 
205
 
-
 
206
function rafraichirMarqueurs(data) {
-
 
207
	$.each(marqueurs, function(index, marqueur) {
-
 
208
		marqueur.setMap(null);
-
 
209
	});
-
 
210
	marqueurs = new Array();
-
 
211
	
-
 
212
	stations = data;
-
 
213
	afficherTitreCarte();
-
 
214
	
-
 
215
	$.each(stations.points, function (index, station) {		
-
 
216
		if(station != null) {
-
 
217
			var nouveauMarqueur = creerMarqueur(station);
-
 
218
			marqueurs.push(nouveauMarqueur);
-
 
219
		}
-
 
220
	});
-
 
221
}
-
 
222
 
-
 
223
function creerMarqueur(station) {
-
 
224
	var titre = '';
-
 
225
	if(station.nbreMarqueur) {
-
 
226
		titre = station.nbreMarqueur+' points renseignés';
-
 
227
	} else {
-
 
228
		if(station.nom) {
-
 
229
			titre = station.nom;
-
 
230
		}
-
 
231
	}
-
 
232
	//var titre = station['nbreMarqueur'];
-
 
233
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
-
 
234
	var latLng = new google.maps.LatLng(station['lat'], station['lng']);
-
 
235
	var marqueur = new google.maps.Marker({
-
 
236
		position: latLng,
-
 
237
		icon: icone,
-
 
238
		title: ''+titre,
-
 
239
		map: map,
-
 
240
		stationInfos: station
-
 
241
	});
-
 
242
	attribuerListenerClick(marqueur, station['id']);
-
 
243
	marqueur.setMap(map);
-
 
244
    return marqueur;
-
 
245
}
-
 
246
 
-
 
247
function rendrePointsVisibles(bounds) {
-
 
248
	map.setCenter(bounds.getCenter());
-
 
249
	map.fitBounds(bounds);
-
 
250
	map.panToBounds(bounds);
-
 
251
}
-
 
252
 
-
 
253
function programmerRafraichissementCarteSauv() {
-
 
254
	
-
 
255
	var points = [];
-
 
256
	var bounds = new google.maps.LatLngBounds();
-
 
257
	for (var i = 0; i < stations.points.length; ++i) {
-
 
258
		var point = stations.points[i];
-
 
259
		var maLatLng = new google.maps.LatLng(point.lat, point.lng);
-
 
260
		var stationImage = attribuerImageMarqueur(point.id); 
-
 
261
		var point = new google.maps.Marker({
-
 
262
			position: maLatLng,
-
 
263
			map: map,
-
 
264
			icon: stationImage,
-
 
265
			stationInfos: point
-
 
266
		});
-
 
267
		bounds.extend(maLatLng);
-
 
268
		google.maps.event.addListener(point, 'click', surClickMarqueur);
-
 
269
		points.push(point);
-
 
270
	}
-
 
271
 
-
 
272
	if (pointsOrigine == null && boundsOrigine == null) {
-
 
273
		pointsOrigine = points;
-
 
274
		boundsOrigine = bounds;
-
 
275
	}
-
 
276
	
-
 
277
	executerMarkerClusterer(points, bounds);
-
 
278
}
-
 
279
 
-
 
280
function attribuerImageMarqueur(id, nbreMarqueur) {
-
 
281
	var marqueurImage = null;
-
 
282
	if (etreMarqueurCommune(id)) {
-
 
283
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
-
 
284
	} else if (etreMarqueurStation(id)) {
-
 
285
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
-
 
286
	} else if (etreMarqueurGroupe(id)) {
-
 
287
		var type = 0;
-
 
288
		var largeur = 0;
-
 
289
		var hauteur = 0;
-
 
290
		if (nbreMarqueur != null) {
-
 
291
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
-
 
292
				type = '1';
-
 
293
				largeur = 53;
-
 
294
				hauteur = 52;
-
 
295
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
-
 
296
				type = '2';
-
 
297
				largeur = 56;
-
 
298
				hauteur = 55;
-
 
299
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
-
 
300
				type = '3';
-
 
301
				largeur = 66;
-
 
302
				hauteur = 65;
-
 
303
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
-
 
304
				type = '4';
-
 
305
				largeur = 78;
-
 
306
				hauteur = 77;
-
 
307
			} else if (nbreMarqueur >= 20000) {
-
 
308
				type = '5';
-
 
309
				largeur = 66;
-
 
310
				hauteur = 65;
-
 
311
			}
-
 
312
		}
-
 
313
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
-
 
314
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
-
 
315
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
-
 
316
	}
-
 
317
	return marqueurImage
-
 
318
}
-
 
319
 
-
 
320
function attribuerListenerClick(marqueur, id) {
-
 
321
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
-
 
322
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
-
 
323
	} else if (etreMarqueurGroupe(id)) {
-
 
324
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
-
 
325
	}
-
 
326
}
-
 
327
 
-
 
328
function surClickMarqueur(event) {
-
 
329
 
-
 
330
	if(infoBulleOuverte) {
-
 
331
	    infoBulle.close();
-
 
332
	}
-
 
333
  
-
 
334
	pointClique = this;
-
 
335
	infoBulle.open(map, this);
-
 
336
	actualiserPagineur();
-
 
337
	
-
 
338
	var limites = map.getBounds();
-
 
339
	var centre = limites.getCenter();
-
 
340
	var nordEst = limites.getNorthEast();
-
 
341
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
-
 
342
	map.panTo(centreSudLatLng);
-
 
343
	
-
 
344
	afficherInfoBulle();
-
 
345
}
-
 
346
 
-
 
347
function surClickGroupe() {
-
 
348
	map.setCenter(this.getPosition());
-
 
349
	var nouveauZoom = map.getZoom() + 2;
-
 
350
	map.setZoom(nouveauZoom);
-
 
351
	mgr.clearMarkers();
-
 
352
}
-
 
353
 
-
 
354
function etreMarqueurGroupe(id) {
-
 
355
	var groupe = false;
-
 
356
	var motif = /^GROUPE/;
-
 
357
	if (motif.test(id)) {
-
 
358
		groupe = true;
-
 
359
	}
-
 
360
	return groupe;
-
 
361
}
-
 
362
 
-
 
363
function etreMarqueurCommune(id) {
-
 
364
	var commune = false;
-
 
365
	var motif = /^COMMUNE:/;
-
 
366
	if (motif.test(id)) {
-
 
367
		commune = true;
-
 
368
	}
-
 
369
	return commune;
-
 
370
}
-
 
371
 
-
 
372
function etreMarqueurStation(id) {
-
 
373
	var station = false;
-
 
374
	var motif = /^STATION:/;
-
 
375
	if (motif.test(id)) {
-
 
376
		station = true;
-
 
377
	}
-
 
378
	return station;
-
 
379
}
-
 
380
 
-
 
381
function deplacerCarteSurPointClique() {
-
 
382
	map.panTo(pointClique.position);
-
 
383
}
-
 
384
 
-
 
385
function executerMarkerClusterer(points, bounds) {
-
 
386
	if (markerClusterer) {
-
 
387
		markerClusterer.clearMarkers();
-
 
388
	}
-
 
389
	markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
-
 
390
	map.fitBounds(bounds);
-
 
391
}
-
 
392
 
-
 
393
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
394
// INFO BULLE
-
 
395
var infoBulleOuverte = false;
-
 
396
function initialiserInfoBulle() {
-
 
397
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
-
 
398
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
-
 
399
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
-
 
400
}
-
 
401
 
-
 
402
function surFermetureInfoBulle() {
-
 
403
	infoBulleOuverte = false;
-
 
404
	programmerRafraichissementCarte();
-
 
405
}
-
 
406
 
-
 
407
function centrerInfoBulle() {
-
 
408
	var limites = map.getBounds();
-
 
409
	var centre = limites.getCenter();
-
 
410
	var nordEst = limites.getNorthEast();
-
 
411
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
-
 
412
	map.panTo(centreSudLatLng);
-
 
413
}
-
 
414
 
-
 
415
function afficherInfoBulle() {
-
 
416
	var obsHtml = $("#tpl-obs").html();
-
 
417
	var largeur = definirLargeurInfoBulle();
-
 
418
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
-
 
419
	infoBulle.setContent(obsHtml);
-
 
420
	chargerObs(0, 0);
-
 
421
	infoBulleOuverte = true;
-
 
422
}
-
 
423
 
-
 
424
function definirLargeurInfoBulle() {
-
 
425
	var largeurViewPort = $(window).width();
-
 
426
	var lageurInfoBulle = null;
-
 
427
	if (largeurViewPort < 800) {
-
 
428
		largeurInfoBulle = 400;
-
 
429
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
-
 
430
		largeurInfoBulle = 500;
-
 
431
	} else if (largeurViewPort >= 1200) {
-
 
432
		largeurInfoBulle = 600;
-
 
433
	}
-
 
434
	return largeurInfoBulle;
-
 
435
}
-
 
436
 
-
 
437
function afficherMessageChargement(element) {
-
 
438
	if ($('#chargement').get() == '') {
-
 
439
		$('#tpl-chargement').tmpl().appendTo(element);
-
 
440
	}
-
 
441
}
-
 
442
 
-
 
443
function afficherMessageChargementTitreInfoBulle() {
-
 
444
	$("#obs-station-titre").text("Chargement des observations");	
-
 
445
}
-
 
446
 
-
 
447
function supprimerMessageChargement() {
-
 
448
	$('#chargement').remove();
-
 
449
}
-
 
450
 
-
 
451
function chargerObs(depart, total) {
-
 
452
	if (depart == 0 || depart < total) {
-
 
453
		var limite = 300;
-
 
454
		if (depart == 0) {
-
 
455
			viderTableauObs();
-
 
456
		}
-
 
457
		
-
 
458
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
-
 
459
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
-
 
460
		if (pointClique.stationInfos.type_emplacement == 'communes') {
-
 
461
			urlObs = urlObs.replace(/commune=%2A/g, 'commune='+pointClique.stationInfos.nom);
-
 
462
		}
-
 
463
		urlObs = urlObs.replace(/\{nt\}/g, nt);
-
 
464
		urlObs = urlObs.replace(/\{start\}/g, depart);
-
 
465
		
-
 
466
		$.getJSON(urlObs, function(observations){
-
 
467
			surRetourChargementObs(observations, depart, total);
-
 
468
			chargerObs(depart+limite, observations.total);
-
 
469
		});
-
 
470
	}
-
 
471
}
-
 
472
 
-
 
473
function viderTableauObs() {
-
 
474
	obsStation = new Array();	
-
 
475
	surClicPagePagination(0, null);
-
 
476
}
-
 
477
 
-
 
478
function surRetourChargementObs(observations, depart, total) {
-
 
479
	obsStation = obsStation.concat(observations.observations);
-
 
480
	if (depart == 0) {
-
 
481
		actualiserInfosStation(observations);
-
 
482
		creerTitreInfoBulle();
-
 
483
		surClicPagePagination(0, null);	
-
 
484
	}
-
 
485
	
-
 
486
	afficherPagination();
-
 
487
	actualiserPagineur();
-
 
488
	selectionnerOnglet("#obs-vue-"+pagineur.format);
-
 
489
}
-
 
490
 
-
 
491
function actualiserInfosStation(infos) {
-
 
492
	pointClique.stationInfos.commune = infos.commune;
-
 
493
	pointClique.stationInfos.obsNbre = infos.total;
-
 
494
}
-
 
495
 
-
 
496
function creerTitreInfoBulle() {
-
 
497
	$("#obs-total").text(station.obsNbre);
-
 
498
	$("#obs-commune").text(station.commune);
-
 
499
	var titre = '';
-
 
500
	titre += pointClique.stationInfos.obsNbre+' observation';
-
 
501
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
-
 
502
	titre += ' pour ';
-
 
503
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
-
 
504
		nomStation = 'la commune : ';
-
 
505
	} else {
-
 
506
		nomStation = 'la station : ';
-
 
507
	}
-
 
508
	titre += pointClique.stationInfos.nom;
-
 
509
	$("#obs-station-titre").text(titre);	
-
 
510
}
-
 
511
 
-
 
512
function actualiserPagineur() {
-
 
513
	pagineur.stationId = pointClique.stationInfos.id;
-
 
514
	pagineur.total = pointClique.stationInfos.obsNbre;
-
 
515
	if (pagineur.total > 4) {
-
 
516
		pagineur.format = 'tableau';
-
 
517
	} else {
-
 
518
		pagineur.format = 'liste';
-
 
519
	}
-
 
520
}
-
 
521
 
-
 
522
function afficherPagination(observations) {
-
 
523
	$(".navigation").pagination(pagineur.total, {
-
 
524
		items_per_page:pagineur.limite,
-
 
525
		callback:surClicPagePagination,
-
 
526
		next_text:'Suivant',
-
 
527
		prev_text:'Précédent',
-
 
528
		prev_show_always:false,
-
 
529
		num_edge_entries:1,
-
 
530
		num_display_entries:4,
-
 
531
		load_first_page:true
-
 
532
	});
-
 
533
}
-
 
534
 
-
 
535
function surClicPagePagination(pageIndex, paginationConteneur) {
-
 
536
	var index = pageIndex * pagineur.limite;
-
 
537
	var indexMax = index + pagineur.limite;
-
 
538
	pagineur.depart = index;
-
 
539
	obsPage = new Array();
-
 
540
    for(index; index < indexMax; index++) {
-
 
541
    	obsPage.push(obsStation[index]);
-
 
542
    }
-
 
543
    
-
 
544
    supprimerMessageChargement();
-
 
545
    mettreAJourObservations();
-
 
546
	return false;
-
 
547
}
-
 
548
 
-
 
549
function mettreAJourObservations() {
-
 
550
	$("#obs-"+pagineur.format+"-lignes").empty();
-
 
551
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
-
 
552
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
-
 
553
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
-
 
554
	
-
 
555
	// Actualisation de Fancybox
-
 
556
	ajouterFomulaireContact("a.contact");
-
 
557
	if (pagineur.format == 'liste') {
-
 
558
		ajouterGaleriePhoto("a.cel-img");
-
 
559
	}
-
 
560
}
-
 
561
 
-
 
562
function initialiserContenuInfoBulle() {
-
 
563
	afficherMessageChargement('#observations');
-
 
564
	cacherContenuOnglets();
-
 
565
	afficherOnglets();
-
 
566
	ajouterTableauTriable("#obs-tableau");
-
 
567
	afficherTextStationId();
-
 
568
	corrigerLargeurInfoWindow();
-
 
569
}
-
 
570
 
-
 
571
function cacherContenuOnglets() {
-
 
572
	$("#obs-vue-tableau").css("display", "none");
-
 
573
	$("#obs-vue-liste").css("display", "none");
-
 
574
}
-
 
575
 
-
 
576
function afficherOnglets() {
-
 
577
	var $tabs = $('#obs').tabs();
-
 
578
	$('#obs').bind('tabsselect', function(event, ui) {
-
 
579
		if (ui.panel.id == 'obs-vue-tableau') {
-
 
580
			surClicAffichageTableau();
-
 
581
		} else if (ui.panel.id == 'obs-vue-liste') {
-
 
582
			surClicAffichageListe();
-
 
583
		}
-
 
584
	});
-
 
585
	if (pointClique.stationInfos.nbre > 4) {
-
 
586
		$tabs.tabs('select', "#obs-vue-tableau");
-
 
587
	} else {
-
 
588
		$tabs.tabs('select', "#obs-vue-liste");
-
 
589
	}
-
 
590
	
-
 
591
}
-
 
592
 
-
 
593
function selectionnerOnglet(onglet) {
-
 
594
	$(onglet).css('display', 'block');
-
 
595
	$('#obs').tabs('select', onglet);
-
 
596
}
-
 
597
 
-
 
598
function afficherTextStationId() {
-
 
599
	$('#obs-station-id').text(pointClique.stationInfos.id);
-
 
600
}
-
 
601
 
-
 
602
function corrigerLargeurInfoWindow() {
-
 
603
	$("#info-bulle").width($("#info-bulle").width() - 17);
-
 
604
}
-
 
605
 
-
 
606
function surClicAffichageTableau(event) {
-
 
607
	pagineur.format = 'tableau';
-
 
608
	mettreAJourObservations();
-
 
609
	mettreAJourTableauTriable("#obs-tableau");
-
 
610
}
-
 
611
 
-
 
612
function surClicAffichageListe(event) {
-
 
613
	pagineur.format = 'liste';
-
 
614
	mettreAJourObservations();
-
 
615
	ajouterGaleriePhoto("a.cel-img");
-
 
616
}
-
 
617
 
-
 
618
function ajouterTableauTriable(element) {
-
 
619
	// add parser through the tablesorter addParser method 
-
 
620
	$.tablesorter.addParser({ 
-
 
621
		// Définition d'un id unique pour ce parsseur 
-
 
622
		id: 'date_cel', 
-
 
623
		is: function(s) { 
-
 
624
			// doit retourner false si le parsseur n'est pas autodétecté
-
 
625
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
-
 
626
		}, 
-
 
627
		format: function(date) { 
-
 
628
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
-
 
629
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
-
 
630
			// Remplace la date par un nombre de millisecondes pour trier numériquement
-
 
631
			return $.tablesorter.formatFloat(new Date(date).getTime());
-
 
632
		}, 
-
 
633
		// set type, either numeric or text 
-
 
634
		type: 'numeric' 
-
 
635
	});
-
 
636
	$(element).tablesorter({ 
-
 
637
        headers: { 
-
 
638
			1: { 
-
 
639
            	sorter:'date_cel' 
-
 
640
        	} 
-
 
641
    	} 
-
 
642
	});
-
 
643
}
-
 
644
 
-
 
645
function mettreAJourTableauTriable(element) {
-
 
646
	$(element).trigger('update');
-
 
647
}
-
 
648
 
-
 
649
function ajouterGaleriePhoto(element) {
-
 
650
	$(element).fancybox({
-
 
651
		transitionIn:'elastic',
-
 
652
		transitionOut:'elastic',
-
 
653
		speedIn	:600, 
-
 
654
		speedOut:200,
-
 
655
		overlayShow:true,
-
 
656
		titleShow:true,
-
 
657
		titlePosition:'inside',
-
 
658
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
-
 
659
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
-
 
660
			motif.exec(titre);
-
 
661
			var id = RegExp.$1;
-
 
662
			var info = $('#cel-info-'+id).clone().html();
-
 
663
			var tpl = 
-
 
664
				'<div class="cel-legende">'+
-
 
665
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
-
 
666
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
-
 
667
				'<\/div>';
-
 
668
			return tpl;
-
 
669
		}
-
 
670
	}).live('click', function(e) {
-
 
671
		if (e.stopPropagation) {
-
 
672
			e.stopPropagation();
-
 
673
		}
-
 
674
		return false;
-
 
675
	});
-
 
676
}
-
 
677
 
-
 
678
function ajouterFomulaireContact(element) {
-
 
679
	$(element).fancybox({
-
 
680
		transitionIn:'elastic',
-
 
681
		transitionOut:'elastic',
-
 
682
		speedIn	:600, 
-
 
683
		speedOut:200,
-
 
684
		scrolling: 'no',
-
 
685
		titleShow: false,
-
 
686
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
-
 
687
			var element = selectedArray[selectedIndex];
-
 
688
 
-
 
689
			var motif = / contributeur-([0-9]+)$/;
-
 
690
			motif.exec($(element).attr('class'));
-
 
691
			var id = RegExp.$1;
-
 
692
			//console.log('Destinataire id : '+id);
-
 
693
			$("#fc_destinataire_id").attr('value', id);
-
 
694
		
-
 
695
			var motif = / obs-([0-9]+) /;
-
 
696
			motif.exec($(element).attr('class'));
-
 
697
			var id = RegExp.$1;
-
 
698
			//console.log('Obs id : '+id);
-
 
699
			chargerInfoObsPourMessage(id);
-
 
700
		},
-
 
701
		onCleanup: function() {
-
 
702
			//console.log('Avant fermeture fancybox');
-
 
703
			$("#fc_destinataire_id").attr('value', '');
-
 
704
			$("#fc_sujet").attr('value', '');
-
 
705
			$("#fc_message").text('');
-
 
706
		},
-
 
707
		onClosed: function(e) {
-
 
708
			//console.log('Fermeture fancybox');
-
 
709
			if (e.stopPropagation) {
-
 
710
				e.stopPropagation();
-
 
711
			}
-
 
712
			return false;
-
 
713
		}
-
 
714
	});
-
 
715
}
-
 
716
 
-
 
717
function chargerInfoObsPourMessage(idObs) {
-
 
718
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
-
 
719
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
-
 
720
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
-
 
721
	var sujet = "Observation #"+idObs+" de "+nomSci;
-
 
722
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
-
 
723
	$("#fc_sujet").attr('value', sujet);
-
 
724
	$("#fc_message").text(message);
-
 
725
}
-
 
726
 
-
 
727
function initialiserFormulaireContact() {
-
 
728
	//console.log('Initialisation du form contact');
-
 
729
	$("#form-contact").validate({
-
 
730
		rules: {
-
 
731
			fc_sujet : "required",
-
 
732
			fc_message : "required",
-
 
733
			fc_utilisateur_courriel : {
-
 
734
				required : true,
-
 
735
				email : true}
-
 
736
		}
-
 
737
	});
-
 
738
	$("#form-contact").bind("submit", envoyerCourriel);
-
 
739
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
-
 
740
	
-
 
741
}
-
 
742
 
-
 
743
function envoyerCourriel() {
-
 
744
	//console.log('Formulaire soumis');
-
 
745
	if ($("#form-contact").valid()) {
-
 
746
		//console.log('Formulaire valide');
-
 
747
		//$.fancybox.showActivity();
-
 
748
		var destinataireId = $("#fc_destinataire_id").attr('value');
-
 
749
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
-
 
750
		var erreurMsg = "";
-
 
751
		var donnees = new Array();
-
 
752
		$.each($(this).serializeArray(), function (index, champ) {
-
 
753
			var cle = champ.name;
-
 
754
			cle = cle.replace(/^fc_/, '');
-
 
755
			
-
 
756
			if (cle == 'sujet') {
-
 
757
				champ.value += " - Carnet en ligne - Tela Botanica";
-
 
758
			}
-
 
759
			if (cle == 'message') {
-
 
760
				champ.value += "\n--\n"+
-
 
761
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
-
 
762
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
-
 
763
					"http://www.tela-botanica.org/widget:cel:carto";
-
 
764
			}
-
 
765
			
-
 
766
			donnees[index] = {'name':cle,'value':champ.value};
-
 
767
		});
-
 
768
		$.ajax({
-
 
769
			type : "POST",
-
 
770
			cache : false,
-
 
771
			url : urlMessage,
-
 
772
			data : donnees,
-
 
773
			beforeSend : function() {
-
 
774
				$(".msg").remove();
-
 
775
			},
-
 
776
			success : function(data) {
-
 
777
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
-
 
778
			},
-
 
779
			error : function(jqXHR, textStatus, errorThrown) {
-
 
780
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
781
				reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
782
				if (reponse != null) {
-
 
783
					$.each(reponse, function (cle, valeur) {
-
 
784
						erreurMsg += valeur + "\n";
-
 
785
					});
-
 
786
				}				
-
 
787
			},
-
 
788
			complete : function(jqXHR, textStatus) {
-
 
789
				var debugMsg = '';
-
 
790
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
791
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
792
					if (debugInfos != null) {
-
 
793
						$.each(debugInfos, function (cle, valeur) {
-
 
794
							debugMsg += valeur + "\n";
-
 
795
						});
-
 
796
					}
-
 
797
				}
-
 
798
				if (erreurMsg != '') {
-
 
799
					$("#fc-zone-dialogue").append('<p class="msg">'+
-
 
800
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
-
 
801
							'Vous pouvez signaler le disfonctionnement à <a href="'+
-
 
802
							'mailto:cel@tela-botanica.org'+'?'+
-
 
803
							'subject=Disfonctionnement du widget carto'+
-
 
804
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
-
 
805
							'">cel@tela-botanica.org</a>.'+
-
 
806
							'</p>');
-
 
807
				}
-
 
808
				if (DEBUG) {
-
 
809
					console.log('Débogage : '+debugMsg);
-
 
810
				}
-
 
811
				//console.log('Débogage : '+debugMsg);
-
 
812
				//console.log('Erreur : '+erreurMsg);
-
 
813
			}
-
 
814
		});
-
 
815
	}
-
 
816
	return false;
-
 
817
}
-
 
818
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
819
// PANNEAU LATÉRAL
-
 
820
 
-
 
821
function initialiserAffichagePanneauLateral() {
-
 
822
	$('#panneau-lateral').height($(window).height() - 35);
-
 
823
	
-
 
824
	if (nt == '*') {
-
 
825
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
-
 
826
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
-
 
827
	}
-
 
828
	chargerTaxons(0, 0);
-
 
829
}
-
 
830
 
-
 
831
function chargerTaxons(depart, total) {
-
 
832
	if (depart == 0 || depart < total) {
-
 
833
		var limite = 7000;
-
 
834
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
-
 
835
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
-
 
836
		urlTax = urlTax.replace(/\{start\}/g, depart);
-
 
837
		$.getJSON(urlTax, function(infos) {
-
 
838
			taxonsCarte = taxonsCarte.concat(infos.taxons);
-
 
839
			//console.log("Nbre taxons :"+taxonsCarte.length);
-
 
840
			chargerTaxons(depart+limite, infos.total);
-
 
841
		});
-
 
842
	} else {
-
 
843
		if (nt == '*') {
-
 
844
			afficherTaxons();
-
 
845
		}
-
 
846
		afficherTitreCarte();
-
 
847
	}
-
 
848
}
-
 
849
 
-
 
850
function afficherTaxons() {
-
 
851
	$(".plantes-nbre").text(taxonsCarte.length);
-
 
852
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
-
 
853
	$('.taxon').live('click', filtrerParTaxon);
-
 
854
}
-
 
855
 
-
 
856
 
-
 
857
function afficherPanneauLateral() {
-
 
858
	$('#panneau-lateral').width(300);
-
 
859
	$('#pl-contenu').css('display', 'block');
-
 
860
	$('#pl-ouverture').css('display', 'none');
-
 
861
	$('#pl-fermeture').css('display', 'block');
-
 
862
	$('#carte').css('left', '300px');
-
 
863
 
-
 
864
	google.maps.event.trigger(map, 'resize');
-
 
865
};
-
 
866
 
-
 
867
function cacherPanneauLateral() {
-
 
868
	$('#panneau-lateral').width(24);
-
 
869
	$('#pl-contenu').css('display', 'none');
-
 
870
	$('#pl-ouverture').css('display', 'block');
-
 
871
	$('#pl-fermeture').css('display', 'none');
-
 
872
	$('#carte').css('left', '24px');
-
 
873
	
-
 
874
	google.maps.event.trigger(map, 'resize');
-
 
875
};
-
 
876
 
-
 
877
function filtrerParTaxon() {
-
 
878
	var ntAFiltrer = $('.nt', this).text();
-
 
879
	infoBulle.close();
-
 
880
	var zoom = map.getZoom();
-
 
881
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
-
 
882
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
-
 
883
	
-
 
884
	$('#taxon-'+nt).removeClass('taxon-actif');
-
 
885
	if (nt == ntAFiltrer) {
-
 
886
		nt = '*';
-
 
887
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
-
 
888
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
-
 
889
	} else {
-
 
890
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
-
 
891
		url = stationsUrl;
-
 
892
		url += '&zoom='+zoom+
-
 
893
			'&ne='+NELatLng+
-
 
894
			'&sw='+SWLatLng;
-
 
895
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
-
 
896
			stations = stationsFiltrees;
-
 
897
			nt = ntAFiltrer;
-
 
898
			$('#taxon-'+nt).addClass('taxon-actif');
-
 
899
			rafraichirMarqueurs(stations);
-
 
900
		});
-
 
901
	}
-
 
902
};
-
 
903
 
-
 
904
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
905
// FONCTIONS UTILITAIRES
-
 
906
 
-
 
907
function ouvrirPopUp(element, nomPopUp, event) {
-
 
908
	var options = 
-
 
909
		'width=650,'+
-
 
910
		'height=600,'+
-
 
911
		'scrollbars=yes,'+
-
 
912
		'directories=no,'+
-
 
913
		'location=no,'+
-
 
914
		'menubar=no,'+
-
 
915
		'status=no,'+
-
 
916
		'toolbar=no';
-
 
917
	var popUp = window.open(element.href, nomPopUp, options);
-
 
918
	if (window.focus) {
-
 
919
		popUp.focus();
-
 
920
	}
-
 
921
	return arreter(event);
-
 
922
};
-
 
923
 
-
 
924
function ouvrirNouvelleFenetre(element, event) {
-
 
925
	window.open(element.href);
-
 
926
	return arreter(event);
-
 
927
}
-
 
928
 
-
 
929
function arreter(event) {
-
 
930
	if (event.stopPropagation) {
-
 
931
		event.stopPropagation();
-
 
932
	} else if (window.event) {
-
 
933
		window.event.cancelBubble = true;
-
 
934
	}
-
 
935
	if (event.preventDefault) {
-
 
936
		event.preventDefault();
-
 
937
	}
-
 
938
	event.returnValue = false;
-
 
939
	return false;
-
 
940
}
-
 
941
 
-
 
942
/**
-
 
943
 * +-------------------------------------+
-
 
944
 * Number.prototype.formaterNombre
-
 
945
 * +-------------------------------------+
-
 
946
 * Params (facultatifs):
-
 
947
 * - Int decimales: nombre de decimales (exemple: 2)
-
 
948
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
-
 
949
 * - String separateurMilliers: comme son nom l'indique
-
 
950
 * Returns:
-
 
951
 * - String chaine formatee
-
 
952
 * @author	::mastahbenus::
-
 
953
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
-
 
954
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
-
 
955
 */
-
 
956
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
-
 
957
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
-
 
958
	
-
 
959
	function is_int(nbre) {
-
 
960
		nbre = nbre.replace(',', '.');
-
 
961
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
-
 
962
	}
-
 
963
 
-
 
964
	if (decimales == undefined) {
-
 
965
		if (is_int(_sNombre)) {
-
 
966
			decimales = 0;
-
 
967
		} else {
-
 
968
			decimales = 2;
-
 
969
		}
-
 
970
	}
-
 
971
	if (signe == undefined) {
-
 
972
		if (is_int(_sNombre)) {
-
 
973
			signe = '';
-
 
974
		} else {
-
 
975
			signe = '.';
-
 
976
		}
-
 
977
	}
-
 
978
	if (separateurMilliers == undefined) {
-
 
979
		separateurMilliers = ' ';
-
 
980
	}
-
 
981
	
-
 
982
	function separeMilliers (sNombre) {
-
 
983
		var sRetour = "";
-
 
984
		while (sNombre.length % 3 != 0) {
-
 
985
			sNombre = "0"+sNombre;
-
 
986
		}
-
 
987
		for (i = 0; i < sNombre.length; i += 3) {
-
 
988
			if (i == sNombre.length-1) separateurMilliers = '';
-
 
989
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
-
 
990
		}
-
 
991
		while (sRetour.substr(0, 1) == "0") {
-
 
992
			sRetour = sRetour.substr(1);
-
 
993
		}
-
 
994
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
-
 
995
	}
-
 
996
	
-
 
997
	if (_sNombre.indexOf('.') == -1) {
-
 
998
		for (i = 0; i < decimales; i++) {
-
 
999
			_sDecimales += "0";
-
 
1000
		}
-
 
1001
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
-
 
1002
	} else {
-
 
1003
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
-
 
1004
		if (sDecimalesTmp.length > decimales) {
-
 
1005
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
-
 
1006
			var nDiv = 1;
-
 
1007
			for (i = 0; i < nDecimalesManquantes; i++) {
-
 
1008
				nDiv *= 10;
-
 
1009
			}
-
 
1010
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
-
 
1011
		}
-
 
1012
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
-
 
1013
	}
-
 
1014
	return _sRetour;
-
 
1015
}
-
 
1016
 
-
 
1017
function debug(objet) {
-
 
1018
	var msg = '';
-
 
1019
	if (objet != null) {
-
 
1020
		$.each(objet, function (cle, valeur) {
-
 
1021
			msg += cle+":"+valeur + "\n";
-
 
1022
		});
-
 
1023
	} else {
-
 
1024
		msg = "La variable vaut null.";
-
 
1025
	}
-
 
1026
	console.log(msg);
-
 
1027
}
-
 
1028
1
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
2
// PARAMÊTRES et CONSTANTES
-
 
3
// Mettre à true pour afficher les messages de débogage
-
 
4
var DEBUG = false; 
-
 
5
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
-
 
6
var pointsOrigine = null;
-
 
7
var boundsOrigine = null;
-
 
8
var markerClusterer = null;
-
 
9
var map = null;
-
 
10
var infoBulle = new google.maps.InfoWindow();
-
 
11
var pointClique = null;
-
 
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
-
 
13
var carteOptions = {
-
 
14
	zoom: 6,
-
 
15
	mapTypeId: google.maps.MapTypeId.ROADMAP,
-
 
16
	mapTypeControlOptions: {
-
 
17
		mapTypeIds: ['OSM', 
-
 
18
		             google.maps.MapTypeId.ROADMAP, 
-
 
19
		             google.maps.MapTypeId.HYBRID, 
-
 
20
		             google.maps.MapTypeId.SATELLITE, 
-
 
21
		             google.maps.MapTypeId.TERRAIN]
-
 
22
	}
-
 
23
};			
-
 
24
var ctaLayer = null;
-
 
25
var osmMapType = new google.maps.ImageMapType({
-
 
26
	getTileUrl: function(coord, zoom) {
-
 
27
		return "http://tile.openstreetmap.org/" +
-
 
28
		zoom + "/" + coord.x + "/" + coord.y + ".png";
-
 
29
	},
-
 
30
	tileSize: new google.maps.Size(256, 256),
-
 
31
	isPng: true,
-
 
32
	alt: "OpenStreetMap",
-
 
33
	name: "OSM",
-
 
34
	maxZoom: 19
-
 
35
});
-
 
36
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
-
 
37
var station = {'commune':'', 'obsNbre':0};
-
 
38
var obsStation = new Array();
-
 
39
var obsPage = new Array();
-
 
40
var taxonsCarte = new Array();
-
 
41
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
42
// INITIALISATION DU CODE
-
 
43
 
-
 
44
//Déclenchement d'actions quand JQuery et le document HTML sont OK
-
 
45
$(document).ready(function() {
-
 
46
	initialiserWidget();
-
 
47
});
-
 
48
 
-
 
49
function initialiserWidget() {
-
 
50
	afficherStats();
-
 
51
	definirTailleTitre();
-
 
52
	initialiserAffichageCarte();
-
 
53
	initialiserAffichagePanneauLateral();
-
 
54
	
-
 
55
	initialiserCarte();
-
 
56
	initialiserInfoBulle();
-
 
57
	initialiserFormulaireContact();
-
 
58
	chargerLimitesCommunales();
-
 
59
	rafraichirCarte();
-
 
60
}
-
 
61
 
-
 
62
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
63
// AFFICHAGE GÉNÉRAL
-
 
64
 
-
 
65
function afficherStats() {
-
 
66
	// Ajout du nombre de communes où des observations ont eu lieu
-
 
67
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
-
 
68
	// Ajout du nombre d'observations
-
 
69
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
-
 
70
}
-
 
71
 
-
 
72
function definirTailleTitre() {
-
 
73
	var largeurViewPort = $(window).width();
-
 
74
	var taille = null;
-
 
75
	if (largeurViewPort < 400) {
-
 
76
		taille = '0.8';
-
 
77
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
-
 
78
		taille = '1.0';
-
 
79
	} else if (largeurViewPort >= 800) {
-
 
80
		taille = '1.6';
-
 
81
	}
-
 
82
	$("#carte-titre").css('font-size', taille+'em');
-
 
83
}
-
 
84
 
-
 
85
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
86
// CARTE
-
 
87
 
-
 
88
function initialiserAffichageCarte() {
-
 
89
	$('#carte').height($(window).height() - 35);
-
 
90
	$('#carte').width($(window).width() - 24);
-
 
91
	
-
 
92
	if (nt != '*') {
-
 
93
		$('#carte').css('left', 0);
-
 
94
	}
-
 
95
}
-
 
96
 
-
 
97
function initialiserCarte() {
-
 
98
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
-
 
99
	// Ajout de la couche OSM à la carte
-
 
100
	map.mapTypes.set('OSM', osmMapType);
-
 
101
}
-
 
102
 
-
 
103
 
-
 
104
function chargerLimitesCommunales() {
-
 
105
	if (urlsLimitesCommunales != null) {
-
 
106
		for (urlId in urlsLimitesCommunales) { 
-
 
107
			var url = urlsLimitesCommunales[urlId];
-
 
108
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
-
 
109
			ctaLayer.setMap(map);
-
 
110
		}
-
 
111
	}
-
 
112
}
-
 
113
 
-
 
114
function rafraichirCarte() {
-
 
115
	var points = [];
-
 
116
	var bounds = new google.maps.LatLngBounds();
-
 
117
	for (var i = 0; i < stations.stats.communes; ++i) {
-
 
118
		var maLatLng = new google.maps.LatLng(stations.points[i].latitude, stations.points[i].longitude);
-
 
119
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
-
 
120
		var point = new google.maps.Marker({
-
 
121
			position: maLatLng,
-
 
122
			map: map,
-
 
123
			icon: pointImage,
-
 
124
			stationId: stations.points[i].id
-
 
125
		});
-
 
126
 
-
 
127
		bounds.extend(maLatLng);
-
 
128
		
-
 
129
		google.maps.event.addListener(point, 'click', function() {
-
 
130
			pointClique =  this;
-
 
131
			infoBulle.open(map, this);
-
 
132
			
-
 
133
			var limites = map.getBounds();
-
 
134
			var centre = limites.getCenter();
-
 
135
			var nordEst = limites.getNorthEast();
-
 
136
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
-
 
137
			map.panTo(centreSudLatLng);
-
 
138
			
-
 
139
			afficherInfoBulle();
-
 
140
			chargerObs(0, 0);
-
 
141
		});
-
 
142
		
-
 
143
		points.push(point);
-
 
144
	}
-
 
145
 
-
 
146
	if (pointsOrigine == null && boundsOrigine == null) {
-
 
147
		pointsOrigine = points;
-
 
148
		boundsOrigine = bounds;
-
 
149
	}
-
 
150
	
-
 
151
	executerMarkerClusterer(points, bounds);
-
 
152
}
-
 
153
 
-
 
154
function deplacerCartePointClique() {
-
 
155
	map.panTo(pointClique.position);
-
 
156
}
-
 
157
 
-
 
158
function executerMarkerClusterer(points, bounds) {
-
 
159
	if (markerClusterer) {
-
 
160
		markerClusterer.clearMarkers();
-
 
161
	}
-
 
162
	markerClusterer = new MarkerClusterer(map, points);
-
 
163
	map.fitBounds(bounds);
-
 
164
}
-
 
165
 
-
 
166
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
167
// INFO BULLE
-
 
168
 
-
 
169
function initialiserInfoBulle() {
-
 
170
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
-
 
171
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
-
 
172
}
-
 
173
 
-
 
174
function afficherInfoBulle() {
-
 
175
	var obsHtml = $("#tpl-obs").html();
-
 
176
	var largeur = definirLargeurInfoBulle();
-
 
177
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
-
 
178
	infoBulle.setContent(obsHtml);
-
 
179
}
-
 
180
 
-
 
181
function definirLargeurInfoBulle() {
-
 
182
	var largeurViewPort = $(window).width();
-
 
183
	var lageurInfoBulle = null;
-
 
184
	if (largeurViewPort < 800) {
-
 
185
		largeurInfoBulle = 400;
-
 
186
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
-
 
187
		largeurInfoBulle = 500;
-
 
188
	} else if (largeurViewPort >= 1200) {
-
 
189
		largeurInfoBulle = 600;
-
 
190
	}
-
 
191
	return largeurInfoBulle;
-
 
192
}
-
 
193
 
-
 
194
function afficherMessageChargement(element) {
-
 
195
	if ($('#chargement').get() == '') {
-
 
196
		$('#tpl-chargement').tmpl().appendTo(element);
-
 
197
	}
-
 
198
}
-
 
199
 
-
 
200
function supprimerMessageChargement() {
-
 
201
	$('#chargement').remove();
-
 
202
}
-
 
203
 
-
 
204
function chargerObs(depart, total) {
-
 
205
	if (depart == 0 || depart < total) {
-
 
206
		var limite = 300;
-
 
207
		if (depart == 0) {
-
 
208
			obsStation = new Array();
-
 
209
		}
-
 
210
		//console.log("Chargement de "+depart+" à "+(depart+limite));
-
 
211
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
-
 
212
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
-
 
213
		urlObs = urlObs.replace(/\{nt\}/g, nt);
-
 
214
		urlObs = urlObs.replace(/\{start\}/g, depart);
-
 
215
		
-
 
216
		$.getJSON(urlObs, function(observations){
-
 
217
			obsStation = obsStation.concat(observations.observations);
-
 
218
			if (depart == 0) {
-
 
219
				actualiserInfosStation(observations);
-
 
220
				actualiserPagineur();
-
 
221
				creerTitreInfoBulle();
-
 
222
			}
-
 
223
			//console.log("Chargement ok");
-
 
224
			chargerObs(depart+limite, station.obsNbre);
-
 
225
		});
-
 
226
	} else {
-
 
227
		if (pagineur.limite < total) {
-
 
228
			afficherPagination();
-
 
229
		} else {
-
 
230
			surClicPagePagination(0, null);
-
 
231
			selectionnerOnglet("#obs-vue-"+pagineur.format);
-
 
232
		}
-
 
233
	}
-
 
234
}
-
 
235
 
-
 
236
function actualiserInfosStation(infos) {
-
 
237
	station.commune = infos.commune;
-
 
238
	station.obsNbre = infos.total;
-
 
239
}
-
 
240
 
-
 
241
function actualiserPagineur() {
-
 
242
	pagineur.stationId = pointClique.stationId;
-
 
243
	pagineur.total = station.obsNbre;
-
 
244
	//console.log("Total pagineur: "+pagineur.total);
-
 
245
	if (pagineur.total > 4) {
-
 
246
		pagineur.format = 'tableau';
-
 
247
	} else {
-
 
248
		pagineur.format = 'liste';
-
 
249
	}
-
 
250
}
-
 
251
 
-
 
252
function afficherPagination(observations) {
-
 
253
	$(".navigation").pagination(pagineur.total, {
-
 
254
		items_per_page:pagineur.limite,
-
 
255
		callback:surClicPagePagination,
-
 
256
		next_text:'Suivant',
-
 
257
		prev_text:'Précédent',
-
 
258
		prev_show_always:false,
-
 
259
		num_edge_entries:1,
-
 
260
		num_display_entries:4,
-
 
261
		load_first_page:true
-
 
262
	});
-
 
263
}
-
 
264
 
-
 
265
function surClicPagePagination(pageIndex, paginationConteneur) {
-
 
266
	var index = pageIndex * pagineur.limite;
-
 
267
	var indexMax = index + pagineur.limite;
-
 
268
	pagineur.depart = index;
-
 
269
	obsPage = new Array();
-
 
270
    for(index; index < indexMax; index++) {
-
 
271
    	obsPage.push(obsStation[index]);
-
 
272
    }
-
 
273
    
-
 
274
    supprimerMessageChargement();
-
 
275
    mettreAJourObservations();
-
 
276
	return false;
-
 
277
}
-
 
278
 
-
 
279
function mettreAJourObservations() {
-
 
280
	$("#obs-"+pagineur.format+"-lignes").empty();
-
 
281
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
-
 
282
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
-
 
283
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
-
 
284
	
-
 
285
	// Actualisation de Fancybox
-
 
286
	ajouterFomulaireContact("a.contact");
-
 
287
	if (pagineur.format == 'liste') {
-
 
288
		ajouterGaleriePhoto("a.cel-img");
-
 
289
	}
-
 
290
}
-
 
291
 
-
 
292
function creerTitreInfoBulle() {
-
 
293
	$("#obs-total").text(station.obsNbre);
-
 
294
	$("#obs-commune").text(station.commune);	
-
 
295
}
-
 
296
 
-
 
297
function initialiserContenuInfoBulle() {
-
 
298
	afficherOnglets();
-
 
299
	afficherMessageChargement('#observations');
-
 
300
	ajouterTableauTriable("#obs-tableau");
-
 
301
	afficherTextStationId();
-
 
302
	corrigerLargeurInfoWindow();
-
 
303
}
-
 
304
 
-
 
305
function afficherOnglets() {
-
 
306
	var $tabs = $('#obs').tabs();
-
 
307
	$('#obs').bind('tabsselect', function(event, ui) {
-
 
308
		if (ui.panel.id == 'obs-vue-tableau') {
-
 
309
			surClicAffichageTableau();
-
 
310
		} else if (ui.panel.id == 'obs-vue-liste') {
-
 
311
			surClicAffichageListe();
-
 
312
		}
-
 
313
	});
-
 
314
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
-
 
315
}
-
 
316
 
-
 
317
function selectionnerOnglet(onglet) {
-
 
318
	$('#obs').tabs('select', onglet);
-
 
319
}
-
 
320
 
-
 
321
function afficherTextStationId() {
-
 
322
	$('#obs-station-id').text(pointClique.stationId);
-
 
323
}
-
 
324
 
-
 
325
function corrigerLargeurInfoWindow() {
-
 
326
	$("#info-bulle").width($("#info-bulle").width() - 17);
-
 
327
}
-
 
328
 
-
 
329
function surClicAffichageTableau(event) {
-
 
330
	//console.log('tableau');
-
 
331
	pagineur.format = 'tableau';
-
 
332
	mettreAJourObservations();
-
 
333
	mettreAJourTableauTriable("#obs-tableau");
-
 
334
}
-
 
335
 
-
 
336
function surClicAffichageListe(event) {
-
 
337
	//console.log('liste');
-
 
338
	pagineur.format = 'liste';
-
 
339
	mettreAJourObservations();
-
 
340
	ajouterGaleriePhoto("a.cel-img");
-
 
341
}
-
 
342
 
-
 
343
function ajouterTableauTriable(element) {
-
 
344
	// add parser through the tablesorter addParser method 
-
 
345
	$.tablesorter.addParser({ 
-
 
346
		// Définition d'un id unique pour ce parsseur 
-
 
347
		id: 'date_cel', 
-
 
348
		is: function(s) { 
-
 
349
			// doit retourner false si le parsseur n'est pas autodétecté
-
 
350
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
-
 
351
		}, 
-
 
352
		format: function(date) { 
-
 
353
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
-
 
354
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
-
 
355
			// Remplace la date par un nombre de millisecondes pour trier numériquement
-
 
356
			return $.tablesorter.formatFloat(new Date(date).getTime());
-
 
357
		}, 
-
 
358
		// set type, either numeric or text 
-
 
359
		type: 'numeric' 
-
 
360
	});
-
 
361
	$(element).tablesorter({ 
-
 
362
        headers: { 
-
 
363
			1: { 
-
 
364
            	sorter:'date_cel' 
-
 
365
        	} 
-
 
366
    	} 
-
 
367
	});
-
 
368
}
-
 
369
 
-
 
370
function mettreAJourTableauTriable(element) {
-
 
371
	$(element).trigger('update');
-
 
372
}
-
 
373
 
-
 
374
function ajouterGaleriePhoto(element) {
-
 
375
	$(element).fancybox({
-
 
376
		transitionIn:'elastic',
-
 
377
		transitionOut:'elastic',
-
 
378
		speedIn	:600, 
-
 
379
		speedOut:200,
-
 
380
		overlayShow:true,
-
 
381
		titleShow:true,
-
 
382
		titlePosition:'inside',
-
 
383
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
-
 
384
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
-
 
385
			motif.exec(titre);
-
 
386
			var id = RegExp.$1;
-
 
387
			var info = $('#cel-info-'+id).clone().html();
-
 
388
			var tpl = 
-
 
389
				'<div class="cel-legende">'+
-
 
390
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
-
 
391
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
-
 
392
				'<\/div>';
-
 
393
			return tpl;
-
 
394
		}
-
 
395
		}).live('click', function(e) {
-
 
396
			if (e.stopPropagation) {
-
 
397
				e.stopPropagation();
-
 
398
			}
-
 
399
			return false;
-
 
400
		});
-
 
401
}
-
 
402
 
-
 
403
function ajouterFomulaireContact(element) {
-
 
404
	$(element).fancybox({
-
 
405
		transitionIn:'elastic',
-
 
406
		transitionOut:'elastic',
-
 
407
		speedIn	:600, 
-
 
408
		speedOut:200,
-
 
409
		scrolling: 'no',
-
 
410
		titleShow: false,
-
 
411
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
-
 
412
			var element = selectedArray[selectedIndex];
-
 
413
 
-
 
414
			var motif = / contributeur-([0-9]+)$/;
-
 
415
			motif.exec($(element).attr('class'));
-
 
416
			var id = RegExp.$1;
-
 
417
			//console.log('Destinataire id : '+id);
-
 
418
			$("#fc_destinataire_id").attr('value', id);
-
 
419
		
-
 
420
			var motif = / obs-([0-9]+) /;
-
 
421
			motif.exec($(element).attr('class'));
-
 
422
			var id = RegExp.$1;
-
 
423
			//console.log('Obs id : '+id);
-
 
424
			chargerInfoObsPourMessage(id);
-
 
425
		},
-
 
426
		onCleanup: function() {
-
 
427
			//console.log('Avant fermeture fancybox');
-
 
428
			$("#fc_destinataire_id").attr('value', '');
-
 
429
			$("#fc_sujet").attr('value', '');
-
 
430
			$("#fc_message").text('');
-
 
431
		},
-
 
432
		onClosed: function(e) {
-
 
433
			//console.log('Fermeture fancybox');
-
 
434
			if (e.stopPropagation) {
-
 
435
				e.stopPropagation();
-
 
436
			}
-
 
437
			return false;
-
 
438
		}
-
 
439
	});
-
 
440
}
-
 
441
 
-
 
442
function chargerInfoObsPourMessage(idObs) {
-
 
443
	var nomSci = trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
-
 
444
	var date = trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
-
 
445
	var lieu = trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
-
 
446
	var sujet = "Observation #"+idObs+" de "+nomSci;
-
 
447
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
-
 
448
	$("#fc_sujet").attr('value', sujet);
-
 
449
	$("#fc_message").text(message);
-
 
450
}
-
 
451
 
-
 
452
function initialiserFormulaireContact() {
-
 
453
	//console.log('Initialisation du form contact');
-
 
454
	$("#form-contact").validate({
-
 
455
		rules: {
-
 
456
			fc_sujet : "required",
-
 
457
			fc_message : "required",
-
 
458
			fc_utilisateur_courriel : {
-
 
459
				required : true,
-
 
460
				email : true}
-
 
461
		}
-
 
462
	});
-
 
463
	$("#form-contact").bind("submit", envoyerCourriel);
-
 
464
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
-
 
465
	
-
 
466
}
-
 
467
 
-
 
468
function envoyerCourriel() {
-
 
469
	//console.log('Formulaire soumis');
-
 
470
	if ($("#form-contact").valid()) {
-
 
471
		//console.log('Formulaire valide');
-
 
472
		//$.fancybox.showActivity();
-
 
473
		var destinataireId = $("#fc_destinataire_id").attr('value');
-
 
474
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
-
 
475
		var erreurMsg = "";
-
 
476
		var donnees = new Array();
-
 
477
		$.each($(this).serializeArray(), function (index, champ) {
-
 
478
			var cle = champ.name;
-
 
479
			cle = cle.replace(/^fc_/, '');
-
 
480
			
-
 
481
			if (cle == 'sujet') {
-
 
482
				champ.value += " - Carnet en ligne - Tela Botanica";
-
 
483
			}
-
 
484
			if (cle == 'message') {
-
 
485
				champ.value += "\n--\n"+
-
 
486
					"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+
-
 
487
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
-
 
488
					"http://www.tela-botanica.org/widget:cel:carto";
-
 
489
			}
-
 
490
			
-
 
491
			donnees[index] = {'name':cle,'value':champ.value};
-
 
492
		});
-
 
493
		$.ajax({
-
 
494
			type : "POST",
-
 
495
			cache : false,
-
 
496
			url : urlMessage,
-
 
497
			data : donnees,
-
 
498
			beforeSend : function() {
-
 
499
				$(".msg").remove();
-
 
500
			},
-
 
501
			success : function(data) {
-
 
502
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
-
 
503
			},
-
 
504
			error : function(jqXHR, textStatus, errorThrown) {
-
 
505
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
506
				reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
507
				if (reponse != null) {
-
 
508
					$.each(reponse, function (cle, valeur) {
-
 
509
						erreurMsg += valeur + "\n";
-
 
510
					});
-
 
511
				}				
-
 
512
			},
-
 
513
			complete : function(jqXHR, textStatus) {
-
 
514
				var debugMsg = '';
-
 
515
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
516
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
517
					if (debugInfos != null) {
-
 
518
						$.each(debugInfos, function (cle, valeur) {
-
 
519
							debugMsg += valeur + "\n";
-
 
520
						});
-
 
521
					}
-
 
522
				}
-
 
523
				if (erreurMsg != '') {
-
 
524
					$("#fc-zone-dialogue").append('<p class="msg">'+
-
 
525
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
-
 
526
							'Vous pouvez signaler le disfonctionnement à <a href="'+
-
 
527
							'mailto:cel@tela-botanica.org'+'?'+
-
 
528
							'subject=Disfonctionnement du widget de Cartographie'+
-
 
529
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
-
 
530
							'">cel@tela-botanica.org</a>.'+
-
 
531
							'</p>');
-
 
532
				}
-
 
533
				if (DEBUG) {
-
 
534
					console.log('Débogage : '+debugMsg);
-
 
535
				}
-
 
536
				//console.log('Débogage : '+debugMsg);
-
 
537
				//console.log('Erreur : '+erreurMsg);
-
 
538
			}
-
 
539
		});
-
 
540
	}
-
 
541
	return false;
-
 
542
}
-
 
543
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
544
// PANNEAU LATÉRAL
-
 
545
 
-
 
546
function initialiserAffichagePanneauLateral() {
-
 
547
	$('#panneau-lateral').height($(window).height() - 35);
-
 
548
	
-
 
549
	if (nt == '*') {
-
 
550
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
-
 
551
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
-
 
552
	}
-
 
553
	chargerTaxons(0, 0);
-
 
554
}
-
 
555
 
-
 
556
function chargerTaxons(depart, total) {
-
 
557
	if (depart == 0 || depart < total) {
-
 
558
		var limite = 7000;
-
 
559
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
-
 
560
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
-
 
561
		urlTax = urlTax.replace(/\{start\}/g, depart);
-
 
562
		$.getJSON(urlTax, function(infos) {
-
 
563
			taxonsCarte = taxonsCarte.concat(infos.taxons);
-
 
564
			//console.log("Nbre taxons :"+taxonsCarte.length);
-
 
565
			chargerTaxons(depart+limite, infos.total);
-
 
566
		});
-
 
567
	} else {
-
 
568
		if (nt == '*') {
-
 
569
			afficherTaxons();
-
 
570
		} else {
-
 
571
			afficherNomPlante();
-
 
572
		}
-
 
573
	}
-
 
574
}
-
 
575
 
-
 
576
function afficherTaxons() {
-
 
577
	// Ajout du nombre de plantes au titre
-
 
578
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
-
 
579
	
-
 
580
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
-
 
581
	$('.taxon').live('click', filtrerParTaxon);
-
 
582
}
-
 
583
 
-
 
584
function afficherNomPlante() {
-
 
585
	if (nt != '*') {
-
 
586
		var taxon = taxonsCarte[0];
-
 
587
		$('.plante-titre').text('pour '+taxon.nom);
-
 
588
	}
-
 
589
}
-
 
590
 
-
 
591
function afficherPanneauLateral() {
-
 
592
	$('#panneau-lateral').width(300);
-
 
593
	$('#pl-contenu').css('display', 'block');
-
 
594
	$('#pl-ouverture').css('display', 'none');
-
 
595
	$('#pl-fermeture').css('display', 'block');
-
 
596
	$('#carte').css('left', '300px');
-
 
597
 
-
 
598
	google.maps.event.trigger(map, 'resize');
-
 
599
};
-
 
600
 
-
 
601
function cacherPanneauLateral() {
-
 
602
	$('#panneau-lateral').width(24);
-
 
603
	$('#pl-contenu').css('display', 'none');
-
 
604
	$('#pl-ouverture').css('display', 'block');
-
 
605
	$('#pl-fermeture').css('display', 'none');
-
 
606
	$('#carte').css('left', '24px');
-
 
607
	
-
 
608
	google.maps.event.trigger(map, 'resize');
-
 
609
};
-
 
610
 
-
 
611
function ouvrirPopUp(url, nom) {
-
 
612
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
-
 
613
};
-
 
614
 
-
 
615
function filtrerParTaxon() {
-
 
616
	var ntAFiltrer = $('.nt', this).text();
-
 
617
	infoBulle.close();
-
 
618
	$('#taxon-'+nt).removeClass('taxon-actif');
-
 
619
	if (nt == ntAFiltrer) {
-
 
620
		nt = '*';
-
 
621
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
-
 
622
	} else {
-
 
623
		var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+
-
 
624
			'&formatRetour=jsonP'+
-
 
625
			'&callback=?';
-
 
626
		$.getJSON(url, function (stationsFiltrees) {
-
 
627
			stations = stationsFiltrees;
-
 
628
			nt = ntAFiltrer;
-
 
629
			$('#taxon-'+nt).addClass('taxon-actif');
-
 
630
			rafraichirCarte();
-
 
631
		});
-
 
632
	}
-
 
633
};
-
 
634
 
-
 
635
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
636
// FONCTIONS UTILITAIRES
-
 
637
 
-
 
638
function arreter(event) {
-
 
639
	if (event.stopPropagation) {
-
 
640
		event.stopPropagation();
-
 
641
	} else if (window.event) {
-
 
642
		window.event.cancelBubble = true;
-
 
643
	}
-
 
644
	return false;
-
 
645
}
-
 
646
 
-
 
647
/**
-
 
648
 * +-------------------------------------+
-
 
649
 * Number.prototype.formaterNombre
-
 
650
 * +-------------------------------------+
-
 
651
 * Params (facultatifs):
-
 
652
 * - Int decimales: nombre de decimales (exemple: 2)
-
 
653
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
-
 
654
 * - String separateurMilliers: comme son nom l'indique
-
 
655
 * Returns:
-
 
656
 * - String chaine formatee
-
 
657
 * @author	::mastahbenus::
-
 
658
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
-
 
659
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
-
 
660
 */
-
 
661
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
-
 
662
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
-
 
663
	
-
 
664
	function is_int(nbre) {
-
 
665
		nbre = nbre.replace(',', '.');
-
 
666
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
-
 
667
	}
-
 
668
 
-
 
669
	if (decimales == undefined) {
-
 
670
		if (is_int(_sNombre)) {
-
 
671
			decimales = 0;
-
 
672
		} else {
-
 
673
			decimales = 2;
-
 
674
		}
-
 
675
	}
-
 
676
	if (signe == undefined) {
-
 
677
		if (is_int(_sNombre)) {
-
 
678
			signe = '';
-
 
679
		} else {
-
 
680
			signe = '.';
-
 
681
		}
-
 
682
	}
-
 
683
	if (separateurMilliers == undefined) {
-
 
684
		separateurMilliers = ' ';
-
 
685
	}
-
 
686
	
-
 
687
	function separeMilliers (sNombre) {
-
 
688
		var sRetour = "";
-
 
689
		while (sNombre.length % 3 != 0) {
-
 
690
			sNombre = "0"+sNombre;
-
 
691
		}
-
 
692
		for (i = 0; i < sNombre.length; i += 3) {
-
 
693
			if (i == sNombre.length-1) separateurMilliers = '';
-
 
694
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
-
 
695
		}
-
 
696
		while (sRetour.substr(0, 1) == "0") {
-
 
697
			sRetour = sRetour.substr(1);
-
 
698
		}
-
 
699
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
-
 
700
	}
-
 
701
	
-
 
702
	if (_sNombre.indexOf('.') == -1) {
-
 
703
		for (i = 0; i < decimales; i++) {
-
 
704
			_sDecimales += "0";
-
 
705
		}
-
 
706
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
-
 
707
	} else {
-
 
708
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
-
 
709
		if (sDecimalesTmp.length > decimales) {
-
 
710
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
-
 
711
			var nDiv = 1;
-
 
712
			for (i = 0; i < nDecimalesManquantes; i++) {
-
 
713
				nDiv *= 10;
-
 
714
			}
-
 
715
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
-
 
716
		}
-
 
717
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
-
 
718
	}
-
 
719
	return _sRetour;
-
 
720
}
-
 
721
 
-
 
722
function debug(objet) {
-
 
723
	var msg = '';
-
 
724
	if (objet != null) {
-
 
725
		$.each(objet, function (cle, valeur) {
-
 
726
			msg += cle+":"+valeur + "\n";
-
 
727
		});
-
 
728
	} else {
-
 
729
		msg = "La variable vaut null.";
-
 
730
	}
-
 
731
	console.log(msg);
-
 
732
}
-
 
733
 
-
 
734
function trim (chaine) {
-
 
735
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
-
 
736
}
-
 
737