Subversion Repositories eFlore/Applications.moissonnage

Rev

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

Rev 31 Rev 37
1
// Javascript Document
-
 
2
 
-
 
3
 
-
 
4
// ===================================================================================
-
 
5
//  FONCTIONS ADDITIONNELLES POUR GERER LES URLS ET L'OUVERTRURE DE NOUVELLE FENETRE
-
 
6
function convertirEnParametresUrl(objet) {
-
 
7
	var parametresUrl = '';
-
 
8
	for (attribut in objet) {
-
 
9
		if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' ||
-
 
10
			objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0)
-
 
11
			continue;
-
 
12
		parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut];
-
 
13
	}
-
 
14
	return parametresUrl;
-
 
15
};
-
 
16
 
-
 
17
function recupererParametreDansUrl(nomParametre, chaineRecherche) {
-
 
18
	var split = chaineRecherche.split('?');
-
 
19
	chaineRecherche = split[split.length-1];
-
 
20
	var valeurParametre = null;
-
 
21
	var listeParametres = chaineRecherche.split("&");
-
 
22
	for (var index = 0; index < listeParametres.length; index ++) {
-
 
23
		var split = listeParametres[index].split("=");
-
 
24
		if (split[0] == nomParametre) {
-
 
25
			valeurParametre = split[1];
-
 
26
			break;
-
 
27
		}
-
 
28
	}
-
 
29
	return valeurParametre;
-
 
30
};
-
 
31
 
-
 
32
function estValeurDansTableau(tableau, valeur) {
-
 
33
	var index;
-
 
34
	for (index = 0; index < tableau.length && tableau[index] != valeur; index ++);
-
 
35
	return (tableau.length > 0 && index != tableau.length);
-
 
36
}
-
 
37
 
-
 
38
function ouvrirNouvelleFenetre(element, event) {
-
 
39
	window.open(element.href);
-
 
40
	return arreter(event);
-
 
41
}
-
 
42
 
-
 
43
function arreter(event) {
-
 
44
	if (event.stopPropagation) {
-
 
45
		event.stopPropagation();
-
 
46
	} else if (window.event) {
-
 
47
		window.event.cancelBubble = true;
-
 
48
	}
-
 
49
	if (event.preventDefault) {
-
 
50
		event.preventDefault();
-
 
51
	}
-
 
52
	event.returnValue = false;
-
 
53
	return false;
-
 
54
}
-
 
55
 
-
 
56
 
-
 
57
 
-
 
58
// =============================================================
-
 
59
 
-
 
60
var map = null,
1
var map = null,
61
optionsCoucheOSM = {
2
optionsCoucheOSM = {
62
	attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,'
3
	attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,'
63
	+ ' <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
4
	+ ' <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
64
	maxZoom: 18
5
	maxZoom: 18
65
},
6
},
66
optionsCoucheGoogle = {
7
optionsCoucheGoogle = {
67
	attribution: 'Map data &copy;'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>',
8
	attribution: 'Map data &copy;'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>',
68
	maxZoom: 18
9
	maxZoom: 18
69
},
10
},
70
coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
11
coucheOSM = new L.TileLayer("http://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
71
	optionsCoucheOSM),
12
	optionsCoucheOSM),
72
couchePlanGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
13
coucheRelief = new L.TileLayer("http://c.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png",
73
	optionsCoucheGoogle),
14
	optionsCoucheOSM),
74
coucheSatelliteGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
15
coucheSatellite = new L.TileLayer("http://mt1.google.com/vt/lyrs=y@218131653&hl=fr&src=app&x={x}&y={y}&z={z}",
75
	optionsCoucheGoogle),
16
	optionsCoucheGoogle),
76
optionsCarte = {
17
optionsCarte = {
77
	center : new L.LatLng(46, 2),
18
	center : new L.LatLng(46, 2),
78
	zoom : 6,
19
	zoom : 6,
79
	minZoom : 3,
20
	minZoom : 3,
80
	maxBounds : [[-85.051129, -180], [85.051129, 180]],
21
	maxBounds : [[-85.051129, -180], [85.051129, 180]],
81
	layers : [coucheOSM]
22
	layers : [coucheOSM]
82
},
23
},
83
zoom = 6,
24
zoom = 6,
84
legende = null,
25
legende = null,
85
coucheDepartement = null,
26
coucheDepartement = null,
86
infoBulle = null;
27
infoBulle = null;
87
 
28
 
88
var coucheSites = new L.FeatureGroup(),
-
 
89
points = new Array(),
-
 
90
coucheSites = new L.FeatureGroup(),
29
var coucheSites = null,
91
sources = new Object(),
-
 
92
formeDonnees = '',
30
sources = new Object(),
93
popupMaille = null;
31
typeSite = 'maille',
94
overlays = [];
32
overlays = [];
95
 
33
 
96
var requeteChargementPoints = null,
34
var requeteChargementPoints = null,
97
	chargementMaillesEnCours = false,
-
 
98
doitRafraichirCarte = true,
-
 
99
chargementCommunesEnCours = false,
-
 
100
timer = null,
35
timer = null,
-
 
36
ancienneRequete = null,
-
 
37
deplacement = true,
101
url = '';
38
url = '';
102
 
39
 
103
 
40
 
104
 
41
 
105
 
42
 
106
$(document).ready(function() {
43
$(document).ready(function() {
107
	initialiserWidget();
44
	initialiserWidget();
108
});
45
});
-
 
46
 
-
 
47
$(window).resize(function() {
-
 
48
	dimensionnerCarte();
-
 
49
});
109
 
50
 
110
function initialiserWidget() {
51
function initialiserWidget() {
111
	initialiserCarte();
52
	initialiserCarte();
112
	dimensionnerOverlay();
53
	chargerLimitesCommunales();
113
	initialiserPanneauControle();
54
	initialiserPanneauControle();
114
	initialiserSources();
55
	initialiserSources();
115
	initialiserListeners();
56
	initialiserListeners();
116
	chargerLimitesCommunales();
-
 
117
	chargerMaillesVides();
57
	chargerLocalisations();
118
	programmerRafraichissementCarte();
-
 
119
}
-
 
120
 
-
 
121
$(window).resize(function() {
-
 
122
	dimensionnerCarte();
-
 
123
	if (infoBulle != null) {
-
 
124
		redimensionnerPopup();
-
 
125
	}
-
 
126
});
-
 
127
 
-
 
128
function dimensionnerOverlay() {
-
 
129
	var taille = '1.6';
-
 
130
	var tailleMaxIcones = 20;
-
 
131
	var padding_icones = 8;
-
 
132
	$("#zone-titre h1").css('font-size', (taille)+'em');
-
 
133
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
-
 
134
	$('#zone-titre').height(tailleMaxIcones*2);
-
 
135
	var left = ($(window).width()-$('#zone-titre').width())/2;
-
 
136
	$('#zone-titre').css('left',left);
-
 
137
}
-
 
138
 
-
 
139
 
-
 
140
function dimensionnerCarte() {
-
 
141
	$('#map').height($(window).height());
-
 
142
	$('#map').width($(window).width());
-
 
143
}
58
}
144
 
59
 
145
function initialiserCarte() {
60
function initialiserCarte() {
146
	dimensionnerCarte();
61
	dimensionnerCarte();
147
	map = L.map('map', optionsCarte);
62
	map = L.map('map', optionsCarte);
-
 
63
	coucheSatellite.addTo(map);
148
	coucheSites.addTo(map);
64
	coucheRelief.addTo(map);
149
	coucheOSM.addTo(map);
65
	coucheOSM.addTo(map);
150
	couchePlanGoogle.addTo(map);
-
 
151
	coucheSatelliteGoogle.addTo(map);
-
 
152
	var echelle = new L.Control.Scale({
66
	var echelle = new L.Control.Scale({
153
		maxWidth : 32,
67
		maxWidth : 50,
154
		metric : true,
68
		metric : true,
155
		imperial : false,
69
		imperial : false,
156
		updateWhenIdle : true
70
		updateWhenIdle : true
157
	});
71
	});
158
	map.addControl(echelle);
72
	map.addControl(echelle);
159
	zoom = map.getZoom();
73
	zoom = map.getZoom();
160
}
74
}
-
 
75
 
-
 
76
function dimensionnerCarte() {
-
 
77
	$('#map').height($(window).height());
-
 
78
	$('#map').width($(window).width());
-
 
79
}
161
 
80
 
162
function initialiserListeners() {
81
function initialiserListeners() {
163
	map.on('moveend', surChangementVueSurCarte);
82
	map.on('moveend', surChangementVueCarte);
164
	map.on('zoomend', surChangementVueSurCarte);
83
	map.on('zoomend', surChangementVueCarte);
165
	map.on('popupclose', function(e) {
84
	map.on('popupclose', function(e) {
166
		masquerInfoBulle();
85
		masquerInfoBulle();
167
		programmerRafraichissementCarte();
86
		programmerRafraichissementCarte();
168
	});
87
	});
169
}
88
}
170
 
89
 
