Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 915 Rev 939
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
3
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
4
var pointsOrigine = null;
4
var pointsOrigine = null;
5
var boundsOrigine = null;
5
var boundsOrigine = null;
6
var markerClusterer = null;
6
var markerClusterer = null;
7
var map = null;
7
var map = null;
8
var infoBulle = new google.maps.InfoWindow();
8
var infoBulle = new google.maps.InfoWindow();
9
var pointClique = null;
9
var pointClique = null;
10
var carteCentre = new google.maps.LatLng(46.4, 3.10);
10
var carteCentre = new google.maps.LatLng(46.4, 3.10);
11
var carteOptions = {
11
var carteOptions = {
12
	zoom: 6,
12
	zoom: 6,
13
	mapTypeId: google.maps.MapTypeId.ROADMAP,
13
	mapTypeId: google.maps.MapTypeId.ROADMAP,
14
	mapTypeControlOptions: {
14
	mapTypeControlOptions: {
15
		mapTypeIds: ['OSM', 
15
		mapTypeIds: ['OSM', 
16
		             google.maps.MapTypeId.ROADMAP, 
16
		             google.maps.MapTypeId.ROADMAP, 
17
		             google.maps.MapTypeId.HYBRID, 
17
		             google.maps.MapTypeId.HYBRID, 
18
		             google.maps.MapTypeId.SATELLITE, 
18
		             google.maps.MapTypeId.SATELLITE, 
19
		             google.maps.MapTypeId.TERRAIN]
19
		             google.maps.MapTypeId.TERRAIN]
20
	}
20
	}
21
};			
21
};			
22
var ctaLayer = null;
22
var ctaLayer = null;
23
var osmMapType = new google.maps.ImageMapType({
23
var osmMapType = new google.maps.ImageMapType({
24
	getTileUrl: function(coord, zoom) {
24
	getTileUrl: function(coord, zoom) {
25
		return "http://tile.openstreetmap.org/" +
25
		return "http://tile.openstreetmap.org/" +
26
		zoom + "/" + coord.x + "/" + coord.y + ".png";
26
		zoom + "/" + coord.x + "/" + coord.y + ".png";
27
	},
27
	},
28
	tileSize: new google.maps.Size(256, 256),
28
	tileSize: new google.maps.Size(256, 256),
29
	isPng: true,
29
	isPng: true,
30
	alt: "OpenStreetMap",
30
	alt: "OpenStreetMap",
31
	name: "OSM",
31
	name: "OSM",
32
	maxZoom: 19
32
	maxZoom: 19
33
});
33
});
34
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
34
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
35
var station = {'commune':'', 'obsNbre':0};
35
var station = {'commune':'', 'obsNbre':0};
36
var obsStation = new Array();
36
var obsStation = new Array();
37
var obsPage = new Array();
37
var obsPage = new Array();
-
 
38
var taxonsCarte = new Array();
38
/*+--------------------------------------------------------------------------------------------------------+*/
39
/*+--------------------------------------------------------------------------------------------------------+*/
39
// INITIALISATION DU CODE
40
// INITIALISATION DU CODE
40
 
41
 
41
//Déclenchement d'actions quand JQuery et le document HTML sont OK
42
//Déclenchement d'actions quand JQuery et le document HTML sont OK
42
$(document).ready(function() {
43
$(document).ready(function() {
43
	initialiserWidget();
44
	initialiserWidget();
44
});
45
});
45
 
46
 
46
function initialiserWidget() {
47
function initialiserWidget() {
47
	afficherStats();
48
	afficherStats();
48
	initialiserAffichageCarte();
49
	initialiserAffichageCarte();
49
	initialiserAffichagePanneauLateral();
50
	initialiserAffichagePanneauLateral();
50
	
51
	
51
	initialiserCarte();
52
	initialiserCarte();
52
	initialiserInfoBulle();
53
	initialiserInfoBulle();
53
	chargerLimitesCommunales();
54
	chargerLimitesCommunales();
54
	rafraichirCarte();
55
	rafraichirCarte();
55
}
56
}
56
 
57
 
57
/*+--------------------------------------------------------------------------------------------------------+*/
58
/*+--------------------------------------------------------------------------------------------------------+*/
58
// AFFICHAGE GÉNÉRAL
59
// AFFICHAGE GÉNÉRAL
59
 
60
 
