Subversion Repositories eFlore/Applications.moissonnage

Rev

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

Rev 7 Rev 28
Line 1... Line 1...
1
// Javascript Document
1
// Javascript Document
Line 2... Line 2...
2
 
2
 
3
 
3
 
4
//==============================================================
4
// ==============================================================
5
//  FONCTIONS ADDITIONNELLES POUR GERER LES URLS
5
//  FONCTIONS ADDITIONNELLES POUR GERER LES URLS
6
convertirEnParametresUrl = function(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)
11
			continue;
11
			continue;
12
		parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut].toString();
12
		parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut].toString();
13
	}
13
	}
Line 14... Line 14...
14
	return parametresUrl;
14
	return parametresUrl;
-
 
15
};
15
};
16
 
16
 
17
function estParametreDansUrl(nomParametre) {
17
parametreDansUrl = function(nomParametre) {
18
	var estDansUrl = false;
18
	var listeParametres = location.search.substring(1).split("&");
19
	var listeParametres = location.search.substring(1).split("&");
19
	for (var index = 0; index < listeParametres.length; index ++) {
20
	for (var index = 0; index < listeParametres.length; index ++) {
20
		var split = listeParametres[index].split("=");
21
		var split = listeParametres[index].split("=");
21
		if (split[0] == nomParametre) {
22
		if (split[0] == nomParametre) {
22
			return true;
23
			estDansUrl = true;
23
		}
24
		}
Line 24... Line 25...
24
	}
25
	}
Line 25... Line 26...
25
	return false;
26
	return estDansUrl;
-
 
27
};
-
 
28
 
-
 
29
// =============================================================
-
 
30
 
-
 
31
 
-
 
32
 
-
 
33
var map = null,
-
 
34
optionsCoucheOSM = {
-
 
35
	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>',
-
 
37
	maxZoom: 18
-
 
38
},
-
 
39
optionsCoucheGoogle = {
-
 
40
	attribution: 'Map data &copy;' + new Date().getFullYear() + ' <a href="http://maps.google.com">Google</a>',
-
 
41
	maxZoom: 18
26
};
42
},
27
 
43
coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
28
//=============================================================
44
	optionsCoucheOSM),
29
 
45
couchePlanGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
30
 
46
	optionsCoucheGoogle),
-
 
47
coucheSatelliteGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
31
 
48
	optionsCoucheGoogle),
32
var map = null,
-
 
33
optionsCarte = {
49
optionsCarte = {
34
	center : new L.LatLng(46, 2),
50
	center : new L.LatLng(46, 2),
35
	zoom : 6,
-
 
36
	minZoom : 3,
-
 
37
	maxBounds : [[-85.051129, -180], [85.051129, 180]]
-
 
Line 38... Line 51...
38
},
51
	zoom : 6,
39
coucheOSM, couchePlanGoogle, coucheSatelliteGoogle,
52
	minZoom : 3,
Line 40... Line 53...
40
bordure = null,
53
	maxBounds : [[-85.051129, -180], [85.051129, 180]],
-
 
54
	layers : [couchePlanGoogle]
41
legende = null;
55
},
42
 
56
legende = null,
Line 60... Line 74...
60
function initialiserWidget() {
74
function initialiserWidget() {
61
	initialiserCarte();
75
	initialiserCarte();
62
	initialiserListeners();
76
	initialiserListeners();
63
	initialiserPanneauControle();
77
	initialiserPanneauControle();
64
	chargerLimitesCommunales();
78
	chargerLimitesCommunales();
65
	if (!parametreDansUrl('source')) {
79
	if (!estParametreDansUrl('source')) {
66
		initialiserSources();
80
		initialiserSources();
67
	}
81
	}
68
	programmerRafraichissementCarte();
82
	programmerRafraichissementCarte();
69
}
83
}
Line 70... Line 84...
70
 
84
 
71
$(window).resize(function() {
85
$(window).resize(function() {
-
 
86
	dimensionnerCarte();
-
 
87
	if (infoBulle != null) {
-
 
88
		redimensionnerPopup();
72
	dimensionnerCarte();
89
	}
Line 73... Line 90...
73
});
90
});
74
 