171
function initialiserPanneauControle() {
90
function initialiserPanneauControle() {
172
	var baseMaps = {
91
	var baseMaps = {
173
		"OpenStreetMap" : coucheOSM,
92
		"Satellite" : coucheSatellite,
174
		"Plan" : couchePlanGoogle,
93
		"Relief" : coucheRelief,
175
		"Satellite" : coucheSatelliteGoogle
94
		"Plan" : coucheOSM
176
	};
95
	};
177
 
96
 
178
	var overlayMaps = {};
97
	var overlayMaps = {};
179
	for (var index = 0; index < listeSources.length; index ++) {
98
	for (var index = 0; index < listeSources.length; index ++) {
180
		sources[listeSources[index]] = estValeurDansTableau(source, listeSources[index]);
99
		sources[listeSources[index]] = estValeurDansTableau(source, listeSources[index]);
181
		overlayMaps[listeSources[index]] = new L.LayerGroup();
100
		overlayMaps[listeSources[index]] = new L.LayerGroup();
182
	}
101
	}
183
	L.control.layers(baseMaps, overlayMaps).addTo(map);
102
	L.control.layers(baseMaps, overlayMaps).addTo(map);
184
	coucheOSM.bringToFront();
103
	coucheOSM.bringToFront();
185
	couchePlanGoogle.bringToBack();
104
	map.removeLayer(coucheRelief);
186
	coucheSatelliteGoogle.bringToBack();
105
	map.removeLayer(coucheOSM);
187
	
106
	
188
	// garder par defaut la couche plan google comme selectionnee dans le panel
107
	// garder par defaut la couche plan google comme selectionnee dans le panel
189
	var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector');
108
	var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector');
190
	selecteursFonds[0].checked = true;
109
	selecteursFonds[0].checked = true;
191
	selecteursFonds[1].checked = false;
110
	selecteursFonds[1].checked = false;
192
	selecteursFonds[2].checked = false;
111
	selecteursFonds[2].checked = false;
193
}
112
}
194
 
113
 
195
function chargerLimitesCommunales() {
114
function chargerLimitesCommunales() {
196
	coucheDepartement = new L.KML(null, {async : true}).addTo(map);
115
	coucheDepartement = new L.KML(null, {async : true}).addTo(map);
197
	if (urlsLimitesCommunales != null) {
116
	if (urlsLimitesCommunales != null) {
198
		coucheDepartement.addKMLFiles(urlsLimitesCommunales);
117
		coucheDepartement.addKMLFiles(urlsLimitesCommunales);
199
	}
118
	}
200
}
119
}
201
 
120
 
202
function initialiserSources() {
121
function initialiserSources() {
203
	overlays = $('.leaflet-control-layers-overlays .leaflet-control-layers-selector');
122
	overlays = $('.leaflet-control-layers-overlays .leaflet-control-layers-selector');
204
	$.each(overlays, function (index, input) {
123
	$.each(overlays, function (index, input) {
205
		input.value = listeSources[index];
124
		input.value = listeSources[index];
206
		input.id = 'overlay' + (index+1);
125
		input.id = 'overlay' + (index+1);
207
		var lien = '<a href="' + liensVersSources[index] + '" target="_blank">' + nomListeSources[index] + '</a>';
126
		var lien = '<a href="' + liensVersSources[index] + '" target="_blank">' + nomListeSources[index] + '</a>';
208
		$('#overlay' + (index+1) + ' ~ span').html(lien);
127
		$('#overlay' + (index+1) + ' ~ span').html(lien);
209
		input.checked = sources[listeSources[index]];
128
		input.checked = sources[listeSources[index]];
210
		input.onclick = function(event) {
129
		input.onclick = function(event) {
211
			changerSource(event.target.value);
130
			changerSource(event.target.value);
212
		}
131
		}
213
	});
132
	});
214
}
133
}
215
 
134
 
216
function determinerSourcesSelectionnees() {
135
function changerSource(projetClique) {
217
	var sourcesSelectionnees = new Array();
136
	var indexProjetClique;
218
	for (source in sources) {
137
	for (var index = 0; index < overlays.length; index ++) {
219
		if (sources[source] == true) {
138
		if (overlays[index].value == projetClique) {
220
			sourcesSelectionnees.push(source);
139
			indexProjetClique = index;
221
		}
140
		}
-
 
141
	}
-
 
142
	masquerInfoBulle();
-
 
143
	sources[projetClique] = overlays[indexProjetClique].checked;
-
 
144
	if (sources[projetClique] == true) {
-
 
145
		programmerRafraichissementCarte(projetClique);
-
 
146
	} else {
-
 
147
		if (requeteEnCours()) {
-
 
148
			stopperRequeteAjax();
222
	}
149
		}
-
 
150
		supprimerFeaturesSource(projetClique);
223
	return sourcesSelectionnees;
151
	}
224
}
152
}
225
 
153
 
-
 
154
function supprimerFeaturesSource(source) {
226
function surChangementVueSurCarte() {
155
	if (coucheSites != null) {
-
 
156
		coucheSites.eachLayer(function(layer) {
227
	if (doitRafraichirCarte == false) {
157
			if (layer.typeSite == 'maille') {
-
 
158
				retirerStationsEtObservations(layer, source);
-
 
159
			} else {
-
 
160
				layer.supprimerSource(source, coucheSites);
-
 
161
				if (layer._map == 'null') {
-
 
162
					couheSites.removeLayer(layer);
-
 
163
				}
-
 
164
			}
-
 
165
		});
-
 
166
		if (typeSite == 'maille') {
228
		doitRafraichirCarte = true;
167
			var nombreMailles = calculerNombreMaillesVisibles();
229
	} else {
168
			if (nombreMailles == 0) {
230
		supprimerTousLayers();
169
				coucheSites.clearLayers();
-
 
170
				masquerLegende();
-
 
171
				typeSite = 'point';
231
		zoom = map.getZoom();
172
			}
232
		chargerMaillesVides();
173
		}
233
	}
174
	}
234
}
175
}
235
 
176
 
236
function chargerMaillesVides() {
177
function retirerStationsEtObservations(maille, sourceRetrait) {
-
 
178
	var sources = maille.properties.source;
-
 
179
	var nombreStations = 0;
-
 
180
	for (var index = 0; index < sources.length; index ++) {
237
	chargementMaillesEnCours = true;
181
		var source = sources[index];
238
	if (timer != null) {
182
		if (source == sourceRetrait) {
-
 
183
			delete maille.properties.stations[source];
-
 
184
			delete maille.properties.observations[source];
-
 
185
		} else if (typeof(maille.properties.stations[source]) != 'undefined') {
239
        window.clearTimeout(timer);
186
			nombreStations += parseInt(maille.properties.stations[source]);
-
 
187
		}
240
    }	
188
	}
-
 
189
	if (nombreStations == 0) {
-
 
190
		coucheSites.removeLayer(maille);
-
 
191
	} else {
241
	if (requeteChargementPoints != null) {
192
		colorerMaille(maille)
242
		stopperRequeteAjax();
193
		genererInfobulle(maille);		
243
	}
-
 
-
 
194
	}
-
 
195
}
244
	timer = window.setTimeout(function() {
196
 
245
		var coordonneesBordure = calculerCoordonneesBordure();
197
function calculerNombreMaillesVisibles() {
246
		var parametres = {
198
	var nombreMailles = 0;
247
				"source" : "floradata",
199
	coucheSites.eachLayer(function(layer) {
248
				"bbox" : coordonneesBordure,
200
		if($(layer._path).attr('fill-opacity') != '0') {
249
				"zoom" : map.getZoom()
201
			nombreMailles ++;
-
 
202
		}
-
 
203
	});
-
 
204
	return nombreMailles;
-
 
205
}
-
 
206
 
-
 
207
function estValeurDansTableau(tableau, valeur) {
250
			};
208
	var index;
251
			url = urlBase + "mailles?" + convertirEnParametresUrl(parametres);
209
	for (index = 0; index < tableau.length && tableau[index] != valeur; index ++);
-
 
210
	return (tableau.length > 0 && index != tableau.length);
-
 
211
}
-
 
212
 
252
			fonctionCallback = traiterDonneesStations;
213
//************************************
-
 
214
// requetes stations
-
 
215
 
253
			executerAJAX();
216
function surChangementVueCarte() {
254
	}, 400);
217
	programmerRafraichissementCarte();
255
}
218
}
256
 
219
 
257
function programmerRafraichissementCarte(source) {
220
function programmerRafraichissementCarte(source) {
-
 
221
	$('#tooltip').css('display', 'none');
258
	source = (source == null || source == 'null') ? null : source;
222
	source = (source == null || source == 'null') ? null : source;
259
	if (!chargementMaillesEnCours) {
-
 
260
		if (timer != null) {
223
	if (timer != null) {
261
			window.clearTimeout(timer);
224
		window.clearTimeout(timer);
262
		}
225
	}
263
		if (requeteChargementPoints != null) {
226
	if (requeteChargementPoints != null) {
264
			if (source == null) {
-
 
265
				stopperRequeteAjax();
227
		stopperRequeteAjax();
266
			}
228
	}
-
 
229
	var nombreSourcesVisibles = 0;
-
 
230
	for (var index = 0; index < overlays.length; index ++) {
-
 
231
		if (overlays[index].checked) {
-
 
232
			nombreSourcesVisibles ++;
267
		}
233
		}
-
 
234
	}
-
 
235
	if (source == null) {
268
		timer = window.setTimeout("rafraichirDonnnees('"+source+"')", 250);
236
		timer = window.setTimeout("chargerLocalisations()", 100);
269
    } else {
237
	} else {
270
    	window.setTimeout("programmerRafraichissementCarte('"+source+"')", 400);
238
		timer = window.setTimeout("chargerSource('"+source+"')", 100);
271
    }
239
	}
272
}
240
}
273
 
