Subversion Repositories eFlore/Applications.cel

Rev

Rev 2572 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2572 Rev 2605
Line 4... Line 4...
4
* Indication de certaines variables ajoutée par php
4
* Indication de certaines variables ajoutée par php
5
* var communeImageUrl ;
5
* var communeImageUrl ;
6
* var pointImageUrl ;
6
* var pointImageUrl ;
7
* var groupeImageUrlTpl ;
7
* var groupeImageUrlTpl ;
8
*/
8
*/
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage
10
	pointsOrigine = null,
-
 
11
	boundsOrigine = null,
-
 
12
	markerClusterer = null,
-
 
13
	map = null,
10
	map = null,
14
	infoBulle = new google.maps.InfoWindow(),
11
	infoBulle = new google.maps.InfoWindow(),
15
	stations = null,
12
	stations = null,
16
	pointClique = null,
13
	pointClique = null,
17
	carteCentre = new google.maps.LatLng(25, 10),
14
	carteCentre = new google.maps.LatLng(25, 10),
Line 70... Line 67...
70
	definirTailleOverlay();
67
	definirTailleOverlay();
71
	initialiserCarte();
68
	initialiserCarte();
72
	attribuerListenersOverlay();
69
	attribuerListenersOverlay();
73
	centrerTitreEtStats();
70
	centrerTitreEtStats();
74
	initialiserAffichagePanneauLateral();
71
	initialiserAffichagePanneauLateral();
75
	initialiserGestionnaireMarqueurs()
72
	initialiserGestionnaireMarqueurs();
76
	initialiserInfoBulle();
73
	initialiserInfoBulle();
77
	initialiserFormulaireContact();
74
	initialiserFormulaireContact();
78
	chargerLimitesCommunales();
75
	chargerLimitesCommunales();
79
	attribuerListenerCarte();
76
	attribuerListenerCarte();
80
}
77
}
Line 81... Line 78...
81
 
78
 
82
function getUrlVars() {
79
function getUrlVars() {
-
 
80
	var vars = [],
83
	var vars = [], hash;
81
		hash;
84
	if (window.location.href.indexOf('?') != -1) {
82
	if (window.location.href.indexOf('?') != -1) {
85
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
83
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
86
		for (var i = 0; i < hashes.length; i++) {
84
		for (var i = 0; i < hashes.length; i++) {
87
			hash = hashes[i].split('=');
85
			hash = hashes[i].split('=');
Line 335... Line 333...
335
function initialiserCarte() {
333
function initialiserCarte() {
336
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
334
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
337
	// Ajout de la couche OSM à la carte
335
	// Ajout de la couche OSM à la carte
338
	map.mapTypes.set('OSM', osmMapType);
336
	map.mapTypes.set('OSM', osmMapType);
Line -... Line 337...
-
 
337
 
-
 
338
	// Centrage sur bounding box si spécifiée
-
 
339
	if (bbox != null) {
-
 
340
		var pointsBbox = bbox.split(',');
-
 
341
		if (pointsBbox.length == 4) {
-
 
342
			var bounds = new google.maps.LatLngBounds(
-
 
343
				new google.maps.LatLng(parseFloat(pointsBbox[0]), parseFloat(pointsBbox[1])), // sud-ouest
-
 
344
				new google.maps.LatLng(parseFloat(pointsBbox[2]), parseFloat(pointsBbox[3])) // nord-est
-
 
345
			);
-
 
346
			// Apply fitBounds
-
 
347
			map.fitBounds(bounds);
-
 
348
			//console.log('bornes demandées: ' + bounds);
-
 
349
			/*var bds = map.getBounds(); // undefined si demandé trop tôt
-
 
350
			console.log('bornes obtenues: ' + bds);*/
-
 
351
		}
-
 
352
	}
339
 
353
 
340
	// écouteur sur changement de fond
354
	// écouteur sur changement de fond
341
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
355
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
342
		// licence par défaut
356
		// licence par défaut
343
		var mention = 'Observations du réseau <a href="http://www.tela-botanica.org/site:botanique" ' +
357
		var mention = 'Observations du réseau <a href="http://www.tela-botanica.org/site:botanique" ' +
Line 402... Line 416...
402
				lngSW = -156;
416
				lngSW = -156;
403
			}
417
			}
404
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
418
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
405
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
419
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
406
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
420
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
-
 
421
			// Répercussion de la bounding box dans l'URL afin de pouvoir copier-coller et se retrouver au même endroit
-
 
422
			var bboxParam = '' + map.getBounds().getSouthWest().lat() + ',' + lngSW + ',' + map.getBounds().getSouthWest().lat() + ',' + lngNE;
-
 
423
			mettreAJourUrlAvecBbox(bboxParam);
407
		} else {
424
		} else {
408
			programmerRafraichissementCarte();
425
			programmerRafraichissementCarte();
409
		}
426
		}
410
	}, 400);
427
	}, 400);
