Subversion Repositories eFlore/Applications.cel

Rev

Rev 980 | Rev 1035 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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