Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 31 | Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 37
Line 1... Line -...
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,
Line 83... Line 24...
83
zoom = 6,
24
zoom = 6,
84
legende = null,
25
legende = null,
85
coucheDepartement = null,
26
coucheDepartement = null,
86
infoBulle = null;
27
infoBulle = null;
Line 87... Line 28...
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',
Line 94... Line 32...
94
overlays = [];
32
overlays = [];
95
 
-
 
96
var requeteChargementPoints = null,
-
 
97
	chargementMaillesEnCours = false,
-
 
98
doitRafraichirCarte = true,
33
 
-
 
34
var requeteChargementPoints = null,
-
 
35
timer = null,
99
chargementCommunesEnCours = false,
36
ancienneRequete = null,
Line 100... Line 37...
100
timer = null,
37
deplacement = true,
101
url = '';
38
url = '';
102
 
39
 
Line -... Line 40...
-
 
40
 
-
 
41
 
-
 
42
 
-
 
43
$(document).ready(function() {
103
 
44
	initialiserWidget();
104
 
45
});
105
 
46
 
106
$(document).ready(function() {
47
$(window).resize(function() {
107
	initialiserWidget();
48
	dimensionnerCarte();
108
});
49
});
109
 
-
 
110
function initialiserWidget() {
50
 
111
	initialiserCarte();
-
 
112
	dimensionnerOverlay();
-
 
113
	initialiserPanneauControle();
-
 
114
	initialiserSources();
-
 
115
	initialiserListeners();
-
 
116
	chargerLimitesCommunales();
-
 
117
	chargerMaillesVides();
-
 
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);
51
function initialiserWidget() {
Line 137... Line 52...
137
}
52
	initialiserCarte();
138
 
53
	chargerLimitesCommunales();
139
 
54
	initialiserPanneauControle();
-
 
55
	initialiserSources();
140
function dimensionnerCarte() {
56
	initialiserListeners();
141
	$('#map').height($(window).height());
57
	chargerLocalisations();
142
	$('#map').width($(window).width());
-
 
143
}
-
 
144
 
58
}
145
function initialiserCarte() {
59
 
146
	dimensionnerCarte();
60
function initialiserCarte() {
147
	map = L.map('map', optionsCarte);
61
	dimensionnerCarte();
148
	coucheSites.addTo(map);
62
	map = L.map('map', optionsCarte);
149
	coucheOSM.addTo(map);
63
	coucheSatellite.addTo(map);
150
	couchePlanGoogle.addTo(map);
64
	coucheRelief.addTo(map);
151
	coucheSatelliteGoogle.addTo(map);
65
	coucheOSM.addTo(map);
152
	var echelle = new L.Control.Scale({
66
	var echelle = new L.Control.Scale({
Line -... Line 67...
-
 
67
		maxWidth : 50,
-
 
68
		metric : true,
-
 
69
		imperial : false,
-
 
70
		updateWhenIdle : true
-
 
71
	});
153
		maxWidth : 32,
72
	map.addControl(echelle);
154
		metric : true,
73
	zoom = map.getZoom();
155
		imperial : false,
74
}
156
		updateWhenIdle : true
75
 
157
	});
76
function dimensionnerCarte() {
158
	map.addControl(echelle);
77
	$('#map').height($(window).height());
159
	zoom = map.getZoom();
78
	$('#map').width($(window).width());
160
}
79
}
Line 161... Line 80...
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();
Line 167... Line 86...
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
Line 176... Line 95...
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 ++) {
Line 211... Line 130...
211
			changerSource(event.target.value);
130
			changerSource(event.target.value);
212
		}
131
		}
213
	});
132
	});
214
}
133
}
Line 215... Line 134...
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
	}
Line 224... Line 152...
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
		}
Line 233... Line 174...
233
	}
174
	}
234
}
175
}
-
 
176
 
-
 
177
function retirerStationsEtObservations(maille, sourceRetrait) {
-
 
178
	var sources = maille.properties.source;
235
 
179
	var nombreStations = 0;
236
function chargerMaillesVides() {
180
	for (var index = 0; index < sources.length; index ++) {
-
 
181
		var source = sources[index];
-
 
182
		if (source == sourceRetrait) {
-
 
183
			delete maille.properties.stations[source];
237
	chargementMaillesEnCours = true;
184
			delete maille.properties.observations[source];
-
 
185
		} else if (typeof(maille.properties.stations[source]) != 'undefined') {
238
	if (timer != null) {
186
			nombreStations += parseInt(maille.properties.stations[source]);
-
 
187
		}
-
 
188
	}
-
 
189
	if (nombreStations == 0) {
239
        window.clearTimeout(timer);
190
		coucheSites.removeLayer(maille);
240
    }	
191
	} else {
241
	if (requeteChargementPoints != null) {
-
 
-
 
192
		colorerMaille(maille)
-
 
193
		genererInfobulle(maille);		
242
		stopperRequeteAjax();
194
	}
243
	}
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) {
-
 
200
		if($(layer._path).attr('fill-opacity') != '0') {
-
 
201
			nombreMailles ++;
-
 
202
		}
-
 
203
	});