91
 
75
 
92
 
76
function dimensionnerCarte() {
93
function dimensionnerCarte() {
Line 77... Line 94...
77
	$('#map').height($(window).height());
94
	$('#map').height($(window).height());
78
	$('#map').width($(window).width());
95
	$('#map').width($(window).width());
79
}
-
 
80
 
96
}
81
function initialiserCarte() {
97
 
82
	dimensionnerCarte();
-
 
83
	// afficher la carte et ajouter un fond cartographique OpenStreetMap
-
 
84
	map = L.map('map', optionsCarte);
-
 
85
	coucheSites.addTo(map);
-
 
86
	
-
 
87
	var optionsCoucheOSM = {
-
 
88
		attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,'
-
 
89
		+ ' <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
-
 
90
		maxZoom: 18
-
 
91
	};
-
 
92
	var optionsCoucheGoogle = {
-
 
93
		attribution: 'Map data &copy;' + new Date().getFullYear() + ' <a href="http://maps.google.com">Google</a>',
-
 
94
		maxZoom: 18
98
function initialiserCarte() {
95
	};
-
 
96
	coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
-
 
97
		optionsCoucheOSM);
99
	dimensionnerCarte();
98
	coucheOSM.addTo(map);
-
 
99
	couchePlanGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
-
 
100
		optionsCoucheGoogle);
100
	map = L.map('map', optionsCarte);
101
	couchePlanGoogle.addTo(map);
-
 
102
	coucheSatelliteGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
-
 
103
		optionsCoucheGoogle);
101
	coucheSites.addTo(map);
104
	coucheSatelliteGoogle.addTo(map);
102
	coucheOSM.addTo(map);
105
	
103
	couchePlanGoogle.addTo(map);
106
	// ajout echelle
104
	coucheSatelliteGoogle.addTo(map);
107
	var echelle = new L.Control.Scale({
105
	var echelle = new L.Control.Scale({
108
		maxWidth : 100,
106
		maxWidth : 100,
109
		metric : true,
107
		metric : true,
110
		imperial : false,
108
		imperial : false,
111
		updateWhenIdle : true
-
 
112
	});
-
 
113
	map.addControl(echelle);
-
 
114
}
-
 
115
 
-
 
116
function chargerLimitesCommunales() {
-
 
117
	/*if (urlsLimitesCommunales != null) {
-
 
118
		for (urlId in urlsLimitesCommunales) { 
-
 
119
			var url = urlsLimitesCommunales[urlId];
-
 
120
			var track = new L.KML(url, {async: true});
-
 
121
			/*ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
-
 
122
			alert(url);
-
 
123
			ctaLayer.setMap(map);
-
 
124
		}
109
		updateWhenIdle : true
125
	}*/
-
 
126
}
110
	});
127
 
111
	map.addControl(echelle);
128
function initialiserListeners() {
-
 
129
	// evenements sur deplacement ou zoom sur la carte
112
}
130
	map.on('moveend', programmerRafraichissementCarte);