241
 
274
function stopperRequeteAjax() {
242
function stopperRequeteAjax() {
275
	requeteChargementPoints.abort();
243
	requeteChargementPoints.abort();
276
	requeteChargementPoints = null;
244
	requeteChargementPoints = null;
277
}
245
}
278
 
-
 
279
function rafraichirDonnnees(source) {
-
 
280
	source = (source == null || source == 'null') ? null : source;
-
 
281
	if (coucheDepartement == null || coucheDepartement.getStatus() == KML_READY) {
-
 
282
		if (source != null) {
-
 
283
			chargerLocalisations(source);
-
 
284
		} else {
246
 
285
			supprimerLocalisations();
247
function chargerLocalisations() {
286
			for (source in sources) {
-
 
287
				if (sources[source] == true) {
248
	if (requeteEnCours()) {
288
					chargerLocalisations(source);
-
 
289
				}
-
 
290
			}
-
 
291
		}
-
 
292
	} else {
-
 
293
		window.setTimeout("rafraichirDonnnees('"+source+"')", 800);
249
		requeteChargementPoints.abort();
-
 
250
	}
-
 
251
	afficherMessageChargement('stations');
-
 
252
	if (!(ancienneRequete != null && ancienneRequete[1] == map.getZoom()
-
 
253
		&& map.getBounds().intersects(ancienneRequete[0]))) {	
-
 
254
		supprimerFeatures();
-
 
255
		deplacement = false;
-
 
256
	}
-
 
257
	var bboxRequete = calculerBboxRequete();
-
 
258
	var parametres = {
-
 
259
		"bbox" : bboxRequete,
-
 
260
		"zoom" : map.getZoom(),
-
 
261
		"source" : recupererSourcesActivees(),
-
 
262
		"num_taxon" : numTaxon,
-
 
263
		"nn" : nn,
-
 
264
		"referentiel" : referentiel,
-
 
265
		"dept" : dept,
-
 
266
		"auteur" : auteur,
-
 
267
		"date_debut" : dateDebut,
-
 
268
		"date_fin" : dateFin,
-
 
269
		"nb_jours" : nbJours
-
 
270
	};
-
 
271
	if (deplacement == true) {
-
 
272
		parametres.format = typeSite;
-
 
273
	}
-
 
274
	ancienneRequete = [map.getBounds(), map.getZoom()];
-
 
275
	url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
-
 
276
	fonctionCallback = traiterDonneesStations;
294
	}
277
	executerAJAX();
295
}
278
}
-
 
279
 
296
 
280
function supprimerFeatures() {
297
function supprimerTousLayers() {
281
	if (coucheSites != null) {
298
	coucheSites.clearLayers();
282
		coucheSites.clearLayers();
299
	points = [];
283
		coucheSites = null;
300
	formeDonnees = '';
284
	}
301
}
285
}
302
 
286
 
303
function supprimerLocalisations(source) {
287
function recupererSourcesActivees(sourceAIgnorer) {
304
	source = (typeof(source) == 'undefined') ? null : source;
288
	sourceAIgnorer = typeof(sourceAIgnorer) == 'undefined' ? '' : sourceAIgnorer;
305
	if (source != null) {
-
 
306
		var sourceUrl = recupererParametreDansUrl('source', url);
-
 
307
		if (requeteChargementPoints != null && sourceUrl == source && source != null) {
-
 
308
			stopperRequeteAjax();
-
 
309
		}
-
 
310
		coucheSites.eachLayer(function(layer) {
-
 
311
			supprimerLayer(layer, source);
-
 
312
		});
-
 
313
		if (source != null) {
289
	var sourcesActivees = [];
314
			supprimerPointsListe(source);
-
 
315
		}
-
 
316
		var sourcesSelectionnees = determinerSourcesSelectionnees();
290
	for (var index = 0; index < overlays.length; index ++) {
317
		if (sourcesSelectionnees.length == 1 && determinerNombreMarqueurs(sourcesSelectionnees[0]) > 0) {
-
 
318
			transformerMaillesEnPoints(sourcesSelectionnees[0]);
-
 
319
		}
291
		if (overlays[index].checked == true && overlays[index].value != sourceAIgnorer) {
-
 
292
			sourcesActivees.push(overlays[index].value);
320
		var sontPointsAffiches = (points.length>0 && determinerNombreMailles(false)==0);
293
		}
321
		formeDonnees = sontPointsAffiches ? 'point' : 'maille';
294
	}
-
 
295
	return sourcesActivees.join(',');
-
 
296
}
-
 
297
 
-
 
298
function chargerSource(sourceAjout) {
-
 
299
	if (requeteEnCours()) {
-
 
300
		requeteChargementPoints.abort();
-
 
301
	}
-
 
302
	afficherMessageChargement('stations');
-
 
303
	var bboxRequete = determinerCoordonneesBordure();
-
 
304
	var parametres = {
-
 
305
		"bbox" : bboxRequete,
-
 
306
		"zoom" : map.getZoom(),
-
 
307
		"format" : typeSite,
-
 
308
		"source" : sourceAjout,
-
 
309
		"num_taxon" : numTaxon,
-
 
310
		"nn" : nn,
-
 
311
		"referentiel" : referentiel,
-
 
312
		"dept" : dept,
-
 
313
		"auteur" : auteur,
-
 
314
		"date_debut" : dateDebut,
-
 
315
		"date_fin" : dateFin,
-
 
316
		"nb_jours" : nbJours
322
	}
317
	};
-
 
318
	ancienneRequete = [map.getBounds(), map.getZoom()];
-
 
319
	url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
-
 
320
	fonctionCallback = traiterRetourChargementSource;
-
 
321
	executerAJAX();
-
 
322
}
-
 
323
 
-
 
324
function calculerBboxRequete() {
323
}
325
	var bordure = map.getBounds();
-
 
326
	var bboxRequete = "";
324
 
327
	if (ancienneRequete != null && ancienneRequete[1] == map.getZoom()
325
function estLayerUtilisePourSource(layer, source) {
328
		&& bordure.intersects(ancienneRequete[0])) {
-
 
329
		bboxRequete = calculerIntersectionRectangle(ancienneRequete[0], bordure);
326
	return (
330
	} else {
327
		(layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[source]) != 'undefined') ||
331
		bboxRequete = determinerCoordonneesBordure();
-
 
332
	}
-
 
333
	return bboxRequete;
-
 
334
}
-
 
335
 
-
 
336
function calculerIntersectionRectangle(rectangle1, rectangle2) {
328
		(layer.typeSite != 'MAILLE' && layer.source == source)
337
	var bbox1 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6),
-
 
338
	    rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)];
-
 
339
	var bbox2 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6),
329
	);
340
	    rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)];
-
 
341
	
-
 
342
	if (rectangle2.getSouthWest().lng >= rectangle1.getSouthWest().lng
-
 
343
	 	&& rectangle2.getSouthWest().lng <= rectangle1.getNorthEast().lng) {
-
 
344
		bbox2[0] = bbox1[2] = rectangle1.getNorthEast().lng.toFixed(6);
-
 
345
		if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat
-
 
346
			&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) {
-
 
347
			bbox1[1] = rectangle1.getNorthEast().lat.toFixed(6);
-
 
348
		} else {
-
 
349
			bbox1[3] = rectangle1.getSouthWest().lat.toFixed(6);
330
}
350
		}
331
 
351
	} else {
332
function supprimerLayer(layer, source) {
352
		bbox2[0] = bbox1[2] = rectangle1.getSouthWest().lng.toFixed(6);
333
	if (estLayerUtilisePourSource(layer, source)) {
353
		if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat
334
		if (layer.typeSite == 'MAILLE') {
354
			&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) {
-
 
355
			bbox2[1] = rectangle1.getNorthEast().lat.toFixed(6);
335
			supprimerSourceDansMaille(layer, source);
356
		} else {
336
		} else {
-
 
337
			coucheSites.removeLayer(layer);
357
			bbox2[3] = rectangle1.getSouthWest().lat.toFixed(6);
338
		}
358
		}
-
 
359
	}
339
	}
360
	return bbox1.join(',')+'|'+bbox2.join(',');
-
 
361
}
-
 
362
 
-
 
363
function determinerCoordonneesBordure() {
340
}
364
	var ouest = map.getBounds().getSouthWest().lng.toFixed(6),
-
 
365
		sud = Math.max(map.getBounds().getSouthWest().lat, -85.051129).toFixed(6),
341
 
366
		est = map.getBounds().getNorthEast().lng.toFixed(6),
342
 
367
		nord = Math.min(map.getBounds().getNorthEast().lat, 85.051129).toFixed(6);
343
function changerSource(projetClique) {
368
	// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees
344
	var indexProjetClique;
369
	// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur)
345
	for (var index = 0; index < overlays.length; index ++) {
-
 
346
		if (overlays[index].value == projetClique) {
370
	if (ouest < -180) {
347
			indexProjetClique = index;
371
		ouest += 360;
348
		}
372
	} else if (ouest > 180) {
349
	}
-
 
350
	masquerInfoBulle();
373
		ouest -= 360;
-
 
374
	}
351
	sources[projetClique] = overlays[indexProjetClique].checked;
375
	if (est < -180) {
352
	if (sources[projetClique] == true) {
376
		est += 360;
353
		programmerRafraichissementCarte(projetClique);
377
	} else if (est > 180) {
354
	} else {
378
		est -= 360;
355
		supprimerLocalisations(projetClique);
379
	}
356
	}
380
	return [ouest, sud, est, nord].join(',');
357
}
381
}
358
 