-
 
204
	return nombreMailles;
-
 
205
}
248
				"bbox" : coordonneesBordure,
206
 
249
				"zoom" : map.getZoom()
207
function estValeurDansTableau(tableau, valeur) {
-
 
208
	var index;
-
 
209
	for (index = 0; index < tableau.length && tableau[index] != valeur; index ++);
-
 
210
	return (tableau.length > 0 && index != tableau.length);
250
			};
211
}
-
 
212
 
-
 
213
//************************************
251
			url = urlBase + "mailles?" + convertirEnParametresUrl(parametres);
214
// requetes stations
252
			fonctionCallback = traiterDonneesStations;
215
 
Line 253... Line 216...
253
			executerAJAX();
216
function surChangementVueCarte() {
-
 
217
	programmerRafraichissementCarte();
254
	}, 400);
218
}
255
}
-
 
256
 
219
 
257
function programmerRafraichissementCarte(source) {
220
function programmerRafraichissementCarte(source) {
258
	source = (source == null || source == 'null') ? null : source;
221
	$('#tooltip').css('display', 'none');
259
	if (!chargementMaillesEnCours) {
222
	source = (source == null || source == 'null') ? null : source;
260
		if (timer != null) {
-
 
261
			window.clearTimeout(timer);
223
	if (timer != null) {
262
		}
224
		window.clearTimeout(timer);
-
 
225
	}
-
 
226
	if (requeteChargementPoints != null) {
-
 
227
		stopperRequeteAjax();
-
 
228
	}
263
		if (requeteChargementPoints != null) {
229
	var nombreSourcesVisibles = 0;
-
 
230
	for (var index = 0; index < overlays.length; index ++) {
-
 
231
		if (overlays[index].checked) {
264
			if (source == null) {
232
			nombreSourcesVisibles ++;
265
				stopperRequeteAjax();
233
		}
266
			}
234
	}
267
		}
235
	if (source == null) {
268
		timer = window.setTimeout("rafraichirDonnnees('"+source+"')", 250);
236
		timer = window.setTimeout("chargerLocalisations()", 100);
Line 269... Line 237...
269
    } else {
237
	} else {
270
    	window.setTimeout("programmerRafraichissementCarte('"+source+"')", 400);
238
		timer = window.setTimeout("chargerSource('"+source+"')", 100);
271
    }
239
	}
272
}
240
}
Line 273... Line -...
273
 
-
 
274
function stopperRequeteAjax() {
-
 
275
	requeteChargementPoints.abort();
-
 
276
	requeteChargementPoints = null;
-
 
277
}
-
 
278
 
-
 
279
function rafraichirDonnnees(source) {
241
 
280
	source = (source == null || source == 'null') ? null : source;
242
function stopperRequeteAjax() {
281
	if (coucheDepartement == null || coucheDepartement.getStatus() == KML_READY) {
-
 
282
		if (source != null) {
243
	requeteChargementPoints.abort();
283
			chargerLocalisations(source);
-
 
284
		} else {
-
 
285
			supprimerLocalisations();
-
 
286
			for (source in sources) {
-
 
287
				if (sources[source] == true) {
-
 
288
					chargerLocalisations(source);
244
	requeteChargementPoints = null;
-
 
245
}
-
 
246
 
-
 
247
function chargerLocalisations() {
-
 
248
	if (requeteEnCours()) {
-
 
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) {
289
				}
272
		parametres.format = typeSite;
Line 290... Line 273...
290
			}
273
	}
-
 
274
	ancienneRequete = [map.getBounds(), map.getZoom()];
291
		}
275
	url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
292
	} else {
276
	fonctionCallback = traiterDonneesStations;
293
		window.setTimeout("rafraichirDonnnees('"+source+"')", 800);
277
	executerAJAX();
294
	}
278
}
Line 295... Line 279...
295
}
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 = '';
-
 
301
}
-
 
302
 
-
 
303
function supprimerLocalisations(source) {
-
 
304
	source = (typeof(source) == 'undefined') ? null : source;
-
 
305
	if (source != null) {
-
 
306
		var sourceUrl = recupererParametreDansUrl('source', url);
-
 
307
		if (requeteChargementPoints != null && sourceUrl == source && source != null) {
-
 
308
			stopperRequeteAjax();
284
	}
309
		}
-
 
310
		coucheSites.eachLayer(function(layer) {
-
 
311
			supprimerLayer(layer, source);
285
}
312
		});
