Subversion Repositories eFlore/Applications.moissonnage

Rev

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

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