Subversion Repositories eFlore/Applications.cel

Rev

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