-
 
313
		if (source != null) {
-
 
314
			supprimerPointsListe(source);
286
 
-
 
287
function recupererSourcesActivees(sourceAIgnorer) {
315
		}
288
	sourceAIgnorer = typeof(sourceAIgnorer) == 'undefined' ? '' : sourceAIgnorer;
Line 316... Line 289...
316
		var sourcesSelectionnees = determinerSourcesSelectionnees();
289
	var sourcesActivees = [];
-
 
290
	for (var index = 0; index < overlays.length; index ++) {
-
 
291
		if (overlays[index].checked == true && overlays[index].value != sourceAIgnorer) {
-
 
292
			sourcesActivees.push(overlays[index].value);
-
 
293
		}
-
 
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,
317
		if (sourcesSelectionnees.length == 1 && determinerNombreMarqueurs(sourcesSelectionnees[0]) > 0) {
312
		"dept" : dept,
-
 
313
		"auteur" : auteur,
-
 
314
		"date_debut" : dateDebut,
-
 
315
		"date_fin" : dateFin,
-
 
316
		"nb_jours" : nbJours
-
 
317
	};
-
 
318
	ancienneRequete = [map.getBounds(), map.getZoom()];
-
 
319
	url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
318
			transformerMaillesEnPoints(sourcesSelectionnees[0]);
320
	fonctionCallback = traiterRetourChargementSource;
-
 
321
	executerAJAX();
319
		}
322
}
320
		var sontPointsAffiches = (points.length>0 && determinerNombreMailles(false)==0);
323
 
-
 
324
function calculerBboxRequete() {
321
		formeDonnees = sontPointsAffiches ? 'point' : 'maille';
325
	var bordure = map.getBounds();
Line 322... Line 326...
322
	}
326
	var bboxRequete = "";
-
 
327
	if (ancienneRequete != null && ancienneRequete[1] == map.getZoom()
-
 
328
		&& bordure.intersects(ancienneRequete[0])) {
-
 
329
		bboxRequete = calculerIntersectionRectangle(ancienneRequete[0], bordure);
-
 
330
	} else {
-
 
331
		bboxRequete = determinerCoordonneesBordure();
323
}
332
	}
-
 
333
	return bboxRequete;
-
 
334
}
324
 
335
 
-
 
336
function calculerIntersectionRectangle(rectangle1, rectangle2) {
-
 
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),
-
 
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);
325
function estLayerUtilisePourSource(layer, source) {
345
		if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat
326
	return (
346
			&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) {
327
		(layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[source]) != 'undefined') ||
347
			bbox1[1] = rectangle1.getNorthEast().lat.toFixed(6);
328
		(layer.typeSite != 'MAILLE' && layer.source == source)
348
		} else {
329
	);
349
			bbox1[3] = rectangle1.getSouthWest().lat.toFixed(6);
-
 
350
		}
330
}
351
	} else {
Line 331... Line -...
331
 
-
 
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
-
 
354
			&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) {
334
		if (layer.typeSite == 'MAILLE') {
355
			bbox2[1] = rectangle1.getNorthEast().lat.toFixed(6);
-
 
356
		} else {
-
 
357
			bbox2[3] = rectangle1.getSouthWest().lat.toFixed(6);
-
 
358
		}
335
			supprimerSourceDansMaille(layer, source);
359
	}
-
 
360
	return bbox1.join(',')+'|'+bbox2.join(',');
336
		} else {
361
}
337
			coucheSites.removeLayer(layer);
362
 
338
		}
363
function determinerCoordonneesBordure() {
339
	}
364
	var ouest = map.getBounds().getSouthWest().lng.toFixed(6),
340
}
-
 
341
 
365
		sud = Math.max(map.getBounds().getSouthWest().lat, -85.051129).toFixed(6),
342
 
366
		est = map.getBounds().getNorthEast().lng.toFixed(6),
343
function changerSource(projetClique) {
367
		nord = Math.min(map.getBounds().getNorthEast().lat, 85.051129).toFixed(6);
344
	var indexProjetClique;
-
 
345
	for (var index = 0; index < overlays.length; index ++) {
368
	// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees
-
 
369
	// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur)
346
		if (overlays[index].value == projetClique) {
370
	if (ouest < -180) {
Line 347... Line 371...
347
			indexProjetClique = index;
371
		ouest += 360;
348
		}
372
	} else if (ouest > 180) {
349
	}
373
		ouest -= 360;
Line 367... Line 391...
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
}
Line 371... Line -...
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();
Line 388... Line 409...
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
}
Line 392... Line 413...
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;
Line 417... Line 423...
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
		}
Line 437... Line 440...
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);
-
 
