Subversion Repositories eFlore/Applications.cel

Rev

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

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