113
function initialiserListeners() {
-
 
114
	map.on('moveend', surChangementVueSurCarte);
131
	map.on('zoomend', programmerRafraichissementCarte);
115
	map.on('zoomend', surChangementVueSurCarte);
132
 
116
	map.on('popupclose', function(e) {
Line 133... Line 117...
133
	map.on('popupclose', function(e) {
117
		masquerInfoBulle();
134
		masquerInfoBulle();
118
		programmerRafraichissementCarte();
Line 141... Line 125...
141
		"Plan" : couchePlanGoogle,
125
		"Plan" : couchePlanGoogle,
142
		"Satellite" : coucheSatelliteGoogle
126
		"Satellite" : coucheSatelliteGoogle
143
	};
127
	};
Line 144... Line 128...
144
 
128
 
145
	var overlayMaps = {};
129
	var overlayMaps = {};
146
	if (!parametreDansUrl('source')) {
130
	if (!estParametreDansUrl('source')) {
147
		for (var index = 0; index < nomSources.length; index ++) {
131
		for (var index = 0; index < nomSources.length; index ++) {
148
			overlayMaps[nomSources[index]] = new L.LayerGroup();
132
			overlayMaps[nomSources[index]] = new L.LayerGroup();
149
		}
133
		}
150
	}
134
	}
-
 
135
	L.control.layers(baseMaps, overlayMaps).addTo(map);
-
 
136
	coucheOSM.bringToBack();
-
 
137
	couchePlanGoogle.bringToFront();
Line 151... Line 138...
151
	L.control.layers(baseMaps, overlayMaps).addTo(map);
138
	coucheSatelliteGoogle.bringToBack();
152
	
139
	
153
	// garder par defaut la couche plan google comme selectionnee dans le panel
140
	// garder par defaut la couche plan google comme selectionnee dans le panel
154
	var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector');
141
	var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector');
155
	selecteursFonds[0].checked = false;
142
	selecteursFonds[0].checked = false;
-
 
143
	selecteursFonds[1].checked = true;
-
 
144
	selecteursFonds[2].checked = false;
156
	selecteursFonds[1].checked = true;
145
}
-
 
146
 
-
 
147
function chargerLimitesCommunales() {
-
 
148
	if (urlsLimitesCommunales != null) {
-
 
149
		for (var index = 0; index < urlsLimitesCommunales.length; index ++) {
157
	selecteursFonds[2].checked = false;
150
			var url = urlsLimitesCommunales[index];
158
	coucheOSM.bringToBack();
151
			var coucheDepartement = new L.KML(url, {async: true});
-
 
152
			coucheDepartement.on("loaded", function(e) {
-
 
153
				map.fitBounds(e.target.getBounds());
-
 
154
			});
-
 
155
			map.addLayer(coucheDepartement);
159
	couchePlanGoogle.bringToFront();
156
		}
Line 160... Line 157...
160
	coucheSatelliteGoogle.bringToBack();
157
	}
161
}
158
}
162
 
159
 
Line 174... Line 171...
174
			changerSource(event.target.value);
171
			changerSource(event.target.value);
175
		}
172
		}
176
	});
173
	});
177
}
174
}
Line -... Line 175...
-
 
175
 
-
 
176
function surChangementVueSurCarte() {
-
 
177
	if (doitRafraichirCarte == false) {
-
 
178
		doitRafraichirCarte = true;
-
 
179
	} else {
-
 
180
		programmerRafraichissementCarte();
-
 
181
	}
Line 178... Line 182...
178
 
182
}
179
 
183
 