448
	} else {
445
	} else {
449
		var donneesJSON = eval("(function(){return " + texte + ";})()");
-
 
450
		if (donneesJSON != null && donneesJSON.features.length > 0) {
-
 
451
			var formatRetourDifferent = donneesJSON.stats.formeDonnees != typeSite;
-
 
452
			ajouterStationsSurCarte(donneesJSON);
-
 
453
			if (formatRetourDifferent) {
-
 
454
				var sourceAIgnorer = donneesJSON.stats.source[0];
446
		var donneesJSON = eval("(function(){return " + texte + ";})()");
455
				var sourcesARecharger = recupererSourcesActivees(sourceAIgnorer);
447
		if (donneesJSON != null && typeof(donneesJSON.features) != 'undefined') {
456
				rechargerSources(sourcesARecharger);
448
			ajouterStationsSurCarte(donneesJSON);
457
			}
Line 449... Line 458...
449
		}
458
		}
-
 
459
	}
-
 
460
}
-
 
461
 
450
	}
462
function supprimerFeaturesHorsBbox() {
451
}
463
	var bordure = map.getBounds();
452
 
464
	var layersRestants = 0;
453
function ajouterStationsSurCarte(data) {
-
 
454
	if (doitTransformerEnMaille(data.stats)) {
465
	if (coucheSites != null) {
455
		if (points.length > 0 && data.stats.source != '') {
466
		coucheSites.eachLayer(function(layer) {
456
			combinerMaillesEtPoints();
467
			if (typeof(layer._latlng) != 'undefined') {
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
	}
-
 
462
	var sourceDonnees = data.stats.source;
-
 
463
	for (var index = 0; index < data.features.length; index ++) {
472
				}
464
		ajouterStation(data.features[index]);
473
			} else {
465
	}
474
				if (bordure.intersects(layer.getBounds())) {
-
 
475
					layersRestants ++;
466
	if (formeDonnees == 'maille' && data.stats.sites > 0) {
476
				} else {
467
		afficherLegende();
477
					coucheSites.removeLayer(layer);
468
		regenererInfobulleMailles();
478
				}
469
	} else {
479
			}
470
		masquerLegende();
-
 
471
	}
480
		});
472
	if (chargementMaillesEnCours) {
481
	}
Line 473... Line 482...
473
		chargementMaillesEnCours = false;
482
	if (layersRestants == 0) {
474
		programmerRafraichissementCarte();
483
		coucheSites = null;
475
	}
484
	}
476
}
-
 
477
 
485
}
478
function ajouterStation(feature) {
486
 
-
 
487
function rechargerSources(sourcesARecharger) {
479
	if (feature.properties.typeSite == 'MAILLE') {
488
	var listeSourcesASupprimer = sourcesARecharger.split(',');
Line 480... Line 489...
480
		traiterMaille(feature);
489
	for (var index = 0; index < listeSourcesASupprimer.length; index ++) {
481
	} else {
490
		supprimerFeaturesSource(listeSourcesASupprimer[index]);
-
 
491
	}
482
		ajouterPoint(feature);
492
	chargerSource(sourcesARecharger);
483
	}
493
}
-
 
494
 
484
}
495
function ajouterStationsSurCarte(donnees) {
-
 
496
	typeSite = donnees.stats.formeDonnees;
-
 
497
	if (coucheSites == null) {
-
 
498
		coucheSites = (typeSite == 'maille') ? new L.FeatureGroup() : new L.ClusterGroup();
-
 
499
		map.addLayer(coucheSites);
-
 
500
	}
-
 
501
	for (var index = 0; index < donnees.features.length; index ++) {
-
 
502
		var feature = donnees.features[index];
485
 
503
		if (typeSite == 'maille') {
-
 
504
			traiterMaille(feature);
-
 
505
		} else {
-
 
506
			ajouterPoint(feature);
-
 
507
		}
-
 
508
	}
486
function doitTransformerEnMaille(statsFeatures) {
509
	if (donnees.features.length > 0) {
-
 
510
		afficherLegende();
487
	var condition1 = (formeDonnees == 'point' && statsFeatures.formeDonnees =='maille');
511
	}
Line 488... Line -...
488
	var condition2 = (formeDonnees == 'maille' && statsFeatures.formeDonnees =='point'
-
 
489
		&& determinerNombreMailles(false) > 0);
-
 
490
	var condition3 = (statsFeatures.formeDonnees == 'point' && map.getZoom() <= ZOOM_MAXIMUM_MAILLAGE
512
	if (typeSite == 'maille') {
491
		&& (points.length+statsFeatures.sites) > SEUIL_MAILLAGE);
513
		genererInfobulleMailles();
Line 492... Line -...
492
	return (condition1 || condition2 || condition3);
-
 
493
}
-
 
494
 
-
 
495
 
-
 
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) {
514
	} else {
516
				nombreMailles ++;
515
		coucheSites.afficherClusters();
517
			}
516
	}