411
}
428
}
Line -... Line 429...
-
 
429
 
-
 
430
// ajoute ou met à jour le paramètre "bbox" de l'url dans la barre du navigateur
-
 
431
function mettreAJourUrlAvecBbox(bboxParam) {
-
 
432
	var urlCourante = window.location.href,
-
 
433
		urlAJour;
-
 
434
	//alert('url courante: ' + urlCourante);
-
 
435
	if (urlCourante.indexOf('bbox=') == -1) {
-
 
436
		if (urlVars && urlVars.length > 0) {
-
 
437
			urlAJour = urlCourante += '&bbox=' + bboxParam;
-
 
438
		} else {
-
 
439
			urlAJour = urlCourante += '?bbox=' + bboxParam;
-
 
440
		}
-
 
441
	} else {
-
 
442
		urlAJour = urlCourante.replace(/bbox=[\d\.,-]*/g, 'bbox=' + bboxParam);
-
 
443
	}
-
 
444
	//alert('url à jour: ' + urlAJour);
-
 
445
	mettreAJourUrl(urlAJour);
-
 
446
}
-
 
447
// met à jour l'url dans la barre du navigateur
-
 
448
function mettreAJourUrl(nouvelleUrl) {
-
 
449
	if (!!(window.history && window.history.pushState)) { // vérif si les méthodes existent sur le navigateur
-
 
450
		var currentState = window.history.state;
-
 
451
		if (currentState != nouvelleUrl) {
-
 
452
			window.history.pushState("tabarnak", "", nouvelleUrl);
-
 
453
		}
-
 
454
	}
-
 
455
}
412
 
456
 
413
var marqueurs = new Array();
457
var marqueurs = new Array();
414
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
458
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
415
	cacherMessageAucuneObs();
459
	cacherMessageAucuneObs();
416
	var url = stationsUrl+
460
	var url = stationsUrl+
Line 462... Line 506...
462
	centrerDansLaPage($('#message-aucune-obs'));
506
	centrerDansLaPage($('#message-aucune-obs'));
463
	$('#message-aucune-obs').hide();
507
	$('#message-aucune-obs').hide();
464
}
508
}
Line 465... Line 509...
465
 
509
 
-
 
510
premierChargement = true;
-
 
511
// Si on charge pour la première fois et qu'on a un filtre sur les données,
-
 
512
// il est peu probable que les marqueurs couvrent la Terre entière... on
466
premierChargement = true;
513
// ajuste donc la bbox aux données présentes - SAUF si on a spécifié une bbox !
467
function doitCentrerCarte() {
514
function doitCentrerCarte() {
468
	return premierChargement && urlVars != null && urlVars.length > 0;
515
	return premierChargement && ! bbox && urlVars != null && urlVars.length > 0;
Line 469... Line 516...
469
}
516
}
470
 
517
 
471
function rafraichirMarqueurs(data) {
518
function rafraichirMarqueurs(data) {
Line 484... Line 531...
484
			if(station != null) {
531
			if(station != null) {
485
				var nouveauMarqueur = creerMarqueur(station);
532
				var nouveauMarqueur = creerMarqueur(station);
486
				marqueurs.push(nouveauMarqueur);
533
				marqueurs.push(nouveauMarqueur);
487
			}
534
			}
488
		});
535
		});
489
		
536
 
490
		if (doitCentrerCarte()) {
537
		if (doitCentrerCarte()) {
491
			premierChargement = false;
538
			premierChargement = false;
492
			var bounds = new google.maps.LatLngBounds(),
539
			var bounds = new google.maps.LatLngBounds(),
493
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
540
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
494
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
541
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);