60
function afficherStats() {
61
function afficherStats() {
61
	// Ajout du nombre de communes où des observations ont eu lieu
62
	// Ajout du nombre de communes où des observations ont eu lieu
62
	$('#commune-nbre').append(obs.stats.communes.formaterNombre());
63
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
63
	// Ajout du nombre d'observations
64
	// Ajout du nombre d'observations
64
	$('#obs-nbre').append(obs.stats.observations.formaterNombre());
65
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
65
	// Ajout du nombre de plantes
-
 
66
	$('.plantes-nbre').append(plantesNbre.formaterNombre());
-
 
67
}
66
}
68
 
67
 
69
/*+--------------------------------------------------------------------------------------------------------+*/
68
/*+--------------------------------------------------------------------------------------------------------+*/
70
// CARTE
69
// CARTE
71
 
70
 
72
function initialiserAffichageCarte() {
71
function initialiserAffichageCarte() {
73
	$('#carte').height($(window).height() - 35);
72
	$('#carte').height($(window).height() - 35);
74
	$('#carte').width($(window).width() - 24);
73
	$('#carte').width($(window).width() - 24);
75
	
74
	
76
	if (nt != '*') {
75
	if (nt != '*') {
77
		$('#carte').css('left', 0);
76
		$('#carte').css('left', 0);
78
	}
77
	}
79
}
78
}
80
 
79
 
81
function initialiserCarte() {
80
function initialiserCarte() {
82
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
81
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
83
	// Ajout de la couche OSM à la carte
82
	// Ajout de la couche OSM à la carte
84
	map.mapTypes.set('OSM', osmMapType);
83
	map.mapTypes.set('OSM', osmMapType);
85
}
84
}
86
 
85
 
87
 
86
 
88
function chargerLimitesCommunales() {
87
function chargerLimitesCommunales() {
89
	if (urlsLimitesCommunales != null) {
88
	if (urlsLimitesCommunales != null) {
90
		for (urlId in urlsLimitesCommunales) { 
89
		for (urlId in urlsLimitesCommunales) { 
91
			var url = urlsLimitesCommunales[urlId];
90
			var url = urlsLimitesCommunales[urlId];
92
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
91
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
93
			ctaLayer.setMap(map);
92
			ctaLayer.setMap(map);
94
		}
93
		}
95
	}
94
	}
96
}
95
}
97
 
96
 
98
function rafraichirCarte() {
97
function rafraichirCarte() {
99
	var points = [];
98
	var points = [];
100
	var bounds = new google.maps.LatLngBounds();
99
	var bounds = new google.maps.LatLngBounds();
101
	for (var i = 0; i < obs.stats.communes; ++i) {
100
	for (var i = 0; i < stations.stats.communes; ++i) {
102
		var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y);
101
		var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y);
103
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
102
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
104
		var point = new google.maps.Marker({
103
		var point = new google.maps.Marker({
105
			position: maLatLng,
104
			position: maLatLng,
106
			map: map,
105
			map: map,
107
			icon: pointImage,
106
			icon: pointImage,
108
			stationId: obs.points[i].id
107
			stationId: stations.points[i].id
109
		});
108
		});
110
 
109
 
111
		bounds.extend(maLatLng);
110
		bounds.extend(maLatLng);
112
		
111
		
113
		google.maps.event.addListener(point, 'click', function() {
112
		google.maps.event.addListener(point, 'click', function() {
114
			pointClique =  this;
113
			pointClique =  this;
115
			infoBulle.open(map, this);
114
			infoBulle.open(map, this);
116
			
115
			
117
			var limites = map.getBounds();
116
			var limites = map.getBounds();
118
			var centre = limites.getCenter();
117
			var centre = limites.getCenter();
119
			var nordEst = limites.getNorthEast();
118
			var nordEst = limites.getNorthEast();
120
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
119
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
121
			map.panTo(centreSudLatLng);
120
			map.panTo(centreSudLatLng);
122
			
121
			
123
			afficherInfoBulle();
122
			afficherInfoBulle();
124
			lancerChargementObs();
123
			chargerObs(0, 0);
125
		});
124
		});
126
		
125
		
127
		points.push(point);
126
		points.push(point);
128
	}
127
	}
129
 
128
 
130
	if (pointsOrigine == null && boundsOrigine == null) {
129
	if (pointsOrigine == null && boundsOrigine == null) {
131
		pointsOrigine = points;
130
		pointsOrigine = points;
132
		boundsOrigine = bounds;
131
		boundsOrigine = bounds;
133
	}
132
	}