518
		}
517
}
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]);
-
 
526
		coordonnees.push(sommet);
527
		coordonnees.push(sommet);
527
	}
Line 528... Line 528...
528
	}
528
	var maille = rechercherMailleExistante(coordonnees);
529
	var maille = rechercherMailleExistante(coordonnees);
529
	if (maille) {
530
	if (maille) {
530
		mettreAJourMaille(maille, feature);
531
		mettreAJourMaille(maille, feature);
531
	} else {
532
	} else if (feature.properties.nombrePoints > 0) {
532
		maille = ajouterMaille(feature, coordonnees);
533
		ajouterMaille(feature);
533
	}
534
	}
534
	colorerMaille(maille);
535
}
535
}
536
 
536
 
Line 554... Line 554...
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
}
Line 558... Line 558...
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;
Line 573... Line 572...
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') {
-
 
578
		maille.nombrePoints[feature.properties.source] = nombreAAjouter;
576
	for (var index = 0; index < sources.length; index ++) {
579
	} else {
-
 
580
		maille.nombrePoints[feature.properties.source] += nombreAAjouter;
577
		var source = sources[index];
581
	}*/
-
 
582
	maille.nombrePoints[feature.properties.source] = nombreAAjouter;
-
 
583
	colorerMaille(maille);
-
 
584
}
-
 
585
 
-
 
586
function regenererInfobulleMailles() {
-
 
587
	$('.leaflet-clickable').addClass('tooltip');
-
 
588
	coucheSites.eachLayer(function(layer) {
578
		maille.properties.stations[source] = parseInt(feature.properties.stations[source]);
589
		if (layer.typeSite == 'MAILLE') {
579
		maille.properties.observations[source] = parseInt(feature.properties.observations[source]);
590
			genererInfobulle(layer);
-
 
591
		}
580
		maille.properties.source.push(source);
Line 592... Line 581...
592
	});
581
	}
593
}
582
}
594
 
583
 
-
 
584
function colorerMaille(maille) {
-
 
585
	var nombreStations = 0;
-
 
586
	var sources = maille.properties.source;
595
function colorerMaille(maille) {
587
	for (var index = 0; index < sources.length; index ++) {
-
 
588
		var source = sources[index];
596
	var nombrePoints = 0;
589
		if (typeof(maille.properties.stations[source]) != 'undefined') {
597
	for (sourceMaille in maille.nombrePoints) {
590
			nombreStations += parseInt(maille.properties.stations[source]);
598
		nombrePoints += maille.nombrePoints[sourceMaille];
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});
Line 605... Line -...
605
		maille.off('click', surClicMaille);
-
 
606
	}
-
 
607
}
-
 
608
 
-
 
609
function surClicMaille(event) {
598
		maille.off('click');
610
	map.fitBounds(event.layer.getBounds());
599
	}
611
}
600
}
612
 
601
 
613
function genererCouleur(nombrePoints) {
602
function genererCouleur(nombrePoints) {
Line 620... Line 609...
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
}
Line -... Line 613...
-
 
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'});
-
 
621
		legende.onAdd = function(map) {
-
 
622
			var contenuHtml = '';
-
 
623
			if (typeSite == 'maille') {
-
 
624
				contenuHtml = construireContenuHtmlLegendeMailles();
628
		legende.onAdd = function(map) {
625
			} else {
-
 
626
				contenuHtml = construireContenuHtmlLegendePoints(); 
-
 
627
			}
629
			return construireContenuHtmlLegende();
628
			return contenuHtml;
630
		};
629
		};
631
		map.addControl(legende);
630
		map.addControl(legende);
632
	}
631
	}
Line 633... Line 632...
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
	}
Line 652... Line 651...
652
		map.removeControl(legende);
651
		map.removeControl(legende);
653
		legende = null;
652
		legende = null;
654
	}
653
	}
655
}
654
}
Line 656... Line 655...
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
	});
Line 663... Line 662...
663
}
662
}
664
 
663
 
665
function genererInfobulle(maille) {
-
 
666
	var nombrePoints = 0,
664
function genererInfobulle(maille) {
667
		nombreSources = 0;
665
	var sources = maille.properties.source;
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, "
-
 
671
				+maille.properties.observations[source]+" observations");
-
 
672
		}
-
 
673
	}
-
 
674
	var contenu = textes.join('<br />');
-
 
675
	maille.on('mouseover', function() {
673
				sourceMaille+' : '+maille.nombrePoints[sourceMaille];
676
		afficherTooltip(contenu, map.latLngToContainerPoint(maille.getBounds().getSouthWest()));
-
 
677
	});
-
 
678
	maille.on('mouseout', function() {
674
		}
679
		$("#tooltip").css('display', 'none');
-
 
680
	});