382
 
359
function afficherMessageChargement(element) {
383
function afficherMessageChargement(element) {
360
	if ($("#zone-chargement").css('display') == 'none') {
384
	if ($("#zone-chargement").css('display') == 'none') {
361
		var divTmplElement = 'tpl-chargement-' + element;
385
		var divTmplElement = 'tpl-chargement-' + element;
362
		$("#zone-chargement").append($("#" + divTmplElement).text());
386
		$("#zone-chargement").append($("#" + divTmplElement).text());
363
		$("#zone-chargement").css('display', 'block');
387
		$("#zone-chargement").css('display', 'block');
364
	}
388
	}
365
}
389
}
366
 
390
 
367
function masquerMessageChargement() {
391
function masquerMessageChargement() {
368
	$("#zone-chargement").css('display', 'none');
392
	$("#zone-chargement").css('display', 'none');
369
	$("#zone-chargement").children().remove();
393
	$("#zone-chargement").children().remove();
370
}
394
}
371
 
-
 
372
 
-
 
373
// execution d'une requete AJAX
395
 
374
function executerAJAX() {
396
function executerAJAX() {
375
	if (requeteEnCours()) {
-
 
376
		masquerMessageChargement();
397
	if (requeteEnCours()) {
377
		requeteChargementPoints.abort();
398
		requeteChargementPoints.abort();
378
	}
399
	}
379
	requeteChargementPoints = $.getJSON(url).complete(function() {
400
	requeteChargementPoints = $.getJSON(url).complete(function() {
380
		fonctionCallback();
401
		fonctionCallback();
381
	});
402
	});
382
}
403
}
383
 
404
 
384
function requeteEnCours() {
405
function requeteEnCours() {
385
	return (requeteChargementPoints != null && requeteChargementPoints.readyState != 4);
406
	return (requeteChargementPoints != null && requeteChargementPoints.readyState != 4);
386
}
407
}
387
 
408
 
388
function estStatutRequeteOK() {
409
function estStatutRequeteOK() {
389
	return ((requeteChargementPoints.status == 200 || requeteChargementPoints.status == 304)
410
	return ((requeteChargementPoints.status == 200 || requeteChargementPoints.status == 304)
390
		|| requeteChargementPoints.status == 0);
411
		|| requeteChargementPoints.status == 0);
391
}
412
}
392
 
413
 
393
function chargerLocalisations(source) {
-
 
394
	if (requeteEnCours()) {
-
 
395
		window.setTimeout("chargerLocalisations('"+source+"')", 400);
-
 
396
	} else {
-
 
397
		afficherMessageChargement('stations');
-
 
398
		// generer l'URL du script a interroger sur le serveur
-
 
399
		var coordonneesBordure = calculerCoordonneesBordure();
414
function convertirEnParametresUrl(objet) {
400
		var parametres = {
-
 
401
			"source" : source,
415
	var parametresUrl = '';
402
			"num_taxon" : numTaxon,
416
	for (attribut in objet) {
403
			"referentiel" : referentiel,
-
 
404
			"dept" : dept,
-
 
405
			"nn" : nn,
-
 
406
			"auteur" : auteur,
417
		if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' ||
407
			"date_debut" : dateDebut,
418
			objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0)
408
			"date_fin" : dateFin,
-
 
409
			"bbox" : coordonneesBordure,
-
 
410
			"nb_jours" : nbJours,
-
 
411
			"zoom" : map.getZoom()
-
 
412
		};
419
			continue;
413
		url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
-
 
414
		fonctionCallback = traiterDonneesStations;
-
 
415
		executerAJAX();
420
		parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut];
-
 
421
	}
416
	}
422
	return parametresUrl;
417
}
423
};
418
 
424
 
419
function calculerCoordonneesBordure() {
-
 
420
	var bordure = map.getBounds();
-
 
421
	var ouest = bordure.getSouthWest().lng.toFixed(6),
-
 
422
		sud = Math.max(bordure.getSouthWest().lat, -85.051129).toFixed(6),
-
 
423
		est = bordure.getNorthEast().lng.toFixed(6),
-
 
424
		nord = Math.min(bordure.getNorthEast().lat, 85.051129).toFixed(6);
-
 
425
	// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees
-
 
426
	// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur)
425
function traiterDonneesStations() {
427
	if (ouest < -180) {
426
	masquerMessageChargement();
428
		ouest += 360;
427
	masquerLegende();
429
	} else if (ouest > 180) {
428
	if (deplacement == true) {
-
 
429
		supprimerFeaturesHorsBbox();
-
 
430
	}
430
		ouest -= 360;
431
	deplacement = true;
431
	}
432
	var texte = requeteChargementPoints.responseText;
432
	if (est < -180) {
433
	if (!estStatutRequeteOK()) {
-
 
434
		alert(texte);
-
 
435
	} else {
-
 
436
		var donneesJSON = eval("(function(){return " + texte + ";})()");
433
		est += 360;
437
		if (donneesJSON != null && donneesJSON.features.length > 0) {
434
	} else if (est > 180) {
438
			ajouterStationsSurCarte(donneesJSON);
435
		est -= 360;
-
 
436
	}
439
		}
437
	return [ouest, sud, est, nord].join(',');
440
	}
438
}
441
}
439
 
442
 
440
function traiterDonneesStations() {
443
function traiterRetourChargementSource() {
441
	masquerMessageChargement();
444
	masquerMessageChargement();
442
	var texte = requeteChargementPoints.responseText;
445
	var texte = requeteChargementPoints.responseText;
443
	if (!estStatutRequeteOK()) {
446
	if (!estStatutRequeteOK()) {
444
		alert(texte);
447
		alert(texte);
445
	} else {
448
	} else {
446
		var donneesJSON = eval("(function(){return " + texte + ";})()");
449
		var donneesJSON = eval("(function(){return " + texte + ";})()");
447
		if (donneesJSON != null && typeof(donneesJSON.features) != 'undefined') {
450
		if (donneesJSON != null && donneesJSON.features.length > 0) {
-
 
451
			var formatRetourDifferent = donneesJSON.stats.formeDonnees != typeSite;
448
			ajouterStationsSurCarte(donneesJSON);
452
			ajouterStationsSurCarte(donneesJSON);
-
 
453
			if (formatRetourDifferent) {
-
 
454
				var sourceAIgnorer = donneesJSON.stats.source[0];
-
 
455
				var sourcesARecharger = recupererSourcesActivees(sourceAIgnorer);
-
 
456
				rechargerSources(sourcesARecharger);
-
 
457
			}
449
		}
458
		}
450
	}
459
	}
451
}
460
}
452
 
461
 
-
 
462
function supprimerFeaturesHorsBbox() {
-
 
463
	var bordure = map.getBounds();
-
 
464
	var layersRestants = 0;
453
function ajouterStationsSurCarte(data) {
465
	if (coucheSites != null) {
454
	if (doitTransformerEnMaille(data.stats)) {
466
		coucheSites.eachLayer(function(layer) {
455
		if (points.length > 0 && data.stats.source != '') {
467
			if (typeof(layer._latlng) != 'undefined') {
456
			combinerMaillesEtPoints();
-
 
457
		}
468
				if (bordure.contains(layer.getLatLng())) {
458
		formeDonnees = 'maille';
469
					layersRestants ++;
459
	} else {
470
				} else {
460
		formeDonnees = data.stats.formeDonnees;
471
					coucheSites.supprimerPoint(layer);
461
	}
472
				}
462
	var sourceDonnees = data.stats.source;
473
			} else {
463
	for (var index = 0; index < data.features.length; index ++) {
474
				if (bordure.intersects(layer.getBounds())) {
464
		ajouterStation(data.features[index]);
-
 
465
	}
-
 
466
	if (formeDonnees == 'maille' && data.stats.sites > 0) {
475
					layersRestants ++;
467
		afficherLegende();
476
				} else {
468
		regenererInfobulleMailles();
477
					coucheSites.removeLayer(layer);
-
 
478
				}
469
	} else {
479
			}
470
		masquerLegende();
480
		});
471
	}
481
	}
472
	if (chargementMaillesEnCours) {
482
	if (layersRestants == 0) {
473
		chargementMaillesEnCours = false;
-
 
474
		programmerRafraichissementCarte();
483
		coucheSites = null;
475
	}
484
	}
476
}
485
}
477
 
486
 
478
function ajouterStation(feature) {
487
function rechargerSources(sourcesARecharger) {
479
	if (feature.properties.typeSite == 'MAILLE') {
488
	var listeSourcesASupprimer = sourcesARecharger.split(',');
480
		traiterMaille(feature);
-
 
481
	} else {
489
	for (var index = 0; index < listeSourcesASupprimer.length; index ++) {
482
		ajouterPoint(feature);
490
		supprimerFeaturesSource(listeSourcesASupprimer[index]);
-
 
491
	}
483
	}
492
	chargerSource(sourcesARecharger);
484
}
493
}
485
 
494
 
-
 
