Subversion Repositories eFlore/Applications.cel

Rev

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

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