-
 
681
}
-
 
682
 
-
 
683
function afficherTooltip(texte, point) { 
675
		nombreSources ++;
684
	$("#tooltip").html(texte);
-
 
685
	if ($("#tooltip").css('display') == 'none') {
-
 
686
		var x = point.x - 15;
676
	}
687
		var y = point.y + (typeSite == 'maille' ? 1 : 10);
677
	if (nombreSources > 0) {
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');
Line 680... Line 691...
680
	}
691
	}
681
}
692
}
Line 682... Line 693...
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, {
-
 
695
			icon  : icone,
-
 
696
			title : feature.properties.nom
-
 
697
		})
-
 
698
	marker.typeSite = feature.properties.typeSite;
-
 
699
	marker.source = feature.properties.source;
-
 
700
	marker.on('click', surClicMarqueur);
-
 
701
	points.push(marker);
-
 
702
	if (formeDonnees != 'maille') {
-
 
703
		coucheSites.addLayer(marker);
-
 
704
	} else {
705
	var marker = new L.Cluster(point, {
705
		ajouterPointDansMaille(marker);
706
		icon  : icone,
706
	}
-
 
707
}
-
 
708
 
-
 
709
function ajouterPointDansMaille(point) {
707
		titre : feature.properties.nom
710
	var maille = null;
-
 
711
	coucheSites.eachLayer(function(layer) {
-
 
712
		if (layer.typeSite == 'MAILLE' && layer.getBounds().contains(point.getLatLng())) {
-
 
713
			maille = layer;
-
 
714
			return;
-
 
715
		}
-
 
716
	});
-
 
717
	if (typeof(maille.nombrePoints[point.source]) == 'undefined') {
-
 
718
		maille.nombrePoints[point.source] = 1;
-
 
719
	} else {
-
 
720
		maille.nombrePoints[point.source] += 1;
708
	});
721
	}
-
 
722
	colorerMaille(maille);
-
 
723
}
709
	marker.typeSite = feature.properties.typeSite.toLowerCase();
724
 
-
 
725
function combinerMaillesEtPoints() {
710
	marker.source = feature.properties.source;
-
 
711
	marker.on('click', surClicMarqueur);
726
	enleverMarqueursCarte();
712
	marker.on('mouseover', function() {
Line 727... Line 713...
727
	coucheSites.eachLayer(function(layer) {
713
		afficherTooltip(marker.options.titre, map.latLngToContainerPoint(marker.getLatLng()));
728
		if (layer.typeSite == 'MAILLE') {
-
 
729
			var nombrePoints = compterNombrePointsDansMaille(layer);
714
	});
730
			ajouterNombrePointsDansMaille(layer, nombrePoints);
-
 
731
		}
715
	marker.on('mouseout', function() {
732
	});
-
 
733
}
-
 
734
 
716
		$("#tooltip").css('display', 'none');
735
function determinerNombreMarqueurs(source) {
-
 
736
	var nombrePoints = 0;
-
 
737
	for (var index = 0; index < points.length; index ++) {
717
	});
738
		if (points[index].source == source) {
718
	coucheSites.ajouterPoint(marker);
739
			nombrePoints += 1;
719
}
740
		}
720
 
741
	}
721
function construireContenuHtmlLegendePoints() {
742
	return nombrePoints;
722
	var div = L.DomUtil.create('div', 'info');
743
}
-
 
744
 
-
 
745
function enleverMarqueursCarte() {
-
 
746
	coucheSites.eachLayer(function(layer) {
-
 
747
		if (layer.typeSite != 'MAILLE') {
-
 
748
			coucheSites.removeLayer(layer);
723
	div.innerHTML =
749
		}
-
 
750
	});
724
	'<h4>Stations</h4>'+
751
}
-
 
752
 
725
	'<div class="legend"><table>'+
753
function compterNombrePointsDansMaille(maille) {
-
 
754
	var nombrePoints = {};
726
		'<tr>'+
755
	for (var index = 0; index < points.length; index ++) {
-
 
756
		if (maille.getBounds().contains(points[index].getLatLng())) {
-
 
757
			var source = points[index].source;
-
 
758
			if (typeof(nombrePoints[source]) == 'undefined') {
-
 
759
				nombrePoints[source] = 1;
-
 
760
			} else {
-
 
761
				nombrePoints[source] += 1;
-
 
762
			}
727
			'<td class="image-station"><img src="'+communeImageUrl+'" width="24" height="32" /></td>'+
763
		}
728
			'<td class="label-station">Commune</td>'+
764
	}
729
		'</tr>'+
765
	return nombrePoints;
-
 
766
}
730
		'<tr>'+
767
 
-
 