495
function ajouterStationsSurCarte(donnees) {
486
function doitTransformerEnMaille(statsFeatures) {
496
	typeSite = donnees.stats.formeDonnees;
487
	var condition1 = (formeDonnees == 'point' && statsFeatures.formeDonnees =='maille');
497
	if (coucheSites == null) {
-
 
498
		coucheSites = (typeSite == 'maille') ? new L.FeatureGroup() : new L.ClusterGroup();
488
	var condition2 = (formeDonnees == 'maille' && statsFeatures.formeDonnees =='point'
499
		map.addLayer(coucheSites);
-
 
500
	}
-
 
501
	for (var index = 0; index < donnees.features.length; index ++) {
-
 
502
		var feature = donnees.features[index];
-
 
503
		if (typeSite == 'maille') {
-
 
504
			traiterMaille(feature);
-
 
505
		} else {
-
 
506
			ajouterPoint(feature);
489
		&& determinerNombreMailles(false) > 0);
507
		}
-
 
508
	}
-
 
509
	if (donnees.features.length > 0) {
-
 
510
		afficherLegende();
-
 
511
	}
-
 
512
	if (typeSite == 'maille') {
490
	var condition3 = (statsFeatures.formeDonnees == 'point' && map.getZoom() <= ZOOM_MAXIMUM_MAILLAGE
513
		genererInfobulleMailles();
-
 
514
	} else {
491
		&& (points.length+statsFeatures.sites) > SEUIL_MAILLAGE);
515
		coucheSites.afficherClusters();
492
	return (condition1 || condition2 || condition3);
-
 
493
}
-
 
494
 
516
	}
495
 
517
}
496
 
-
 
497
// ====================================================================
-
 
498
// Gestion des mailles
-
 
499
 
-
 
500
var optionsMaille = {
-
 
501
	color: '#FFFFFF',
-
 
502
	opacity : 0.7,
-
 
503
	weight: 1,
-
 
504
	fillOpacity : 0.6
-
 
505
};
-
 
506
 
-
 
507
function determinerNombreMailles(prendToutesMailles) {
-
 
508
	var nombreMailles = 0;
-
 
509
	coucheSites.eachLayer(function(layer) {
-
 
510
		if ('typeSite' in layer && layer.typeSite == 'MAILLE') {
-
 
511
			var nombrePoints = 0;
-
 
512
			for (var source in layer.nombrePoints) {
-
 
513
				nombrePoints = layer.nombrePoints[source];
-
 
514
			}
-
 
515
			if (prendToutesMailles || nombrePoints>0) {
-
 
516
				nombreMailles ++;
-
 
517
			}
-
 
518
		}
-
 
519
	});
518
 
520
	return nombreMailles;
519
// =========================================
521
}
520
// Gestion des mailles
522
 
521
 
523
function traiterMaille(feature) {
522
function traiterMaille(feature) {
524
	var coordonnees = [];
523
	var coordonnees = [];
525
	for (var i = 0; i < feature.geometry.coordinates.length; i++) {
524
	for (var i = 0; i < feature.geometry.coordinates.length; i++) {
526
		var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]);
525
		var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]);
527
		coordonnees.push(sommet);
526
		coordonnees.push(sommet);
528
	}
527
	}
529
	var maille = rechercherMailleExistante(coordonnees);
528
	var maille = rechercherMailleExistante(coordonnees);
530
	if (maille) {
529
	if (maille) {
531
		mettreAJourMaille(maille, feature);
530
		mettreAJourMaille(maille, feature);
532
	} else if (feature.properties.nombrePoints > 0) {
531
	} else {
533
		ajouterMaille(feature);
532
		maille = ajouterMaille(feature, coordonnees);
534
	}
533
	}
-
 
534
	colorerMaille(maille);
535
}
535
}
536
 
536
 
537
function rechercherMailleExistante(coordonnees) {
537
function rechercherMailleExistante(coordonnees) {
538
	var mailleTrouvee = null;
538
	var mailleTrouvee = null;
539
	coucheSites.eachLayer(function(layer) {
539
	coucheSites.eachLayer(function(layer) {
540
		if ('typeSite' in layer && layer.typeSite == 'MAILLE') {
540
		if ('typeSite' in layer && layer.typeSite == 'maille') {
541
			if (sontMaillesIdentiques(coordonnees, layer._latlngs)) {
541
			if (sontMaillesIdentiques(coordonnees, layer._latlngs)) {
542
				mailleTrouvee = layer;
542
				mailleTrouvee = layer;
543
				return;
543
				return;
544
			}
544
			}
545
		}
545
		}
546
	});
546
	});
547
	return mailleTrouvee;
547
	return mailleTrouvee;
548
}
548
}
549
 
549
 
550
function sontMaillesIdentiques(coordonnees1, coordonnees2) {
550
function sontMaillesIdentiques(coordonnees1, coordonnees2) {
551
	return (
551
	return (
552
		coordonnees1[0].lat == coordonnees2[0].lat &&
552
		coordonnees1[0].lat == coordonnees2[0].lat &&
553
		coordonnees1[0].lng == coordonnees2[0].lng &&
553
		coordonnees1[0].lng == coordonnees2[0].lng &&
554
		coordonnees1[2].lat == coordonnees2[2].lat &&
554
		coordonnees1[2].lat == coordonnees2[2].lat &&
555
		coordonnees1[2].lng == coordonnees2[2].lng
555
		coordonnees1[2].lng == coordonnees2[2].lng
556
	);
556
	);
557
}
557
}
558
 
558
 
559
function ajouterMaille(feature) {
-
 
560
	var coordonnees = [];
-
 
561
	for (var i = 0; i < feature.geometry.coordinates.length; i++) {
-
 
562
		var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]);
-
 
563
		coordonnees.push(sommet);
-
 
564
	}
559
function ajouterMaille(feature, coordonnees) {
-
 
560
	var maille = new L.Polygon(coordonnees);
-
 
561
	var optionsMaille = {
-
 
562
		color: '#FFFFFF',
-
 
563
		opacity : 0.7,
-
 
564
		weight: 1,
-
 
565
		fillOpacity : 0.6
565
	var maille = new L.Polygon(coordonnees);
566
	};
566
	maille.setStyle(optionsMaille);
567
	maille.setStyle(optionsMaille);
567
	maille.typeSite = feature.properties.typeSite;
568
	maille.typeSite = 'maille';
568
	maille.nombrePoints = new Object();
-
 
569
	var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints);
-
 
570
	maille.nombrePoints[feature.properties.source] = nombreAAjouter;
569
	maille.properties = feature.properties;
571
	coucheSites.addLayer(maille);
570
	coucheSites.addLayer(maille);
572
	colorerMaille(maille);
571
	return maille;
573
}
572
}
574
 
573
 
575
function mettreAJourMaille(maille, feature) {
574
function mettreAJourMaille(maille, feature) {
576
	var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints);
575
	var sources = feature.properties.source;
577
	/*if (typeof(maille.nombrePoints[feature.properties.source]) == 'undefined') {
576
	for (var index = 0; index < sources.length; index ++) {
578
		maille.nombrePoints[feature.properties.source] = nombreAAjouter;
577
		var source = sources[index];
579
	} else {
-
 
580
		maille.nombrePoints[feature.properties.source] += nombreAAjouter;
578
		maille.properties.stations[source] = parseInt(feature.properties.stations[source]);
581
	}*/
-
 
582
	maille.nombrePoints[feature.properties.source] = nombreAAjouter;
579
		maille.properties.observations[source] = parseInt(feature.properties.observations[source]);
583
	colorerMaille(maille);
-
 
584
}
-
 
585
 
-
 
586
function regenererInfobulleMailles() {
-
 
587
	$('.leaflet-clickable').addClass('tooltip');
-
 
588
	coucheSites.eachLayer(function(layer) {
-
 
589
		if (layer.typeSite == 'MAILLE') {
-
 
590
			genererInfobulle(layer);
580
		maille.properties.source.push(source);
591
		}
581
	}
592
	});
-
 
593
}
582
}
594
 
583
 
595
function colorerMaille(maille) {
584
function colorerMaille(maille) {
596
	var nombrePoints = 0;
585
	var nombreStations = 0;
597
	for (sourceMaille in maille.nombrePoints) {
586
	var sources = maille.properties.source;
-
 
587
	for (var index = 0; index < sources.length; index ++) {
-
 
588
		var source = sources[index];
-
 
589
		if (typeof(maille.properties.stations[source]) != 'undefined') {
598
		nombrePoints += maille.nombrePoints[sourceMaille];
590
			nombreStations += parseInt(maille.properties.stations[source]);
-
 
591
		}
599
	}
592
	}
600
	if (nombrePoints > 0) {
593
	if (nombreStations > 0) {
601
		maille.on('click', surClicMaille);
594
		maille.on('click', surClicMaille);
602
		maille.setStyle({fillColor : genererCouleur(nombrePoints), fillOpacity: 0.45, opacity: 0.7});
595
		maille.setStyle({fillColor : genererCouleur(nombreStations), fillOpacity: 0.45, opacity: 0.7});
603
	} else {
596
	} else {
604
		maille.setStyle({fillOpacity: 0, opacity: 0});
597
		maille.setStyle({fillOpacity: 0, opacity: 0});
605
		maille.off('click', surClicMaille);
598
		maille.off('click');
606
	}
599
	}
607
}
600
}
608
 
-
 
609
function surClicMaille(event) {
-
 
610
	map.fitBounds(event.layer.getBounds());
-
 
611
}
-
 
612
 
601
 
613
function genererCouleur(nombrePoints) {
602
function genererCouleur(nombrePoints) {
614
	var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64},
603
	var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64},