134
	
133
	
135
	executerMarkerClusterer(points, bounds);
134
	executerMarkerClusterer(points, bounds);
136
}
135
}
137
 
136
 
138
function deplacerCartePointClique() {
137
function deplacerCartePointClique() {
139
	map.panTo(pointClique.position);
138
	map.panTo(pointClique.position);
140
}
139
}
141
 
140
 
142
function executerMarkerClusterer(points, bounds) {
141
function executerMarkerClusterer(points, bounds) {
143
	if (markerClusterer) {
142
	if (markerClusterer) {
144
		markerClusterer.clearMarkers();
143
		markerClusterer.clearMarkers();
145
	}
144
	}
146
	markerClusterer = new MarkerClusterer(map, points);
145
	markerClusterer = new MarkerClusterer(map, points);
147
	map.fitBounds(bounds);
146
	map.fitBounds(bounds);
148
}
147
}
149
 
148
 
150
/*+--------------------------------------------------------------------------------------------------------+*/
149
/*+--------------------------------------------------------------------------------------------------------+*/
151
// INFO BULLE
150
// INFO BULLE
152
 
151
 
153
function initialiserInfoBulle() {
152
function initialiserInfoBulle() {
154
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
153
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
155
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
154
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
156
}
155
}
157
 
156
 
158
function afficherInfoBulle() {
157
function afficherInfoBulle() {
159
	var obsHtml = $("#tpl-obs").html();
158
	var obsHtml = $("#tpl-obs").html();
160
	infoBulle.setContent(obsHtml);
159
	infoBulle.setContent(obsHtml);
161
}
160
}
162
 
161
 
163
function afficherMessageChargement(element) {
162
function afficherMessageChargement(element) {
164
	if ($('#chargement').get() == '') {
163
	if ($('#chargement').get() == '') {
165
		$('#tpl-chargement').tmpl().appendTo(element);
164
		$('#tpl-chargement').tmpl().appendTo(element);
166
	}
165
	}
167
}
166
}
168
 
167
 
169
function supprimerMessageChargement() {
168
function supprimerMessageChargement() {
170
	$('#chargement').remove();
169
	$('#chargement').remove();
171
}
170
}
172
 
-
 
173
function lancerChargementObs() {
-
 
174
	var urlObsNbre = urlObsStation;
-
 
175
	urlObsNbre = urlObsNbre.replace(/\{action\}/g, 'observations-nombre');
-
 
176
	urlObsNbre = urlObsNbre.replace(/\{stationId\}/g, pointClique.stationId);
-
 
177
	console.log("Lancement recup nombre");
-
 
178
	$.getJSON(urlObsNbre, function(infos){
-
 
179
		console.log("Lancement charger obs");
-
 
180
		chargerObs(0, infos.obsNbre);
-
 
181
		station = infos;
-
 
182
		actualiserPagineur();
-
 
183
		creerTitreInfoBulle();
-
 
184
	});
-
 
185
}
-
 
186
 
-
 
187
function actualiserPagineur() {
-
 
188
	pagineur.stationId = pointClique.stationId;
-
 
189
	pagineur.total = station.obsNbre;
-
 
190
	console.log(pagineur.total);
-
 
191
	if (pagineur.total > 4) {
-
 
192
		pagineur.format = 'tableau';
-
 
193
	} else {
-
 
194
		pagineur.format = 'liste';
-
 
195
	}
-
 
196
}
-
 
197
 
171
 