768
function ajouterNombrePointsDansMaille(maille, nombrePoints) {
731
			'<td class="image-station"><img src="'+pointImageUrl+'" /></td>'+
769
	for (sourceDonnees in nombrePoints) {
732
			'<td class="label-station">Lieu précis</td>'+
Line 770... Line -...
770
		if (typeof(maille.nombrePoints[sourceDonnees]) == 'undefined') {
-
 
771
			maille.nombrePoints[sourceDonnees] = nombrePoints[sourceDonnees];
-
 
772
		} else {
-
 
773
			maille.nombrePoints[sourceDonnees] += nombrePoints[sourceDonnees];
-
 
774
		}
-
 
775
	}
-
 
776
	colorerMaille(maille);
-
 
777
}
-
 
778
 
-
 
779
function supprimerPointsListe(sourceDonnees) {
-
 
Line 780... Line 733...
780
	var index = 0;
733
		'</tr>'+
781
	while (index < points.length) {
734
		'<tr>'+
782
		if (points[index].source == sourceDonnees) {
735
			'<td class="image-station"><img src="'+clusterImageUrl+'" width="20" height="20" /></td>'+
783
			points.splice(index, 1);
736
			'<td class="label-station">Groupe de stations proches</td>'+
784
		} else {
-
 
785
			index ++;
737
		'</tr>'+
786
		}
738
	'</table></div>';
787
	}
-
 
788
}
739
	return div;
789
 
740
}
Line 790... Line 741...
790
function transformerMaillesEnPoints(sourceDonnees) {
741
 
791
	coucheSites.eachLayer(function(layer) {
742
 
792
		if (layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[sourceDonnees]) != 'undefined') {
743
function surClicMarqueur(event) {
793
			supprimerSourceDansMaille(layer, sourceDonnees);
-
 
794
		}
744
	var nombreMarkers = event.target.recupererMarkers().length;
795
	});
745
	if (nombreMarkers == 1 || map.getZoom() == map.getMaxZoom()) {
796
	for (var index = 0; index < points.length; index ++) {
746
		recupererObservations(event.target);
-
 
747
	} else {
797
		coucheSites.addLayer(points[index]);
748
		map.setView(event.target.getLatLng(), Math.min(map.getZoom()+2, map.getMaxZoom()));
-
 
749
	}
798
	}
750
}
799
}
751
 
800
 
-
 
801
function surClicMarqueur(event) {
-
 
802
	var latitude = event.target.getLatLng().lat;
752
function recupererObservations(cluster) {
803
	var longitude = event.target.getLatLng().lng;
753
	pointClique = cluster;
804
	pointClique = event.target;
-
 
805
	afficherMessageChargement('observations');
-
 
806
	var parametres = {
754
	var latlng = cluster.getLatLng();
807
		"source" : pointClique.source,
755
	afficherMessageChargement('observations');
808
		"num_taxon" : numTaxon,
756
	var parametres = {
809
		"referentiel" : referentiel,
757
		"source" : recupererSourcesCluster(cluster),
810
		"auteur" : auteur,
758
		"stations" : construireListeStationsCluster(cluster),
811
		"nn" : nn,
759
		"num_taxon" : numTaxon,
Line -... Line 760...
-
 
760
		"nn" : nn,
-
 
761
		"referentiel" : referentiel,
-
 
762
		"auteur" : auteur,
-
 
763
		"date_debut" : dateDebut,
-
 
764
		"date_fin" : dateFin,
-
 
765
		"nb_jours" : nbJours
-
 
766
	};
-
 
767
	url = urlBase + "observations?" + convertirEnParametresUrl(parametres);
-
 
768
	fonctionCallback = traiterDonneesObservations;
-
 
769
	executerAJAX();
-
 
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(',');
812
		"type_site" : pointClique.typeSite,
781
}
813
		"date_debut" : dateDebut,
782
 
814
		"date_fin" : dateFin,
783
function construireListeStationsCluster(cluster) {
815
		"longitude" : longitude,
784
	var markers = cluster.recupererMarkers();
816
		"latitude" : latitude,
785
	var listePoints = [];
Line 839... Line 808...
839
			}
808
			}
840
		}
809
		}
841
	}
810
	}
842
}
811
}
Line 843... Line -...
843
 
-
 
844
function viderListeObservations() {
-
 
845
	obsStation = new Array();
-
 
846
}
-
 
Line 847... Line 812...
847
 
812
 
848
 
813
 
Line 849... Line 814...
849
 
814
 
850
 
815
 
851
// ====================================================================
816
// ====================================================================
852
// Gestion de l'infobulle
817
// Gestion de l'infobulle
Line 853... Line 818...
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;
-
 
826
	var longitude = pointClique.getLatLng().lng;
-
 
827
	infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 380});
-
 