615
		seuils = [1, 10, 50 ,100, 500, 1000, 2500],
604
		seuils = [1, 10, 50 ,100, 500, 1000, 2500],
616
		pas = 26,
605
		pas = 26,
617
		position = 0;
606
		position = 0;
618
	for (var index = 1; index < seuils.length-1 && nombrePoints >= seuils[index]; index ++) {
607
	for (var index = 1; index < seuils.length-1 && nombrePoints >= seuils[index]; index ++) {
619
		position ++;
608
		position ++;
620
	}
609
	}
621
	couleur.vert -= position*pas;
610
	couleur.vert -= position*pas;
622
	return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')';
611
	return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')';
623
}
612
}
-
 
613
 
-
 
614
function surClicMaille(event) {
-
 
615
	map.fitBounds(event.layer.getBounds());
-
 
616
}
624
 
617
 
625
function afficherLegende() {
618
function afficherLegende() {
626
	if (legende == null) {
619
	if (legende == null) {
627
		legende = new L.Control({position : 'bottomright'});
620
		legende = new L.Control({position : 'bottomright'});
628
		legende.onAdd = function(map) {
621
		legende.onAdd = function(map) {
-
 
622
			var contenuHtml = '';
-
 
623
			if (typeSite == 'maille') {
-
 
624
				contenuHtml = construireContenuHtmlLegendeMailles();
-
 
625
			} else {
629
			return construireContenuHtmlLegende();
626
				contenuHtml = construireContenuHtmlLegendePoints(); 
-
 
627
			}
-
 
628
			return contenuHtml;
630
		};
629
		};
631
		map.addControl(legende);
630
		map.addControl(legende);
632
	}
631
	}
633
}
632
}
634
 
633
 
635
function construireContenuHtmlLegende() {
634
function construireContenuHtmlLegendeMailles() {
636
	var div = L.DomUtil.create('div', 'info');
635
	var div = L.DomUtil.create('div', 'info');
637
	div.innerHTML = '<h4>' + titreLegende + '</h4>';
636
	div.innerHTML = '<h4>' + titreLegende + '</h4>';
638
	var seuils = [1, 10, 50 ,100, 500, 1000, 2500];
637
	var seuils = [1, 10, 50 ,100, 500, 1000, 2500];
639
	var labels = [];
638
	var labels = [];
640
	for (var i = 0; i < seuils.length; i ++) {
639
	for (var i = 0; i < seuils.length; i ++) {
641
		div.innerHTML += 
640
		div.innerHTML += 
642
			'<div class="legend">'+
641
			'<div class="legend">'+
643
				'<span style="background:' + genererCouleur(seuils[i] + 1) + '"></span>'+
642
				'<span class="couleur-maille" style="background:' + genererCouleur(seuils[i] + 1) + '">'+
644
				seuils[i]+ (i + 1 < seuils.length ? '&ndash;' + seuils[i + 1] : '+')+
643
				'</span>'+seuils[i]+ (i + 1 < seuils.length ? '&ndash;' + seuils[i + 1] : '+')+
645
			'</div>';
644
			'</div>';
646
	}
645
	}
647
	return div;
646
	return div;
648
}
647
}
649
 
648
 
650
function masquerLegende() {
649
function masquerLegende() {
651
	if (legende != null) {
650
	if (legende != null) {
652
		map.removeControl(legende);
651
		map.removeControl(legende);
653
		legende = null;
652
		legende = null;
654
	}
653
	}
655
}
654
}
656
 
655
 
657
function supprimerSourceDansMaille(maille, sourceSuppression) {
-
 
658
	if (typeof(maille.nombrePoints[sourceSuppression]) != 'undefined') {
656
function genererInfobulleMailles() {
659
		maille.nombrePoints[sourceSuppression] = 0;
657
	coucheSites.eachLayer(function(layer) {
660
		colorerMaille(maille);
658
		if (layer.typeSite == 'maille') {
661
		genererInfobulle(maille);
659
			genererInfobulle(layer);
-
 
660
		}
662
	}
661
	});
663
}
662
}
664
 
663
 
665
function genererInfobulle(maille) {
664
function genererInfobulle(maille) {
666
	var nombrePoints = 0,
665
	var sources = maille.properties.source;
667
		nombreSources = 0;
-
 
668
		contenuTexte = '';
666
	var textes = new Array();
669
	for (sourceMaille in maille.nombrePoints) {
667
	for (var index = 0; index < sources.length; index ++) {
670
		nombrePoints = maille.nombrePoints[sourceMaille];
668
		var source = sources[index];
671
		if (nombrePoints > 0) {
669
		if (typeof(maille.properties.stations[source]) != 'undefined') {
672
			contenuTexte += (contenuTexte.length==0 ?'' : '\n')+
670
			textes.push(source+" : "+maille.properties.stations[source]+" stations, "
673
				sourceMaille+' : '+maille.nombrePoints[sourceMaille];
671
				+maille.properties.observations[source]+" observations");
674
		}
672
		}
-
 
673
	}
-
 
674
	var contenu = textes.join('<br />');
-
 
675
	maille.on('mouseover', function() {
-
 
676
		afficherTooltip(contenu, map.latLngToContainerPoint(maille.getBounds().getSouthWest()));
-
 
677
	});
675
		nombreSources ++;
678
	maille.on('mouseout', function() {
-
 
679
		$("#tooltip").css('display', 'none');
-
 
680
	});
676
	}
681
}
-
 
682
 
-
 
683
function afficherTooltip(texte, point) { 
-
 
684
	$("#tooltip").html(texte);
-
 
685
	if ($("#tooltip").css('display') == 'none') {
677
	if (nombreSources > 0) {
686
		var x = point.x - 15;
-
 
687
		var y = point.y + (typeSite == 'maille' ? 1 : 10);
-
 
688
		$("#tooltip").css('display', 'block');
678
		$(maille._path).addClass('tooltip');
689
		$("#tooltip").css('left', x + 'px');
679
		$(maille._path).attr('title',contenuTexte);
690
		$("#tooltip").css('top', y + 'px');
680
	}
691
	}
681
}
692
}
682
 
693
 
683
 
694
 
684
 
695
 
685
 
696
 
686
// ====================================================================
697
// ====================================================================
687
// Gestion des marqueurs
698
// Gestion des points
688
 
699
 
689
function ajouterPoint(feature) {
700
function ajouterPoint(feature) {
690
	var iconePoint = new L.Icon({ iconUrl : pointImageUrl,   iconSize : [16, 16] }),
701
	var iconePoint = new L.Icon({ iconUrl : pointImageUrl,   iconSize : [16, 16] }),
691
		iconeCommune   = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }),
702
		iconeCommune   = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }),
692
		icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune,
703
		icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune,
693
		point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]),
704
		point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]);
694
		marker = new L.Marker(point, {
705
	var marker = new L.Cluster(point, {
695
			icon  : icone,
706
		icon  : icone,
696
			title : feature.properties.nom
707
		titre : feature.properties.nom
697
		})
708
	});
698
	marker.typeSite = feature.properties.typeSite;
709
	marker.typeSite = feature.properties.typeSite.toLowerCase();
699
	marker.source = feature.properties.source;
710
	marker.source = feature.properties.source;
700
	marker.on('click', surClicMarqueur);
711
	marker.on('click', surClicMarqueur);
701
	points.push(marker);
-
 
702
	if (formeDonnees != 'maille') {
-
 
703
		coucheSites.addLayer(marker);
-
 
704
	} else {
-
 
705
		ajouterPointDansMaille(marker);
-
 
706
	}
-
 
707
}
-
 
708
 
-
 
709
function ajouterPointDansMaille(point) {
-
 
710
	var maille = null;
-
 
711
	coucheSites.eachLayer(function(layer) {
712
	marker.on('mouseover', function() {
712
		if (layer.typeSite == 'MAILLE' && layer.getBounds().contains(point.getLatLng())) {
713
		afficherTooltip(marker.options.titre, map.latLngToContainerPoint(marker.getLatLng()));
713
			maille = layer;
-
 
714
			return;
-
 
715
		}
-
 
716
	});
714
	});
717
	if (typeof(maille.nombrePoints[point.source]) == 'undefined') {
-
 
718
		maille.nombrePoints[point.source] = 1;
-
 
719
	} else {
-
 
720
		maille.nombrePoints[point.source] += 1;
-
 
721
	}
-
 
722
	colorerMaille(maille);
-
 
723
}
-
 
724
 
-
 
725
function combinerMaillesEtPoints() {
-
 
726
	enleverMarqueursCarte();
-
 
727
	coucheSites.eachLayer(function(layer) {
715
	marker.on('mouseout', function() {
728
		if (layer.typeSite == 'MAILLE') {
-
 
729
			var nombrePoints = compterNombrePointsDansMaille(layer);
-
 
730
			ajouterNombrePointsDansMaille(layer, nombrePoints);
716
		$("#tooltip").css('display', 'none');
731
		}
-
 
732
	});
717
	});
-
 
718
	coucheSites.ajouterPoint(marker);
733
}
719
}
734
 
720
 