198
function chargerObs(depart, total) {
172
function chargerObs(depart, total) {
199
	if (depart < total) {
173
	if (depart == 0 || depart < total) {
200
		var limite = 300;
174
		var limite = 300;
201
		if (depart == 0) {
175
		if (depart == 0) {
202
			obsStation = new Array();
176
			obsStation = new Array();
203
		}
177
		}
204
		console.log("Chargement de "+depart+" à "+(depart+limite));
178
		console.log("Chargement de "+depart+" à "+(depart+limite));
205
		var urlObs = urlObsStation+'&start={start}&limit='+limite;
179
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
206
		urlObs = urlObs.replace(/\{action\}/g, 'observations');
-
 
207
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
180
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
-
 
181
		urlObs = urlObs.replace(/\{nt\}/g, nt);
208
		urlObs = urlObs.replace(/\{start\}/g, depart);
182
		urlObs = urlObs.replace(/\{start\}/g, depart);
209
		
183
		
210
		$.getJSON(urlObs, function(observations){
184
		$.getJSON(urlObs, function(observations){
211
			obsStation = obsStation.concat(observations.observations);
185
			obsStation = obsStation.concat(observations.observations);
-
 
186
			if (depart == 0) {
-
 
187
				actualiserInfosStation(observations);
-
 
188
				actualiserPagineur();
-
 
189
				creerTitreInfoBulle();
-
 
190
			}
212
			console.log("Chargement ok");
191
			console.log("Chargement ok");
213
			chargerObs(depart+limite, total);
192
			chargerObs(depart+limite, station.obsNbre);
214
		});
193
		});
215
	} else {
194
	} else {
216
		if (pagineur.limite < total) {
195
		if (pagineur.limite < total) {
217
			afficherPagination();
196
			afficherPagination();
218
		} else {
197
		} else {
219
			surClicPagePagination(0, null);
198
			surClicPagePagination(0, null);
-
 
199
			selectionnerOnglet("#obs-vue-"+pagineur.format);
220
		}
200
		}
221
	}
201
	}
222
}
202
}
-
 
203
 
-
 
204
function actualiserInfosStation(infos) {
-
 
205
	station.commune = infos.commune;
-
 
206
	station.obsNbre = infos.total;
-
 
207
}
-
 
208
 
-
 
209
function actualiserPagineur() {
-
 
210
	pagineur.stationId = pointClique.stationId;
-
 
211
	pagineur.total = station.obsNbre;
-
 
212
	console.log("Total pagineur: "+pagineur.total);
-
 
213
	if (pagineur.total > 4) {
-
 
214
		pagineur.format = 'tableau';
-
 
215
	} else {
-
 
216
		pagineur.format = 'liste';
-
 
217
	}
223
 
218
}
224
 
219
 
225
function afficherPagination(observations) {
220
function afficherPagination(observations) {
226
	$(".navigation").pagination(pagineur.total, {
221
	$(".navigation").pagination(pagineur.total, {
227
		items_per_page:pagineur.limite,
222
		items_per_page:pagineur.limite,
228
		callback:surClicPagePagination,
223
		callback:surClicPagePagination,
229
		next_text:'Suivant',
224
		next_text:'Suivant',
230
		prev_text:'Précédent',
225
		prev_text:'Précédent',
231
		prev_show_always:false,
226
		prev_show_always:false,
232
		num_edge_entries:1,
227
		num_edge_entries:1,
233
		num_display_entries:5,
228
		num_display_entries:5,
234
		load_first_page:true
229
		load_first_page:true
235
	});
230
	});
236
}
231
}
237
 
232
 
238
function surClicPagePagination(pageIndex, paginationConteneur) {
233
function surClicPagePagination(pageIndex, paginationConteneur) {
239
	var index = pageIndex * pagineur.limite;
234
	var index = pageIndex * pagineur.limite;
240
	var indexMax = index + pagineur.limite;
235
	var indexMax = index + pagineur.limite;
241
	pagineur.depart = index;
236
	pagineur.depart = index;
242
	obsPage = new Array();
237
	obsPage = new Array();
243
    for(index; index < indexMax; index++) {
238
    for(index; index < indexMax; index++) {
244
    	obsPage.push(obsStation[index]);
239
    	obsPage.push(obsStation[index]);
245
    }
240
    }
246
    
241
    
247
    supprimerMessageChargement();
242
    supprimerMessageChargement();
248
    mettreAJourObservations();
243
    mettreAJourObservations();
249
	return false;
244
	return false;
250
}
245
}
251
 
246
 
252
function mettreAJourObservations() {
247
function mettreAJourObservations() {
253
	$("#obs-"+pagineur.format+"-lignes").empty();
248
	$("#obs-"+pagineur.format+"-lignes").empty();
254
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
249
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
255
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
250
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
256
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
251
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
257
	
252
	
258
	// Actualisation de Fancybox
253
	// Actualisation de Fancybox
259
	if (pagineur.format == 'liste') {
254
	if (pagineur.format == 'liste') {
260
		ajouterGaleriePhoto("a.cel-img");
255
		ajouterGaleriePhoto("a.cel-img");
261
	}
256
	}
262
}
257
}
263
 
258
 
