Subversion Repositories eFlore/Applications.cel

Rev

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

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