735
function determinerNombreMarqueurs(source) {
-
 
736
	var nombrePoints = 0;
721
function construireContenuHtmlLegendePoints() {
737
	for (var index = 0; index < points.length; index ++) {
-
 
738
		if (points[index].source == source) {
722
	var div = L.DomUtil.create('div', 'info');
739
			nombrePoints += 1;
-
 
740
		}
-
 
741
	}
723
	div.innerHTML =
742
	return nombrePoints;
-
 
743
}
-
 
744
 
724
	'<h4>Stations</h4>'+
745
function enleverMarqueursCarte() {
725
	'<div class="legend"><table>'+
746
	coucheSites.eachLayer(function(layer) {
726
		'<tr>'+
747
		if (layer.typeSite != 'MAILLE') {
727
			'<td class="image-station"><img src="'+communeImageUrl+'" width="24" height="32" /></td>'+
748
			coucheSites.removeLayer(layer);
728
			'<td class="label-station">Commune</td>'+
749
		}
729
		'</tr>'+
750
	});
-
 
751
}
-
 
752
 
-
 
753
function compterNombrePointsDansMaille(maille) {
-
 
754
	var nombrePoints = {};
-
 
755
	for (var index = 0; index < points.length; index ++) {
730
		'<tr>'+
756
		if (maille.getBounds().contains(points[index].getLatLng())) {
-
 
757
			var source = points[index].source;
731
			'<td class="image-station"><img src="'+pointImageUrl+'" /></td>'+
758
			if (typeof(nombrePoints[source]) == 'undefined') {
-
 
759
				nombrePoints[source] = 1;
732
			'<td class="label-station">Lieu précis</td>'+
760
			} else {
-
 
761
				nombrePoints[source] += 1;
733
		'</tr>'+
762
			}
-
 
763
		}
-
 
764
	}
-
 
765
	return nombrePoints;
-
 
766
}
-
 
767
 
-
 
768
function ajouterNombrePointsDansMaille(maille, nombrePoints) {
-
 
769
	for (sourceDonnees in nombrePoints) {
734
		'<tr>'+
770
		if (typeof(maille.nombrePoints[sourceDonnees]) == 'undefined') {
735
			'<td class="image-station"><img src="'+clusterImageUrl+'" width="20" height="20" /></td>'+
771
			maille.nombrePoints[sourceDonnees] = nombrePoints[sourceDonnees];
736
			'<td class="label-station">Groupe de stations proches</td>'+
772
		} else {
-
 
773
			maille.nombrePoints[sourceDonnees] += nombrePoints[sourceDonnees];
737
		'</tr>'+
774
		}
-
 
775
	}
738
	'</table></div>';
776
	colorerMaille(maille);
739
	return div;
777
}
-
 
778
 
-
 
779
function supprimerPointsListe(sourceDonnees) {
-
 
780
	var index = 0;
-
 
781
	while (index < points.length) {
-
 
782
		if (points[index].source == sourceDonnees) {
-
 
783
			points.splice(index, 1);
-
 
784
		} else {
-
 
785
			index ++;
-
 
786
		}
-
 
787
	}
740
}
788
}
741
 
789
 
742
 
790
function transformerMaillesEnPoints(sourceDonnees) {
743
function surClicMarqueur(event) {
791
	coucheSites.eachLayer(function(layer) {
-
 
792
		if (layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[sourceDonnees]) != 'undefined') {
744
	var nombreMarkers = event.target.recupererMarkers().length;
793
			supprimerSourceDansMaille(layer, sourceDonnees);
745
	if (nombreMarkers == 1 || map.getZoom() == map.getMaxZoom()) {
794
		}
-
 
795
	});
746
		recupererObservations(event.target);
796
	for (var index = 0; index < points.length; index ++) {
747
	} else {
797
		coucheSites.addLayer(points[index]);
748
		map.setView(event.target.getLatLng(), Math.min(map.getZoom()+2, map.getMaxZoom()));
798
	}
749
	}
799
}
750
}
800
 
751
 
801
function surClicMarqueur(event) {
752
function recupererObservations(cluster) {
802
	var latitude = event.target.getLatLng().lat;
753
	pointClique = cluster;
803
	var longitude = event.target.getLatLng().lng;
-
 
804
	pointClique = event.target;
754
	var latlng = cluster.getLatLng();
805
	afficherMessageChargement('observations');
755
	afficherMessageChargement('observations');
806
	var parametres = {
756
	var parametres = {
-
 
757
		"source" : recupererSourcesCluster(cluster),
807
		"source" : pointClique.source,
758
		"stations" : construireListeStationsCluster(cluster),
-
 
759
		"num_taxon" : numTaxon,
808
		"num_taxon" : numTaxon,
760
		"nn" : nn,
809
		"referentiel" : referentiel,
761
		"referentiel" : referentiel,
810
		"auteur" : auteur,
-
 
811
		"nn" : nn,
-
 
812
		"type_site" : pointClique.typeSite,
762
		"auteur" : auteur,
813
		"date_debut" : dateDebut,
763
		"date_debut" : dateDebut,
814
		"date_fin" : dateFin,
-
 
815
		"longitude" : longitude,
-
 
816
		"latitude" : latitude,
764
		"date_fin" : dateFin,
817
		"nb_jours" : nbJours
765
		"nb_jours" : nbJours
818
	};
766
	};
819
	url = urlBase + "observations?" + convertirEnParametresUrl(parametres);
767
	url = urlBase + "observations?" + convertirEnParametresUrl(parametres);
820
	fonctionCallback = traiterDonneesObservations;
768
	fonctionCallback = traiterDonneesObservations;
821
	executerAJAX();
769
	executerAJAX();
822
}
770
}
-
 
771
 
-
 
772
function recupererSourcesCluster(cluster) {
-
 
773
	var markers = cluster.recupererMarkers();
-
 
774
	var sourcesCluster = [];
-
 
775
	for (var index = 0; index < markers.length; index ++) {
-
 
776
		if (sourcesCluster.indexOf(markers[index].source) == -1) {
-
 
777
			sourcesCluster.push(markers[index].source);
-
 
778
		}
-
 
779
	}
-
 
780
	return sourcesCluster.join(',');
-
 
781
}
-
 
782
 
-
 
783
function construireListeStationsCluster(cluster) {
-
 
784
	var markers = cluster.recupererMarkers();
-
 
785
	var listePoints = [];
-
 
786
	for (var index = 0; index < markers.length; index ++) {
-
 
787
		var latlng = markers[index].getLatLng();
-
 
788
		listePoints.push(markers[index].source+":"+markers[index].typeSite+":"+latlng.lng+","+latlng.lat);
-
 
789
	}
-
 
790
	return listePoints.join('|');
-
 
791
}
823
 
792
 
824
function traiterDonneesObservations() {
793
function traiterDonneesObservations() {
825
	masquerMessageChargement();
794
	masquerMessageChargement();
826
	var texte = requeteChargementPoints.responseText;
795
	var texte = requeteChargementPoints.responseText;
827
	if (!estStatutRequeteOK()) {
796
	if (!estStatutRequeteOK()) {
828
		alert(texte);
797
		alert(texte);
829
	} else {
798
	} else {
830
		obsJSON = eval("(function(){return " + texte + ";})()");
799
		obsJSON = eval("(function(){return " + texte + ";})()");
831
		if (obsJSON != null) {
800
		if (obsJSON != null) {
832
			viderListeObservations();
801
			viderListeObservations();
833
			if (obsJSON.total > 0) {
802
			if (obsJSON.total > 0) {
834
				doitRafraichirCarte = false;
803
				doitRafraichirCarte = false;
835
				map.setView(new L.LatLng(pointClique.getLatLng().lat, pointClique.getLatLng().lng), map.getZoom());
804
				map.setView(new L.LatLng(pointClique.getLatLng().lat, pointClique.getLatLng().lng), map.getZoom());
836
				afficherInfoBulle();
805
				afficherInfoBulle();
837
			} else if (infoBulle != null)  {
806
			} else if (infoBulle != null)  {
838
				masquerInfoBulle();
807
				masquerInfoBulle();
839
			}
808
			}
840
		}
809
		}
841
	}
810
	}
842
}
811
}
843
 
-
 
844
function viderListeObservations() {
-
 
845
	obsStation = new Array();
-
 
846
}
-
 
847
 
812
 
848
 
813
 
849
 
814
 
850
 
815
 
851
// ====================================================================
816
// ====================================================================
852
// Gestion de l'infobulle
817
// Gestion de l'infobulle
853
 
818
 
854
var obsJSON = null,
819
var obsJSON = null,
855
	pointClique = null,
820
	pointClique = null,
856
	obsStation = [],
821
	obsStation = [],
857
	typeAffichage = "";
822
	pagineur = {'limite':100, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
858
 
823
 
859
function afficherInfoBulle() {
824
function afficherInfoBulle() {
860
	var latitude = pointClique.getLatLng().lat;
825
	var latitude = pointClique.getLatLng().lat;
861
	var longitude = pointClique.getLatLng().lng;
826
	var longitude = pointClique.getLatLng().lng;
862
	infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 350});
827
	infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 380});
863
	infoBulle.setLatLng(new L.LatLng(latitude, longitude));
828
	infoBulle.setLatLng(new L.LatLng(latitude, longitude));
864
	infoBulle.setContent($("#tpl-obs").html());
829
	infoBulle.setContent($("#tpl-obs").html());
865
	infoBulle.openOn(map);	
830
	infoBulle.openOn(map);
866
	remplirContenuPopup();
831
	remplirContenuPopup();
-
 
832
	$('#info-bulle').css('width', '99%');
-
 
833
	$('#observations').css('height', '250px');
-
 