264
function creerTitreInfoBulle() {
259
function creerTitreInfoBulle() {
265
	$("#obs-total").append(station.obsNbre);
260
	$("#obs-total").append(station.obsNbre);
266
	$("#obs-commune").append(station.commune);	
261
	$("#obs-commune").append(station.commune);	
267
}
262
}
268
 
263
 
269
function initialiserContenuInfoBulle() {
264
function initialiserContenuInfoBulle() {
270
	afficherOnglets();
265
	afficherOnglets();
271
	afficherMessageChargement('#observations');
266
	afficherMessageChargement('#observations');
272
	ajouterTableauTriable("#obs-tableau");
267
	ajouterTableauTriable("#obs-tableau");
273
	afficherTextStationId();
268
	afficherTextStationId();
274
	corrigerLargeurInfoWindow();
269
	corrigerLargeurInfoWindow();
275
}
270
}
276
 
271
 
277
function afficherOnglets() {
272
function afficherOnglets() {
278
	var $tabs = $('#obs').tabs();
273
	var $tabs = $('#obs').tabs();
279
	$('#obs').bind('tabsselect', function(event, ui) {
274
	$('#obs').bind('tabsselect', function(event, ui) {
280
		if (ui.panel.id == 'obs-vue-tableau') {
275
		if (ui.panel.id == 'obs-vue-tableau') {
281
			surClicAffichageTableau();
276
			surClicAffichageTableau();
282
		} else if (ui.panel.id == 'obs-vue-liste') {
277
		} else if (ui.panel.id == 'obs-vue-liste') {
283
			surClicAffichageListe();
278
			surClicAffichageListe();
284
		}
279
		}
285
	});
280
	});
286
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
281
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
287
}
282
}
-
 
283
 
-
 
284
function selectionnerOnglet(onglet) {
-
 
285
	$('#obs').tabs('select', onglet);
-
 
286
}
288
 
287
 
289
function afficherTextStationId() {
288
function afficherTextStationId() {
290
	$('#obs-station-id').text(pointClique.stationId);
289
	$('#obs-station-id').text(pointClique.stationId);
291
}
290
}
292
 
291
 
293
function corrigerLargeurInfoWindow() {
292
function corrigerLargeurInfoWindow() {
294
	$("#info-bulle").width($("#info-bulle").width() - 16);
293
	$("#info-bulle").width($("#info-bulle").width() - 16);
295
}
294
}
296
 
295
 
297
function surClicAffichageTableau(event) {
296
function surClicAffichageTableau(event) {
298
	console.log('tableau');
297
	console.log('tableau');
299
	pagineur.format = 'tableau';
298
	pagineur.format = 'tableau';
300
	mettreAJourObservations();
299
	mettreAJourObservations();
301
	mettreAJourTableauTriable("#obs-tableau");
300
	mettreAJourTableauTriable("#obs-tableau");
302
}
301
}
303
 
302
 
304
function surClicAffichageListe(event) {
303
function surClicAffichageListe(event) {
305
	console.log('liste');
304
	console.log('liste');
306
	pagineur.format = 'liste';
305
	pagineur.format = 'liste';
307
	mettreAJourObservations();
306
	mettreAJourObservations();
308
	ajouterGaleriePhoto("a.cel-img");
307
	ajouterGaleriePhoto("a.cel-img");
309
}
308
}
310
 
309
 
311
function ajouterTableauTriable(element) {
310
function ajouterTableauTriable(element) {
312
	// add parser through the tablesorter addParser method 
311
	// add parser through the tablesorter addParser method 
313
	$.tablesorter.addParser({ 
312
	$.tablesorter.addParser({ 
314
		// Définition d'un id unique pour ce parsseur 
313
		// Définition d'un id unique pour ce parsseur 
315
		id: 'date_cel', 
314
		id: 'date_cel', 
316
		is: function(s) { 
315
		is: function(s) { 
317
			// doit retourner false si le parsseur n'est pas autodétecté
316
			// doit retourner false si le parsseur n'est pas autodétecté
318
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
317
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
319
		}, 
318
		}, 
320
		format: function(date) { 
319
		format: function(date) { 
321
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
320
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
322
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
321
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
323
			// Remplace la date par un nombre de millisecondes pour trier numériquement
322
			// Remplace la date par un nombre de millisecondes pour trier numériquement
324
			return $.tablesorter.formatFloat(new Date(date).getTime());
323
			return $.tablesorter.formatFloat(new Date(date).getTime());
325
		}, 
324
		}, 
326
		// set type, either numeric or text 
325
		// set type, either numeric or text 
327
		type: 'numeric' 
326
		type: 'numeric' 
328
	});
327
	});
329
	$(element).tablesorter({ 
328
	$(element).tablesorter({ 
330
        headers: { 
329
        headers: { 
331
			1: { 
330
			1: { 
332
            	sorter:'date_cel' 
331
            	sorter:'date_cel' 
333
        	} 
332
        	} 
334
    	} 
333
    	} 
335
	});
334
	});
336
}
335
}
337
 