180
function programmerRafraichissementCarte() {
184
function programmerRafraichissementCarte() {
181
	if(timer != null) {
185
	if(timer != null) {
Line 197... Line 201...
197
	coucheSites.clearLayers();
201
	coucheSites.clearLayers();
198
}
202
}
Line 199... Line 203...
199
 
203
 
200
 
204
 
201
function changerSource(projetClique) {
205
function changerSource(projetClique) {
202
	// dechecker les autres controles d'overlays dans le panel
206
	// deselctionner les autres boutons des controles d'overlays dans le panel
203
	for (var index = 0; index < overlays.length; index ++) {
207
	for (var index = 0; index < overlays.length; index ++) {
204
		if (overlays[index].value != projetClique) {
208
		if (overlays[index].value != projetClique) {
205
			overlays[index].checked = false;
209
			overlays[index].checked = false;
Line 231... Line 235...
231
	if (requeteEnCours()) {
235
	if (requeteEnCours()) {
232
		masquerMessageChargement();
236
		masquerMessageChargement();
233
		requeteChargementPoints.abort();
237
		requeteChargementPoints.abort();
234
	}
238
	}
235
	requeteChargementPoints = $.getJSON(url).complete(function() {
239
	requeteChargementPoints = $.getJSON(url).complete(function() {
236
		fonctionCallback(requeteChargementPoints.responseText);
240
		fonctionCallback();
237
	});
241
	});
238
}
242
}
Line 239... Line 243...
239
 
243
 
240
function requeteEnCours() {
244
function requeteEnCours() {
241
	return (requeteChargementPoints != null && requeteChargementPoints.readyState != 4);
245
	return (requeteChargementPoints != null && requeteChargementPoints.readyState != 4);
Line -... Line 246...
-
 
246
}
-
 
247
 
-
 
248
function retourRequeteOK() {
-
 
249
	return ((requeteChargementPoints.status == 200 || requeteChargementPoints.status == 304)
-
 
250
		|| requeteChargementPoints.status == 0);
Line 242... Line 251...
242
}
251
}
243
 
252
 
244
 
-
 
245
 
253
 
-
 
254
 
-
 
255
function chargerLocalisations() {
-
 
256
	// generer l'URL du script a interroger sur le serveur
246
function chargerLocalisations() {
257
	var coordonneesBordure = calculerCoordonneesBordure();
-
 
258
	var parametres = {
-
 
259
		"source" : source,
247
	// generer l'URL du script a interroger sur le serveur
260
		"num_taxon" : num_taxon,
-
 
261
		"referentiel" : referentiel,
-
 
262
		"dept" : dept,
248
	bordure = map.getBounds();
263
		"auteur" : auteur,
Line 249... Line 264...
249
	var coordonneesBordure = calculerCoordonneesBordure();
264
		"bbox" : coordonneesBordure,
250
	var parametres = {"num_taxon" : num_taxon, "referentiel" : referentiel, "dept" : dept,
-
 
251
			"utilisateur" : utilisateur, "bbox" : coordonneesBordure, "zoom" : map.getZoom()};
-
 
252
	url = urlBase + source + "/stations?" + convertirEnParametresUrl(parametres);
-
 
253
	
-
 
254
	fonctionCallback = function(JSONtext) {
-
 
255
		masquerMessageChargement();
-
 
256
		if (requeteChargementPoints.status != 200 && requeteChargementPoints.status != 304
-
 
257
			&& typeof(JSONtext) != 'undefined') {
-
 
258
			alert(JSONtext);
-
 
259
			return;
-
 
260
		}
-
 
261
		
-
 
262
		var data = eval("(function(){return " + JSONtext + ";})()");
265
		"zoom" : map.getZoom()
263
		if (typeof(data) != 'undefined' && typeof(data.features) != 'undefined') {
266
	};
Line 264... Line 267...
264
			ajouterObjets(data);
267
	url = urlBase + "stations?" + convertirEnParametresUrl(parametres);
-
 
268
	
265
		}
269
	fonctionCallback = traiterDonneesStations;
266
	}
270
	executerAJAX();
267
	executerAJAX();
271
}
268
}	
272
 
269
 
-
 
270
function calculerCoordonneesBordure() {
273
function calculerCoordonneesBordure() {
271
	var ouest = bordure.getSouthWest().lng,
274
	var bordure = map.getBounds();
272
		sud = Math.max(bordure.getSouthWest().lat, -85.051129),
275
	var ouest = bordure.getSouthWest().lng,
273
		est = bordure.getNorthEast().lng,
276
		sud = Math.max(bordure.getSouthWest().lat, -85.051129),
274
		nord = Math.min(bordure.getNorthEast().lat, 85.051129);
277
		est = bordure.getNorthEast().lng,
Line 283... Line 286...
283
	if (est < -180) {
286
	if (est < -180) {
284
		est += 360;
287
		est += 360;
285
	} else if (est > 180) {
288
	} else if (est > 180) {
286
		est -= 360;
289
		est -= 360;
287
	}
290
	}
288
	
-
 
289
	return [ouest, sud, est, nord].join(',');
291
	return [ouest, sud, est, nord].join(',');
290
}
292
}
Line -... Line 293...
-
 
293
 
-
 
294
function traiterDonneesStations() {
-
 
295
	masquerMessageChargement();
-
 
296
	
-
 
297
	var texte = requeteChargementPoints.responseText;
-
 
298
	if (!retourRequeteOK()) {
-
 
299
		alert(texte);
-
 
300
	} else {
-
 
301
		var donneesJSON = eval("(function(){return " + texte + ";})()");
-
 
302
		if (typeof(donneesJSON) != 'undefined' && typeof(donneesJSON.features) != 'undefined') {
-
 
303
			ajouterObjets(donneesJSON);
-
 
304
		}
-
 
305
	}
-
 
306
}
Line 291... Line 307...
291
 
307
 
292
 
308
 
293
function ajouterObjets(data) {
309
function ajouterObjets(data) {
294
	coucheSites.clearLayers();
-
 
295
	var contientMailles = false;
310
	coucheSites.clearLayers();
296
	// ajout des nouveaux points a la couche
311
	var contientMailles = (data.features[0].properties.typeSite == 'MAILLE');
297
	for (var i = 0; i < data.features.length; i ++) {
-
 
298
		var typeSite = data.features[i].properties.typeSite;	
-
 
299
		var objet = null;
-
 
300
		switch (typeSite) {
-
 
301
			case 'MAILLE' : {
312
	for (var index = 0; index < data.features.length; index ++) {
302
				contientMailles = true;
313
		switch (data.features[index].properties.typeSite) {
303
				ajouterMaille(data.features[i]);
-
 
304
				break;
314
			case 'MAILLE'  : ajouterMaille(data.features[index]);
305
			}
-
 
306
			case 'COMMUNE' :
315
				break;
307
			case 'STATION' : {
316
			case 'COMMUNE' :
308
				ajouterPoint(data.features[i]);
-
 
309
				break;
317
			case 'STATION' : ajouterPoint(data.features[index]);
310
			}
318
				break;
311
		}
-
 
312
	}
319
		}
313
	// afficher/masquer la legende
320
	}
314
	if (contientMailles) {
321
	if (contientMailles && legende == null) {
315
		afficherLegende();
322
		afficherLegende();
316
	} else {
323
	} else if (legende != null) {
317
		masquerLegende();
324
		masquerLegende();
Line 318... Line -...
318
	}
-
 
319
}
325
	}
320
 
326
}
321
 
327
 
322
function ajouterMaille(feature) {
328
function ajouterMaille(feature) {
323
	var coordonnees = [];
329
	var coordonnees = [];
Line 340... Line 346...
340
	// afficher le nombre de points inclus dans la maille
346
	// afficher le nombre de points inclus dans la maille
341
	afficherNombreStationsDansMaille(objet);
347
	afficherNombreStationsDansMaille(objet);
342
}
348
}
Line 343... Line 349...
343
 
349
 
344
function afficherNombreStationsDansMaille(maille) {
-
 
345
	var recul = 0;
350
function afficherNombreStationsDansMaille(maille) {
346
	if (maille.nombrePoints >= 10000) {
-
 
347
		recul = 14;
351
	// comme la div qui contiendra la valeur du nombre de stations va se placer dans la page
348
	} else if (maille.nombrePoints >= 1000) {
352
	// au centre de la maille (et qui va servir de point d'ancrage pour le bord gauche par defaut)
349
		recul = 9;
353
	// il est necessaire de creer un decalage vers la gauche en fonction du nombre de chiffres
350
	} else if (maille.nombrePoints >= 100) {
-
 
351
		recul = 5;
-
 
352
	}
354
	var decalage = calculerDecalagePositionnementNombre(maille.nombrePoints);
353
	var sudMaille    = maille._originalPoints[0].y,
355
	var sudMaille    = maille._originalPoints[0].y,
354
		ouestMaille  = maille._originalPoints[0].x,
356
		ouestMaille  = maille._originalPoints[0].x,
355
		nordMaille   = maille._originalPoints[2].y,
357
		nordMaille   = maille._originalPoints[2].y,
356
		estMaille    = maille._originalPoints[2].x,
358
		estMaille    = maille._originalPoints[2].x,
357
		centreMaille = new L.Point((ouestMaille + estMaille) / 2 - recul, (sudMaille + nordMaille) / 2);
-
 
358
		
359
		centreMaille = new L.Point((ouestMaille+estMaille)/2 - decalage, (sudMaille+nordMaille)/2);	
359
	var divIcon = new L.divIcon({
360
	var divIcon = new L.divIcon({
360
		className : "nombre-sites",
361
		className : "nombre-sites",
361
		html : maille.nombrePoints
362
		html : maille.nombrePoints
362
	});
363
	});
Line 366... Line 367...
366
	});
367
	});
367
	marqueurDiv.on('click', clicSurMaille);
368
	marqueurDiv.on('click', clicSurMaille);
368
	coucheSites.addLayer(marqueurDiv);
369
	coucheSites.addLayer(marqueurDiv);
369
}
370
}
Line -... Line 371...
-
 
371
 
-
 
372
function calculerDecalagePositionnementNombre(nombrePoints) {
-
 
373
	var recul = 0;
-
 
374
	if (nombrePoints >= 10000) {
-
 
375
		recul = 14;
-
 
376
	} else if (nombrePoints >= 1000) {
-
 
377
		recul = 9;
-
 
378
	} else if (nombrePoints >= 100) {
-
 
379
		recul = 5;
-
 
380
	}
-
 
381
	return recul;
-
 
382
}
370
 
383
 
371
function clicSurMaille(event) {
384
function clicSurMaille(event) {
372
	if (event.target._zIndex != null) {
385
	if (event.target._zIndex != null) {
373
		map.fitBounds(event.target.options.maille)
386
		map.fitBounds(event.target.options.maille)
374
	} else {
387
	} else {
375
		map.fitBounds(event.target.getBounds());
388
		map.fitBounds(event.target.getBounds());
376
	}
389
	}
Line -... Line 390...
-
 
390
}
377
}
391
 
-
 
392
// generer la couleur a afficher pour les mailles
-
 
393
function getColor(nombrePoints) {
-
 
394
	var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64},
378
 
395
		seuils = [1, 10, 50 ,100, 500, 1000, 2500],
-
 
396
		pas = 26,
379
function getColor(nbPoints) {
397
		position = 0;
-
 
398
	for (var index = 1; index < seuils.length-1 && nombrePoints >= seuils[index]; index ++) {
-
 
399
		position ++;
-
 
400
	}
-
 
401
	couleur.vert -= position*pas;
-
 
402
	return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')';
380
	if (nbPoints >= 2500) {
403
	
381
		return '#E74440';
404
	/*var codeHexa = 'rgb(231,224,64)';
382
	} else if (nbPoints >= 1000) {
405
	if (nombrePoints >= 2500) {
383
		return '#E75E40';
406
		codeHexa =  'rgb(231,68,64)';
384
	} else if (nbPoints >= 500) {
407
	} else if (nombrePoints >= 1000) {
385
		return '#E77840';
408
		codeHexa =  'rgb(231,94,64)';
386
	} else if (nbPoints >= 100) {
409
	} else if (nombrePoints >= 500) {
387
		return '#E79240';
410
		codeHexa =  'rgb(231,120,64)';
388
	} else if (nbPoints >= 50) {
411
	} else if (nombrePoints >= 100) {
389
		return '#E7AC40';
412
		codeHexa =  'rgb(231,146,64)';
390
	} else if (nbPoints >= 10) {
413
	} else if (nombrePoints >= 50) {
391
		return '#E7C640';
414
		codeHexa =  'rgb(231,172,64)';
392
	} else {
415
	} else if (nombrePoints >= 10) {
-
 
416
		codeHexa =  'rgb(231,198,64)';
393
		return '#E7E040';
417
	}
Line 394... Line 418...
394
	}
418
	return codeHexa;*/
395
}
419
}
-
 
420
 
396
 
421
 
-
 
422
function ajouterPoint(feature) {
397
 
423
	var iconePoint = new L.Icon({ iconUrl : pointImageUrl,   iconSize : [16, 16] }),
398
function ajouterPoint(feature) {
424
		iconeCommune   = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }),
399
	var point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]),