834
	$('#observations').css('overflow', 'auto');
-
 
835
	$('.leaflet-popup-scrolled').css('overflow', 'visible');
-
 
836
}
-
 
837
 
-
 
838
function viderListeObservations() {
-
 
839
	obsStation = new Array();
867
}
840
}
868
 
841
 
869
function definirLargeurInfoBulle() {
842
function definirLargeurInfoBulle() {
870
	var largeurViewPort = $(window).width();
843
	var largeurViewPort = $(window).width();
871
	var lageurInfoBulle = null;
844
	var lageurInfoBulle = null;
872
	if (largeurViewPort < 800) {
845
	if (largeurViewPort < 800) {
873
		largeurInfoBulle = 400;
846
		largeurInfoBulle = 400;
874
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
847
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
875
		largeurInfoBulle = 500;
848
		largeurInfoBulle = 500;
876
	} else if (largeurViewPort >= 1200) {
849
	} else if (largeurViewPort >= 1200) {
877
		largeurInfoBulle = 600;
850
		largeurInfoBulle = 600;
878
	}
851
	}
879
	return largeurInfoBulle;
852
	return largeurInfoBulle;
880
}
853
}
881
 
854
 
882
function redimensionnerPopup() {
855
function redimensionnerPopup() {
883
	$('.leaflet-popup-content*').css('width',  definirLargeurInfoBulle());
856
	$('.leaflet-popup-content*').css('width', definirLargeurInfoBulle());
884
	$('#info-bulle').css('width',  definirLargeurInfoBulle());
857
	$('#info-bulle').css('width', '99%');
885
}
858
}
886
 
859
 
887
function remplirContenuPopup() {
860
function remplirContenuPopup() {
888
	ajouterTableauTriable("#obs-tableau");
861
	ajouterTableauTriable("#obs-tableau");
889
	ajouterTitre();
862
	ajouterTitre();
890
	afficherOnglets();
863
	afficherTableau();
891
	afficherTexteStationId();
864
	afficherTexteStationId();
892
}
865
}
893
 
866
 
894
function masquerInfoBulle() {
867
function masquerInfoBulle() {
895
	if (infoBulle != null && map.hasLayer(infoBulle)) {
868
	if (infoBulle != null && map.hasLayer(infoBulle)) {
896
		map.removeLayer(infoBulle);
869
		map.removeLayer(infoBulle);
897
	}
870
	}
898
	infoBulle = null;
871
	infoBulle = null;
899
}
872
}
900
 
873
 
901
function ajouterTitre() {
874
function ajouterTitre() {
902
	var texteStationTitre = obsJSON.total + ' observation' + (obsJSON.total > 1 ? 's' : '')
875
	var texteStationTitre = obsJSON.total + ' observation' + (obsJSON.total > 1 ? 's' : '')
903
		+ ' pour ' + (pointClique.options.type=='STATION' ? 'la station : ' : 'la commune : ')
876
		+ ' sur ' + (pointClique.typeSite=='station' ? 'la station : ' : 'la commune : ')
904
		+ pointClique.options.title;
877
		+ pointClique.options.title;
905
	$('#obs-station-titre').text(texteStationTitre);
878
	$('#obs-station-titre').text(texteStationTitre);
906
}
879
}
907
 
880
 
908
function selectionnerOnglet() {
-
 
909
	$("#obs-vue-" + typeAffichage).css("display", "block");
-
 
910
	$('#obs-tableau-lignes').empty();
881
function afficherTableau() {
911
	$('#obs-liste-lignes').empty();
882
	construireListeObservations();
912
	if (typeAffichage=='liste') {
-
 
913
		$("#obs-vue-tableau").css("display", "none");
-
 
914
	} else {
883
	afficherPagination();
915
		$("#obs-vue-liste").css("display", "none");
-
 
916
	}
884
	afficherObservationsDansHTML();
917
}
885
}
918
 
886
 
919
function ajouterObservationsDansHTML() {
887
function construireListeObservations() {
920
	if (obsStation.length==0) {
888
	if (obsStation.length==0) {
921
		// premiere execution de la fonction : faire une copie des objets JSON decrivant les observations 
889
		// premiere execution de la fonction : faire une copie des objets JSON decrivant les observations 
922
		for (var index = 0; index < obsJSON.observations.length; index ++) {
890
		for (var index = 0; index < obsJSON.observations.length; index ++) {
923
			obsStation.push(obsJSON.observations[index]);
891
			obsStation.push(obsJSON.observations[index]);
924
		}
892
		}
925
	}
893
	}
926
	var obsPage = [];
-
 
927
	for (var index = 0; index < obsStation.length; index ++) {
-
 
928
		obsPage.push(obsStation[index]);
894
	pagineur.total = obsStation.length;
929
	}
-
 
930
	$("#tpl-obs-"+typeAffichage).tmpl(obsPage).appendTo("#obs-"+typeAffichage+"-lignes");
-
 
931
}
895
}
932
 
896
 
-
 
897
function afficherPagination() {
933
function afficherOnglets() {
898
	$(".navigation").pagination(pagineur.total, {
934
	var $tabs = $('#obs').tabs();
899
		items_per_page:pagineur.limite,
935
	$('#obs').bind('tabsselect', function(event, ui) {
900
		callback:afficherObservationsDansHTML,
936
		if (ui.panel.id == 'obs-vue-tableau') {
901
		next_text:'Suivant',
937
			surClicAffichageTableau();
902
		prev_text:'Précédent',
-
 
903
		prev_show_always:false,
938
		} else if (ui.panel.id == 'obs-vue-liste') {
904
		num_edge_entries:1,
939
			surClicAffichageListe();
905
		num_display_entries:4,
940
		}
906
		load_first_page:true
941
	});
-
 
942
	if (obsJSON.total > 4) {
-
 
943
		surClicAffichageTableau();
-
 
944
	} else {
-
 
945
		$tabs.tabs('select', "#obs-vue-liste");
-
 
946
	}
907
	});
947
}
908
}
948
 
-
 
949
function surClicAffichageTableau() {
909
 
950
	typeAffichage = 'tableau';
910
function afficherObservationsDansHTML(indexPage) {
951
	selectionnerOnglet();
911
	$("#obs-tableau-lignes").empty();
952
	ajouterObservationsDansHTML();
912
	if (typeof(indexPage) == 'undefined') {
953
	mettreAJourTableauTriable("#obs-tableau");
-
 
954
}
913
		indexPage = 0;
955
 
914
	}
-
 
915
	var depart = indexPage * pagineur.limite;
956
function surClicAffichageListe() {
916
	var obsPage = [];
-
 
917
	for (var index = depart; index < depart + pagineur.limite; index ++) {
-
 
918
		obsPage.push(obsStation[index]);
957
	typeAffichage = 'liste';
919
	}
958
	selectionnerOnglet();
920
	$("#tpl-obs-tableau").tmpl(obsPage).appendTo("#obs-tableau-lignes");
959
	ajouterObservationsDansHTML();
921
	mettreAJourTableauTriable();
960
}
922
}
961
 
923
 
962
function ajouterTableauTriable(element) {
924
function ajouterTableauTriable() {
963
	$.tablesorter.addParser({ 
925
	$.tablesorter.addParser({ 
964
		id: 'date_cel', 
926
		id: 'date_cel', 
965
		is: function(s) { 
927
		is: function(s) { 
966
			// doit retourner false si le parseur n'est pas autodétecté
928
			// doit retourner false si le parseur n'est pas autodétecté
967
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
929
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
968
		}, 
930
		}, 
969
		format: function(date) { 
931
		format: function(date) { 
970
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
932
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
971
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
933
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3-$2-$1");
972
			// Remplace la date par un nombre de millisecondes pour trier numériquement
934
			// Remplace la date par un nombre de millisecondes pour trier numériquement
973
			return $.tablesorter.formatFloat(new Date(date).getTime());
935
			return $.tablesorter.formatFloat(new Date(date).getTime());
974
		}, 
936
		}, 
975
		type: 'numeric' 
937
		type: 'numeric' 
976
	});
938
	});
977
	$(element).tablesorter({ 
939
	$("#obs-tableau").tablesorter({ 
978
        headers: { 
940
        headers: { 
979
			1: { 
941
			1: { 
980
            	sorter:'date_cel' 
942
            	sorter:'date_cel'
981
        	} 
943
        	} 
982
    	}
944
    	}
983
	});
945
	});
984
}
946
}
985
 
947
 
986
function mettreAJourTableauTriable(element) {
948
function mettreAJourTableauTriable() {
987
	$(element).trigger('update');
949
	$("#obs-tableau").trigger('update');
988
}
950
}
989
 
951
 
990
function afficherTexteStationId() {
952
function afficherTexteStationId() {
991
	var latitude = pointClique.getLatLng().lat;
953
	var latitude = pointClique.getLatLng().lat.toFixed(5);
992
	var longitude = pointClique.getLatLng().lng;
954
	var longitude = pointClique.getLatLng().lng.toFixed(5);
-
 
955
	var texteStationId = pointClique.typeSite.toUpperCase() + ':'
993
	var texteStationId = pointClique.typeSite+':'+latitude+'|'+longitude+', SOURCE:'+pointClique.source;
956
		+ latitude + '|' + longitude + ', SOURCE:' + pointClique.source;
994
	$('#obs-station-id').text(texteStationId);
957
	$('#obs-station-id').text(texteStationId);
995
}
958
}