336
 
338
function mettreAJourTableauTriable(element) {
337
function mettreAJourTableauTriable(element) {
339
	$(element).trigger('update');
338
	$(element).trigger('update');
340
}
339
}
341
 
340
 
342
function ajouterGaleriePhoto(element) {
341
function ajouterGaleriePhoto(element) {
343
	$(element).fancybox({
342
	$(element).fancybox({
344
		transitionIn:'elastic',
343
		transitionIn:'elastic',
345
		transitionOut:'elastic',
344
		transitionOut:'elastic',
346
		speedIn	:600, 
345
		speedIn	:600, 
347
		speedOut:200,
346
		speedOut:200,
348
		overlayShow:true,
347
		overlayShow:true,
349
		titleShow:true,
348
		titleShow:true,
350
		titlePosition:'inside',
349
		titlePosition:'inside',
351
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
350
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
352
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
351
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
353
			motif.exec(titre);
352
			motif.exec(titre);
354
			var id = RegExp.$1;
353
			var id = RegExp.$1;
355
			var info = $('#cel-info-'+id).clone().html();
354
			var info = $('#cel-info-'+id).clone().html();
356
			var tpl = 
355
			var tpl = 
357
				'<div class="cel-legende">'+
356
				'<div class="cel-legende">'+
358
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
357
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
359
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
358
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
360
				'<\/div>';
359
				'<\/div>';
361
			return tpl;
360
			return tpl;
362
		}
361
		}
363
		}).live('click', function(e) {
362
		}).live('click', function(e) {
364
			if (e.stopPropagation) {
363
			if (e.stopPropagation) {
365
				e.stopPropagation();
364
				e.stopPropagation();
366
			}
365
			}
367
			return false;
366
			return false;
368
		});
367
		});
369
}
368
}
370
 
369
 
371
/*+--------------------------------------------------------------------------------------------------------+*/
370
/*+--------------------------------------------------------------------------------------------------------+*/
372
// PANNEAU LATÉRAL
371
// PANNEAU LATÉRAL
373
 
372
 
374
function initialiserAffichagePanneauLateral() {
373
function initialiserAffichagePanneauLateral() {
375
	$('#panneau-lateral').height($(window).height() - 35);
374
	$('#panneau-lateral').height($(window).height() - 35);
376
	
375
	
377
	if (nt == '*') {
376
	if (nt == '*') {
378
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
377
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
379
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
378
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
-
 
379
	}
-
 
380
	chargerTaxons(0, 0);
-
 
381
}
-
 
382
 
-
 
383
function chargerTaxons(depart, total) {
-
 
384
	if (depart == 0 || depart < total) {
-
 
385
		var limite = 7000;
-
 
386
		console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
-
 
387
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
-
 
388
		urlTax = urlTax.replace(/\{start\}/g, depart);
-
 
389
		$.getJSON(urlTax, function(infos) {
-
 
390
			taxonsCarte = taxonsCarte.concat(infos.taxons);
-
 
391
			console.log("Nbre taxons :"+taxonsCarte.length);
-
 
392
			chargerTaxons(depart+limite, infos.total);
-
 
393
		});
-
 
394
	} else {
-
 
395
		if (nt == '*') {
-
 
396
			afficherTaxons();
-
 
397
		} else {
-
 
398
			afficherNomPlante();
-
 
399
		}
-
 
400
	}
-
 
401
}
-
 
402
 
-
 
403
function afficherTaxons() {
-
 
404
	// Ajout du nombre de plantes au titre
-
 
405
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
-
 
406
	
-
 
407
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
380
		$('.taxon').live('click', filtrerParTaxon);
408
	$('.taxon').live('click', filtrerParTaxon);
-
 
409
}
-
 
410
 
-
 
411
function afficherNomPlante() {
-
 
412
	if (nt != '*') {
-
 
413
		var taxon = taxonsCarte[0];
-
 
414
		$('.plante-titre').text('pour '+taxon.nom);
381
	}
415
	}
382
}
416
}
383
 