425
		icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune,
400
		icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune,
426
		point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]),
401
		marker = new L.Marker(point, {
427
		marker = new L.Marker(point, {
402
		icon : icone,
-
 
403
		type : feature.properties.typeSite,
428
			icon : icone,
404
		title : feature.properties.nom
429
			type : feature.properties.typeSite,
405
	}).addTo(map);
430
			title : feature.properties.nom
Line 406... Line 431...
406
	// evenement onclick sur marqueur pour recuperer les observations sur ce point
431
		}).addTo(map);
407
	marker.on('click', clicSurMarqueur);
-
 
408
	coucheSites.addLayer(marker);
-
 
409
}
-
 
410
 
432
	marker.on('click', surClicMarqueur);
411
 
433
	coucheSites.addLayer(marker);
412
function afficherLegende() {
434
}
413
	if (legende != null) {
-
 
414
		return;
-
 
415
	}
-
 
416
	legende = new L.Control({position : 'bottomright'});
-
 
417
	legende.onAdd = function(map) {
-
 
418
		var div = L.DomUtil.create('div', 'info');
-
 
419
		div.innerHTML = '<h4>' + titreLegende + '</h4>';
-
 
420
		var seuils = [1, 10, 50 ,100, 500, 1000, 2500];
-
 
421
		var labels = [];
435
 
422
		for (var i = 0; i < seuils.length; i ++) {
436
 
423
			div.innerHTML += '<div class="legend"><i style="background:' + getColor(seuils[i] + 1) + '"></i>' + seuils[i]
437
function afficherLegende() {
Line 424... Line 438...
424
				+ (i + 1 < seuils.length ? '&ndash;' + seuils[i + 1] : '+') + '</div>';
438
	legende = new L.Control({position : 'bottomright'});
-
 
439
	legende.onAdd = function(map) {
-
 
440
		return construireContenuHtmlLegende();
-
 
441
	};
425
		}
442
	map.addControl(legende);
-
 
443
}
-
 
444
 
426
		return div;
445
function construireContenuHtmlLegende() {
-
 
446
	var div = L.DomUtil.create('div', 'info');
-
 
447
	div.innerHTML = '<h4>' + titreLegende + '</h4>';
427
	};
448
	var seuils = [1, 10, 50 ,100, 500, 1000, 2500];
428
	map.addControl(legende);
449
	var labels = [];
-
 
450
	for (var i = 0; i < seuils.length; i ++) {
-
 
451
		div.innerHTML += 
-
 
452
			'<div class="legend">'+
-
 
453
				'<span style="background:' + getColor(seuils[i] + 1) + '"></span>'+
-
 
454
				seuils[i]+ (i + 1 < seuils.length ? '&ndash;' + seuils[i + 1] : '+')+
-
 
455
			'</div>';
429
}
456
	}