828
	infoBulle.setLatLng(new L.LatLng(latitude, longitude));
-
 
829
	infoBulle.setContent($("#tpl-obs").html());
-
 
830
	infoBulle.openOn(map);
-
 
831
	remplirContenuPopup();
-
 
832
	$('#info-bulle').css('width', '99%');
-
 
833
	$('#observations').css('height', '250px');
861
	var longitude = pointClique.getLatLng().lng;
834
	$('#observations').css('overflow', 'auto');
Line 862... Line 835...
862
	infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 350});
835
	$('.leaflet-popup-scrolled').css('overflow', 'visible');
863
	infoBulle.setLatLng(new L.LatLng(latitude, longitude));
836
}
864
	infoBulle.setContent($("#tpl-obs").html());
837
 
Line 878... Line 851...
878
	}
851
	}
879
	return largeurInfoBulle;
852
	return largeurInfoBulle;
880
}
853
}
Line 881... Line 854...
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%');
Line 885... Line 858...
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();
Line 891... Line 864...
891
	afficherTexteStationId();
864
	afficherTexteStationId();
892
}
865
}
Line 898... Line 871...
898
	infoBulle = null;
871
	infoBulle = null;
899
}
872
}
Line 900... Line 873...
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);
Line 906... Line 879...
906
}
879
}
907
 
-
 
908
function selectionnerOnglet() {
-
 
909
	$("#obs-vue-" + typeAffichage).css("display", "block");
880
 
910
	$('#obs-tableau-lignes').empty();
881
function afficherTableau() {
911
	$('#obs-liste-lignes').empty();
-
 
912
	if (typeAffichage=='liste') {
-
 
913
		$("#obs-vue-tableau").css("display", "none");
882
	construireListeObservations();
914
	} else {
-
 
915
		$("#obs-vue-liste").css("display", "none");
883
	afficherPagination();
Line 916... Line 884...
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]);
-
 
924
		}
-
 
925
	}
891
			obsStation.push(obsJSON.observations[index]);
926
	var obsPage = [];
-
 
927
	for (var index = 0; index < obsStation.length; index ++) {
-
 
928
		obsPage.push(obsStation[index]);
892
		}
Line 929... Line 893...
929
	}
893
	}
-
 
894
	pagineur.total = obsStation.length;
930
	$("#tpl-obs-"+typeAffichage).tmpl(obsPage).appendTo("#obs-"+typeAffichage+"-lignes");
895
}
931
}
896
 
932
 
897
function afficherPagination() {
933
function afficherOnglets() {
898
	$(".navigation").pagination(pagineur.total, {
934
	var $tabs = $('#obs').tabs();
899
		items_per_page:pagineur.limite,
-
 
900
		callback:afficherObservationsDansHTML,
935
	$('#obs').bind('tabsselect', function(event, ui) {
901
		next_text:'Suivant',
936
		if (ui.panel.id == 'obs-vue-tableau') {
902
		prev_text:'Précédent',
937
			surClicAffichageTableau();
903
		prev_show_always:false,
938
		} else if (ui.panel.id == 'obs-vue-liste') {
-
 
939
			surClicAffichageListe();
-
 
940
		}
-
 
941
	});
-
 
942
	if (obsJSON.total > 4) {
-
 
943
		surClicAffichageTableau();
904
		num_edge_entries:1,
Line 944... Line 905...
944
	} else {
905
		num_display_entries:4,
945
		$tabs.tabs('select', "#obs-vue-liste");
-
 
946
	}
906
		load_first_page:true
947
}
907
	});
948
 
908
}
949
function surClicAffichageTableau() {
909
 
950
	typeAffichage = 'tableau';
-
 
951
	selectionnerOnglet();
910
function afficherObservationsDansHTML(indexPage) {
952
	ajouterObservationsDansHTML();
911
	$("#obs-tableau-lignes").empty();
-
 
912
	if (typeof(indexPage) == 'undefined') {
953
	mettreAJourTableauTriable("#obs-tableau");
913
		indexPage = 0;
-
 
914
	}
-
 
915
	var depart = indexPage * pagineur.limite;
954
}
916
	var obsPage = [];
955
 
917
	for (var index = depart; index < depart + pagineur.limite; index ++) {
Line 956... Line 918...
956
function surClicAffichageListe() {
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: { 
Line 979... Line 941...
979
			1: { 
941
			1: { 
980
            	sorter:'date_cel' 
942
            	sorter:'date_cel'
981
        	} 
943
        	} 
Line 982... Line 944...
982
    	}
944
    	}
983
	});
945
	});
984
}
946
}
-
 
947
 
985
 
948
function mettreAJourTableauTriable() {
986
function mettreAJourTableauTriable(element) {
949
	$("#obs-tableau").trigger('update');
987
	$(element).trigger('update');
950
}