417
 
384
function afficherPanneauLateral() {
418
function afficherPanneauLateral() {
385
	$('#panneau-lateral').width(300);
419
	$('#panneau-lateral').width(300);
386
	$('#pl-contenu').css('display', 'block');
420
	$('#pl-contenu').css('display', 'block');
387
	$('#pl-ouverture').css('display', 'none');
421
	$('#pl-ouverture').css('display', 'none');
388
	$('#pl-fermeture').css('display', 'block');
422
	$('#pl-fermeture').css('display', 'block');
389
	$('#carte').css('left', '300px');
423
	$('#carte').css('left', '300px');
390
 
424
 
391
	google.maps.event.trigger(map, 'resize');
425
	google.maps.event.trigger(map, 'resize');
392
};
426
};
393
 
427
 
394
function cacherPanneauLateral() {
428
function cacherPanneauLateral() {
395
	$('#panneau-lateral').width(24);
429
	$('#panneau-lateral').width(24);
396
	$('#pl-contenu').css('display', 'none');
430
	$('#pl-contenu').css('display', 'none');
397
	$('#pl-ouverture').css('display', 'block');
431
	$('#pl-ouverture').css('display', 'block');
398
	$('#pl-fermeture').css('display', 'none');
432
	$('#pl-fermeture').css('display', 'none');
399
	$('#carte').css('left', '24px');
433
	$('#carte').css('left', '24px');
400
	
434
	
401
	google.maps.event.trigger(map, 'resize');
435
	google.maps.event.trigger(map, 'resize');
402
};
436
};
403
 
437
 
404
function ouvrirPopUp(url, nom) {
438
function ouvrirPopUp(url, nom) {
405
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
439
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
406
};
440
};
407
 
441
 
408
function filtrerParTaxon() {
442
function filtrerParTaxon() {
409
	var ntAFiltrer = $('.nt', this).text();
443
	var ntAFiltrer = $('.nt', this).text();
410
	infoBulle.close();
444
	infoBulle.close();
411
	$('#taxon-'+nt).removeClass('taxon-actif');
445
	$('#taxon-'+nt).removeClass('taxon-actif');
412
	if (nt == ntAFiltrer) {
446
	if (nt == ntAFiltrer) {
413
		nt = '*';
447
		nt = '*';
414
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
448
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
415
	} else {
449
	} else {
416
		var url = urlObsCarte+'&'+
450
		var url = stationsUrl+'&'+
417
			'num_taxon='+ntAFiltrer+'&'+
451
			'num_taxon='+ntAFiltrer+'&'+
418
			'formatRetour=jsonp'+'&'+
452
			'formatRetour=jsonP'+'&'+
419
			'callback=?';
453
			'callback=?';
420
		$.getJSON(url, function (observations) {
454
		$.getJSON(url, function (stationsFiltrees) {
421
			obs = observations;
455
			stations = stationsFiltrees;
422
			nt = ntAFiltrer;
456
			nt = ntAFiltrer;
423
			$('#taxon-'+nt).addClass('taxon-actif');
457
			$('#taxon-'+nt).addClass('taxon-actif');
424
			rafraichirCarte();
458
			rafraichirCarte();
425
		});
459
		});
426
	}
460
	}
427
};
461
};
428
 
462
 
429
/*+--------------------------------------------------------------------------------------------------------+*/
463
/*+--------------------------------------------------------------------------------------------------------+*/
430
// FONCTIONS UTILITAIRES
464
// FONCTIONS UTILITAIRES
431
 
465
 
432
function arreter(event) {
466
function arreter(event) {
433
	if (event.stopPropagation) {
467
	if (event.stopPropagation) {
434
		event.stopPropagation();
468
		event.stopPropagation();
435
	} else if (window.event) {
469
	} else if (window.event) {
436
		window.event.cancelBubble = true;
470
		window.event.cancelBubble = true;
437
	}
471
	}
438
	return false;
472
	return false;
439
}
473
}
440
 
474
 