Line 430... Line 457...
430
 
457
	return div;
431
function masquerLegende() {
-
 
432
	if (legende != null) {
458
}
433
		map.removeControl(legende);
459
 
434
		legende = null;
460
function masquerLegende() {
435
	}
461
	map.removeControl(legende);
-
 
462
	legende = null;
-
 
463
}
436
}
464
 
437
 
465
 
-
 
466
 
438
 
467
function surClicMarqueur(event) {
-
 
468
	var latitude = event.target.getLatLng().lat;
-
 
469
	var longitude = event.target.getLatLng().lng;
439
 
470
	pointClique = event.target;
440
function clicSurMarqueur(event) {
471
	afficherMessageChargement('observations');
-
 
472
	var parametres = {
-
 
473
		"source" : source,
-
 
474
		"num_taxon" : num_taxon,
-
 
475
		"referentiel" : referentiel,
441
	// centrer la carte sur le marqueur
476
		"auteur" : auteur,
442
	var latitude = event.target.getLatLng().lat;
477
		"longitude" : longitude,
443
	var longitude = event.target.getLatLng().lng;
478
		"latitude" : latitude
444
	pointClique = event.target;
479
	};
445
	afficherMessageChargement('observations');
480
	url = urlBase + "observations?" + convertirEnParametresUrl(parametres);
446
	// charger les observations se trouvant sur ce point
-
 
Line 447... Line 481...
447
	var parametres = {"num_taxon" : num_taxon, "referentiel" : referentiel, "dept" : dept,
481
	fonctionCallback = traiterDonneesObservations;
448
		"utilisateur" : utilisateur, "longitude" : longitude, "latitude" : latitude};
-
 
449
	url = urlBase + source + "/observations?" + convertirEnParametresUrl(parametres);
-
 
450
	fonctionCallback = function(JSONtext) {
482
	executerAJAX();
451
		masquerMessageChargement();
-
 
452
		if (requeteChargementPoints.status != 200 && requeteChargementPoints.status != 304
483
}
453
				&& typeof(JSONtext) != 'undefined') {
484
 
454
			alert(JSONtext);
485
function traiterDonneesObservations() {
455
			return;
-
 
456
		}
486
	masquerMessageChargement();
457
		
487
	var texte = requeteChargementPoints.responseText;
458
		obsJSON = eval("(function(){return " + JSONtext + ";})()");
-
 
459
		// vider la liste des observations de l'infobulle precedente
488
	if (!retourRequeteOK()) {
460
		while (obsStation.length > 0) {
489
		alert(texte);
461
			obsStation.pop();
490
	} else {
462
		}
-
 
463
		if (obsJSON.total > 0) {
491
		
Line -... Line 492...
-
 
492
		obsJSON = eval("(function(){return " + texte + ";})()");
-
 
493
		viderListeObservations();
-
 
494
		if (obsJSON.total > 0) {
Line 464... Line -...
464
			// centrer la vue de la carte sur la station
-
 
465
			map.setView(new L.LatLng(latitude, longitude), map.getZoom());
-
 
466
			// afficher les observations dans une infobulle
-
 
Line -... Line 495...
-
 
495
			doitRafraichirCarte = false;
-
 
496
			map.setView(new L.LatLng(pointClique.getLatLng().lat, pointClique.getLatLng().lng), map.getZoom());
Line 467... Line -...
467
			afficherInfoBulle();
-
 
468
		} else if (infoBulle != null)  {
497
			afficherInfoBulle();
469
			// supprimer l'infobulle
498
		} else if (infoBulle != null)  {
470
			masquerInfoBulle();
499
			masquerInfoBulle();
471
		}
500
		}
Line 472... Line 501...
472
	}
501
	}
473
	executerAJAX();
-
 
474
}
502
}
475
 