441
/**
475
/**
442
 * +-------------------------------------+
476
 * +-------------------------------------+
443
 * Number.prototype.formaterNombre
477
 * Number.prototype.formaterNombre
444
 * +-------------------------------------+
478
 * +-------------------------------------+
445
 * Params (facultatifs):
479
 * Params (facultatifs):
446
 * - Int decimales: nombre de decimales (exemple: 2)
480
 * - Int decimales: nombre de decimales (exemple: 2)
447
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
481
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
448
 * - String separateurMilliers: comme son nom l'indique
482
 * - String separateurMilliers: comme son nom l'indique
449
 * Returns:
483
 * Returns:
450
 * - String chaine formatee
484
 * - String chaine formatee
451
 * @author	::mastahbenus::
485
 * @author	::mastahbenus::
452
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
486
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
453
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
487
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
454
 */
488
 */
455
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
489
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
456
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
490
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
457
	
491
	
458
	function is_int(nbre) {
492
	function is_int(nbre) {
459
		nbre = nbre.replace(',', '.');
493
		nbre = nbre.replace(',', '.');
460
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
494
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
461
	}
495
	}
462
 
496
 
463
	if (decimales == undefined) {
497
	if (decimales == undefined) {
464
		if (is_int(_sNombre)) {
498
		if (is_int(_sNombre)) {
465
			decimales = 0;
499
			decimales = 0;
466
		} else {
500
		} else {
467
			decimales = 2;
501
			decimales = 2;
468
		}
502
		}
469
	}
503
	}
470
	if (signe == undefined) {
504
	if (signe == undefined) {
471
		if (is_int(_sNombre)) {
505
		if (is_int(_sNombre)) {
472
			signe = '';
506
			signe = '';
473
		} else {
507
		} else {
474
			signe = '.';
508
			signe = '.';
475
		}
509
		}
476
	}
510
	}
477
	if (separateurMilliers == undefined) {
511
	if (separateurMilliers == undefined) {
478
		separateurMilliers = ' ';
512
		separateurMilliers = ' ';
479
	}
513
	}
480
	
514
	
481
	function separeMilliers (sNombre) {
515
	function separeMilliers (sNombre) {
482
		var sRetour = "";
516
		var sRetour = "";
483
		while (sNombre.length % 3 != 0) {
517
		while (sNombre.length % 3 != 0) {
484
			sNombre = "0"+sNombre;
518
			sNombre = "0"+sNombre;
485
		}
519
		}
486
		for (i = 0; i < sNombre.length; i += 3) {
520
		for (i = 0; i < sNombre.length; i += 3) {
487
			if (i == sNombre.length-1) separateurMilliers = '';
521
			if (i == sNombre.length-1) separateurMilliers = '';
488
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
522
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
489
		}
523
		}
490
		while (sRetour.substr(0, 1) == "0") {
524
		while (sRetour.substr(0, 1) == "0") {
491
			sRetour = sRetour.substr(1);
525
			sRetour = sRetour.substr(1);
492
		}
526
		}
493
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
527
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
494
	}
528
	}
495
	
529
	
496
	if (_sNombre.indexOf('.') == -1) {
530
	if (_sNombre.indexOf('.') == -1) {
497
		for (i = 0; i < decimales; i++) {
531
		for (i = 0; i < decimales; i++) {
498
			_sDecimales += "0";
532
			_sDecimales += "0";
499
		}
533
		}
500
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
534
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
501
	} else {
535
	} else {
502
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
536
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
503
		if (sDecimalesTmp.length > decimales) {
537
		if (sDecimalesTmp.length > decimales) {
504
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
538
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
505
			var nDiv = 1;
539
			var nDiv = 1;
506
			for (i = 0; i < nDecimalesManquantes; i++) {
540
			for (i = 0; i < nDecimalesManquantes; i++) {
507
				nDiv *= 10;
541
				nDiv *= 10;
508
			}
542
			}
509
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
543
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
510
		}
544
		}
511
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
545
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
512
	}
546
	}
513
	return _sRetour;
547
	return _sRetour;
514
}
548
}
515
 
549
 
516
function debug(objet) {
550
function debug(objet) {
517
	var msg = '';
551
	var msg = '';
518
	if (objet != null) {
552
	if (objet != null) {
519
		$.each(objet, function (cle, valeur) {
553
		$.each(objet, function (cle, valeur) {
520
			msg += cle+":"+valeur + "\n";
554
			msg += cle+":"+valeur + "\n";
521
		});
555
		});
522
	} else {
556
	} else {
523
		msg = "La variable vaut null.";
557
		msg = "La variable vaut null.";
524
	}
558
	}
525
	console.log(msg);
559
	console.log(msg);
526
}
560
}