503
 
476
 
504
function viderListeObservations() {
477
///////////////////////////////////////
505
	obsStation = new Array();
478
//             INFOBULLE             //
-
 
479
///////////////////////////////////////
506
}
480
 
507
 
-
 
508
 
-
 
509
// ====================================================================
-
 
510
//  Gestion de l'infobulle
-
 
511
 
-
 
512
var obsJSON = null,
-
 
513
	pointClique = null,
-
 
514
	obsStation = [],
-
 
515
	typeAffichage = "";
-
 
516
 
-
 
517
function afficherInfoBulle() {
-
 
518
	var latitude = pointClique.getLatLng().lat;
-
 
519
	var longitude = pointClique.getLatLng().lng;
-
 
520
	infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 350});
-
 
521
	infoBulle.setLatLng(new L.LatLng(latitude, longitude));
-
 
522
	infoBulle.setContent($("#tpl-obs").html());
-
 
523
	infoBulle.openOn(map);	
-
 
524
	remplirContenuPopup();
-
 
525
}
-
 
526
 
-
 
527
function definirLargeurInfoBulle() {
481
 
528
	var largeurViewPort = $(window).width();
482
var infoBulle = null,
529
	var lageurInfoBulle = null;
483
	obsJSON = null,
530
	if (largeurViewPort < 800) {
484
	pointClique = null,
531
		largeurInfoBulle = 400;
485
	obsStation = [],
532
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
486
	typeAffichage = "";
533
		largeurInfoBulle = 500;
487
 
534
	} else if (largeurViewPort >= 1200) {