/trunk/widget/modules/carto/Carto.php |
---|
31,20 → 31,25 |
*/ |
class Carto extends WidgetCommun { |
const DS = DIRECTORY_SEPARATOR; |
const SERVICE_DEFAUT = 'carte-defaut'; |
const SERVICE_CARTO_NOM = 'CelWidgetMap'; |
const SERVICE_CARTO_ACTION_DEFAUT = 'carte-defaut'; |
private $carte = null; |
private $utilisateur = null; |
private $projet = null; |
private $dept = null; |
private $num_taxon = null; |
private $station = null; |
private $format = null;// Format des obs pour les stations (tableau/liste) |
/** |
* Méthode appelée par défaut pour charger ce widget. |
*/ |
public function executer() { |
$retour = null; |
extract($this->parametres); |
$this->extraireParametres(); |
if (!isset($carte)) { |
$carte = self::SERVICE_DEFAUT; |
} |
$methode = $this->traiterNomMethodeExecuter($carte); |
$methode = $this->traiterNomMethodeExecuter($this->carte); |
if (method_exists($this, $methode)) { |
$retour = $this->$methode(); |
} else { |
60,6 → 65,17 |
$this->envoyer($html); |
} |
} |
public function extraireParametres() { |
extract($this->parametres); |
$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT); |
$this->utilisateur = (isset($utilisateur) ? $utilisateur : '*'); |
$this->projet = (isset($projet) ? $projet : '*'); |
$this->dept = (isset($dept) ? $dept : '*'); |
$this->num_taxon = (isset($num_taxon) ? $num_taxon : '*'); |
$this->station = (isset($station) ? $station : null); |
$this->format = (isset($format) ? $format : null); |
} |
/** |
* Carte par défaut |
66,56 → 82,67 |
*/ |
public function executerCarteDefaut() { |
$widget = null; |
extract($this->parametres); |
$utilisateur = (isset($utilisateur) ? $utilisateur : '*'); |
$projet = (isset($projet) ? $projet : '*'); |
$dept = (isset($dept) ? $dept : '*'); |
$num_taxon = (isset($num_taxon) ? $num_taxon : '*'); |
// Création url données json |
$url_cel_carto = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelWidgetMap'); |
$url_json = "$url_cel_carto/carte-defaut-json/$utilisateur/$projet/$dept/$num_taxon"; |
$url_json = $this->contruireUrlServiceCarto('carte-defaut-json'); |
$url_base = sprintf($this->config['chemins']['baseURLAbsoluDyn'], ''); |
// Création des infos du widget |
$widget['donnees']['url_cel_carto'] = $url_cel_carto; |
$widget['donnees']['url_cel_carto'] = $this->contruireUrlServiceCarto(); |
$widget['donnees']['url_json'] = $url_json; |
$widget['donnees']['url_base'] = $url_base; |
$widget['donnees']['jquery_version'] = '1.4.4'; |
$widget['donnees']['utilisateur'] = $utilisateur; |
$widget['donnees']['projet'] = $projet; |
$widget['donnees']['dept'] = $dept; |
$widget['donnees']['num_taxon'] = $num_taxon; |
$widget['donnees']['utilisateur'] = $this->utilisateur; |
$widget['donnees']['projet'] = $this->projet; |
$widget['donnees']['dept'] = $this->dept; |
$widget['donnees']['num_taxon'] = $this->num_taxon; |
$widget['donnees']['taxons'] = $this->chargerTaxons(); |
if ($num_taxon != '*') { |
if ($this->num_taxon != '*') { |
$taxon_courrant = current($widget['donnees']['taxons']); |
$widget['donnees']['taxon_nom'] = $taxon_courrant['nom']; |
} |
$widget['squelette'] = 'carte_defaut'; |
if (isset($dept)) { |
if (isset($this->dept)) { |
// si on veut afficher les limites départemmentales on va compter et chercher les noms de fichiers |
$fichiersKml = $this->chercherFichierKml($dept); |
$fichiersKml = $this->chercherFichierKml(); |
$urls = null; |
foreach ($fichiersKml as $kml => $dossier){ |
$url_limites_communales = sprintf($this->config['carto']['limitesCommunaleUrlTpl'], $dossier, $kml); |
$widget['donnees']['url_limites_communales'][] = $url_limites_communales; |
$urls[] = $url_limites_communales; |
} |
$widget['donnees']['url_limites_communales'] = json_encode($urls); |
} |
return $widget; |
} |
private function contruireUrlServiceCarto($action = null) { |
// Création url données json |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::SERVICE_CARTO_NOM); |
if ($action) { |
$url .= "/$action"; |
$parametres_retenus = array(); |
$parametres_a_tester = array('station', 'utilisateur', 'projet', 'dept', 'num_taxon'); |
foreach ($parametres_a_tester as $param) { |
if ($this->$param != null && $this->$param != '*') { |
$parametres_retenus[$param] = $this->$param; |
} |
} |
if (count($parametres_retenus) > 0) { |
$parametres_url = array(); |
foreach ($parametres_retenus as $cle => $valeur) { |
$parametres_url[] = $cle.'='.$valeur; |
} |
$url .= '?'.implode('&', $parametres_url); |
} |
} |
$this->debug[] = $url; |
// Prendre en compte param "station" |
return $url; |
} |
private function chargerTaxons() { |
extract($this->parametres); |
$utilisateur = (isset($utilisateur) ? $utilisateur : '*'); |
$projet = (isset($projet) ? $projet : '*'); |
$dept = (isset($dept) ? $dept : '*'); |
$num_taxon = (isset($num_taxon) ? $num_taxon : '*'); |
// Récupération des données au format Json |
$service = "CelWidgetMap/taxons/$utilisateur/$projet/$dept/$num_taxon"; |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service); |
$url = $this->contruireUrlServiceCarto('taxons'); |
$json = $this->getDao()->consulter($url); |
$donnees = json_decode($json); |
142,9 → 169,9 |
return $taxons; |
} |
private function chercherFichierKml($dept){ |
private function chercherFichierKml(){ |
$chemins = explode(',', $this->config['carto']['communesKmzChemin']); |
$departements = explode(',', $dept);// plrs code de départements peuvent être demandés séparés par des virgules |
$departements = explode(',', $this->dept);// plrs code de départements peuvent être demandés séparés par des virgules |
$departements_trouves = array(); |
$fichiers = array(); |
foreach ($chemins as $dossier_chemin) { |
175,9 → 202,7 |
*/ |
public function executerObservations() { |
$widget = null; |
extract($this->parametres); |
$observations = $this->chargerObservation($station); |
$observations = $this->chargerObservation(); |
// Création des infos du widget |
if (isset($observations['commune'])) { |
198,21 → 223,14 |
} |
$widget['donnees']['observations'] = $observations; |
$widget['donnees']['station_id'] = $station; |
$widget['donnees']['station_id'] = $this->station; |
return $widget; |
} |
private function chargerObservation($station) { |
extract($this->parametres); |
$utilisateur = (isset($utilisateur) ? $utilisateur : '*'); |
$projet = (isset($projet) ? $projet : '*'); |
$dept = (isset($dept) ? $dept : '*'); |
$num_taxon = (isset($num_taxon) ? $num_taxon : '*'); |
private function chargerObservation() { |
// Récupération des données au format Json |
$service = "CelWidgetMap/observations/$station/$utilisateur/$projet/$dept/$num_taxon"; |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service); |
$url = $this->contruireUrlServiceCarto('observations'); |
$json = $this->getDao()->consulter($url); |
$donnees = json_decode($json); |
254,10 → 272,9 |
} |
private function choisirFormatSortie($observations_nbre) { |
extract($this->parametres); |
$sortie = 'obs_tableau'; |
if (isset($format) && $format != '*') { |
$sortie = ($format == 'tableau' ) ? 'obs_tableau' : 'obs_liste'; |
if (isset($this->format) && $this->format != '*') { |
$sortie = ($this->format == 'tableau' ) ? 'obs_tableau' : 'obs_liste'; |
} else { |
$sortie = ($observations_nbre > 4) ? 'obs_tableau' : 'obs_liste'; |
} |
268,6 → 285,7 |
// Récupération des données au format Json |
$service = 'CelImage/liste-ids?obsId='.implode(',', $obs_ids); |
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], $service); |
$this->debug[] = $url; |
$json = $this->getDao()->consulter($url); |
$donnees = json_decode($json); |
/trunk/widget/modules/carto/squelettes/carte_defaut.tpl.html |
---|
22,11 → 22,12 |
<link rel="shortcut icon" type="image/x-icon" href="http://www.tela-botanica.org/sites/commun/generique/images/favicones/tela_botanica.ico" /> |
<!-- Javascript : bibliothèques --> |
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> |
<!-- Google Map v3 --> |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.3&sensor=true"></script> |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.5&sensor=true&language=fr&region=FR"></script> |
<script type="text/javascript" src="http://www.tela-botanica.org/commun/google/map/3/markerclusterer/1.0/markerclusterer-1.0.pack.js"></script> |
<!-- Jquery --> |
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/<?=$jquery_version?>/jquery-<?=$jquery_version?>.min.js"></script> |
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/1.6.2/jquery-1.6.2.min.js"></script> |
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/tablesorter/2.0.5/jquery.tablesorter.min.js"></script> |
<script type="text/javascript" src="http://www.tela-botanica.org/commun/jquery/fancybox/1.3.4/jquery.fancybox-1.3.4.pack.js"></script> |
36,264 → 37,38 |
<!-- Javascript : appli carto --> |
<script type="text/javascript"> |
//<![CDATA[ |
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png'; |
var pointsOrigine = null; |
var boundsOrigine = null; |
var markerClusterer = null; |
var map = null; |
var urlsLimitesCommunales = <?=$url_limites_communales?>; |
var nt = '<?=$num_taxon?>'; |
var infoBulle = new google.maps.InfoWindow(); |
google.maps.event.addListener(infoBulle, 'domready', function() { |
// Onglet Tableau : Jquery => TableSorter |
if ($("#observations table").get() != '') { |
// add parser through the tablesorter addParser method |
$.tablesorter.addParser({ |
// Définition d'un id unique pour ce parsseur |
id: 'date_cel', |
is: function(s) { |
// retourne false si le parsseur n'est pas autodétecté |
return false; |
}, |
format: function(s) { |
// Transformation date jj/mm/aaaa en aaaa/mm/jj |
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1"); |
// Remplace la date par un nombre de millisecondes pour trier numériquement |
return $.tablesorter.formatFloat(new Date(s).getTime()); |
}, |
// set type, either numeric or text |
type: 'numeric' |
}); |
$("#observations table").tablesorter({ |
headers: { |
1: { |
sorter:'date_cel' |
} |
} |
}); |
} |
// Onglet Liste : Jquery => FancyBox |
if ($("#observations ol").get() != '') { |
$("a.cel-img").fancybox({ |
transitionIn : 'elastic', |
transitionOut : 'elastic', |
speedIn : 600, |
speedOut : 200, |
overlayShow : true |
}).bind('click', function(e) { |
if (e.stopPropagation) { |
e.stopPropagation(); |
} |
return false; |
}); |
} |
}); |
google.maps.event.addListener(infoBulle, 'closeclick', function() { |
map.panTo(pointClique.position); |
}); |
var pointClique = null; |
var carteCentre = new google.maps.LatLng(46.4, 3.10); |
var carteOptions = { |
zoom: 6, |
mapTypeId: google.maps.MapTypeId.ROADMAP, |
mapTypeControlOptions: { |
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU} |
}; |
var ctaLayer = null; |
function refreshMap() { |
var points = []; |
var bounds = new google.maps.LatLngBounds(); |
for (var i = 0; i < obs.nombre; ++i) { |
var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y); |
var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32)); |
var point = new google.maps.Marker({ |
position: maLatLng, |
map: map, |
icon: pointImage, |
stationId: obs.points[i].id |
}); |
bounds.extend(maLatLng); |
google.maps.event.addListener(point, 'click', function() { |
pointClique = this; |
infoBulle.open(map, this); |
var limites = map.getBounds(); |
var centre = limites.getCenter(); |
var nordEst = limites.getNorthEast(); |
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng()); |
map.panTo(centreSudLatLng); |
afficherMsgChargement(); |
chargerFormatObs(this.stationId, '*'); |
}); |
points.push(point); |
} |
if (pointsOrigine == null && boundsOrigine == null) { |
pointsOrigine = points; |
boundsOrigine = bounds; |
} |
executerMarkerClusterer(points, bounds); |
} |
function executerMarkerClusterer(points, bounds) { |
if (markerClusterer) { |
markerClusterer.clearMarkers(); |
} |
markerClusterer = new MarkerClusterer(map, points); |
map.fitBounds(bounds); |
} |
function afficherMsgChargement() { |
var chargement = document.getElementById('chargement').cloneNode(true); |
chargement.setAttribute('id', 'chargement-copie'); |
infoBulle.setContent(chargement); |
} |
function chargerFormatObs(stationId, format) { |
var url = '<?=$url_base?>carto?carte=observations'+ |
'&utilisateur=<?=$utilisateur?>'+ |
'&projet=<?=$projet?>'+ |
'&num_taxon='+nt+ |
'&dept=<?=$dept?>'+ |
'&format='+format+'&station='+stationId; |
$.get(url, function(observations){ |
infoBulle.setContent(observations); |
}); |
} |
function arreter(event) { |
if (event.stopPropagation) { |
event.stopPropagation(); |
} |
return false; |
} |
function afficher() { |
document.getElementById('panneau-lateral').style.width = '300px'; |
document.getElementById('pl-contenu').style.display = 'block'; |
document.getElementById('pl-ouverture').style.display = 'none'; |
document.getElementById('pl-fermeture').style.display = 'block'; |
document.getElementById('carte').style.left = '300px'; |
google.maps.event.trigger(map, 'resize'); |
}; |
function cacher() { |
document.getElementById('panneau-lateral').style.width = '24px'; |
document.getElementById('pl-contenu').style.display = 'none'; |
document.getElementById('pl-ouverture').style.display = 'block'; |
document.getElementById('pl-fermeture').style.display = 'none'; |
document.getElementById('carte').style.left = '24px'; |
google.maps.event.trigger(map, 'resize'); |
}; |
function ouvrirPopUp(url, nom) { |
window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no'); |
}; |
function filtrerParTaxon(ntAFiltrer) { |
infoBulle.close(); |
$('#taxon-'+nt).removeClass('taxon-actif'); |
if (nt == ntAFiltrer) { |
nt = '*'; |
executerMarkerClusterer(pointsOrigine, boundsOrigine); |
} else { |
var url = '<?=$url_cel_carto?>/carte-defaut-json/<?=$utilisateur?>/<?=$projet?>/<?=$dept?>/'+ntAFiltrer+'?formatRetour=jsonp&callback=?'; |
$.getJSON(url, function (observations) { |
obs = observations; |
nt = ntAFiltrer; |
$('#taxon-'+nt).addClass('taxon-actif'); |
refreshMap(); |
}); |
} |
}; |
function initialize() { |
map = new google.maps.Map(document.getElementById('carte'), carteOptions); |
// Ajout des limites communales sur la carte |
<? if (isset($url_limites_communales)) : ?> |
<? foreach ($url_limites_communales as $url) : ?> |
ctaLayer = new google.maps.KmlLayer('<?=$url?>', {preserveViewport: true}); |
ctaLayer.setMap(map); |
<? endforeach ?> |
<? endif ?> |
<? if ($num_taxon == '*') : ?> |
var ouvertureDiv = document.getElementById('pl-ouverture'); |
google.maps.event.addDomListener(ouvertureDiv, 'click', afficher); |
var fermetureDiv = document.getElementById('pl-fermeture'); |
google.maps.event.addDomListener(fermetureDiv, 'click', cacher); |
<? endif ?> |
refreshMap(); |
} |
// Déclenchement d'actions pour JQuery |
$(document).ready(function() { |
// Ajout du nombre de communes où des observations ont eu lieu |
$('#commune-nbre').append(obs.nombre); |
}); |
var plantesNbre = <?=count($taxons)?>; |
var urlObsStation = '<?=$url_base?>carto'+'?'+ |
'carte=observations'+'&'+ |
'utilisateur=<?=$utilisateur?>'+'&'+ |
'projet=<?=$projet?>'+'&'+ |
'num_taxon='+nt+'&'+ |
'dept=<?=$dept?>'; |
var urlObsCarte = '<?=$url_cel_carto?>/carte-defaut-json'+'?'+ |
'utilisateur=<?=$utilisateur?>'+'&'+ |
'projet=<?=$projet?>'+'&'+ |
'dept=<?=$dept?>'; |
//]]> |
</script> |
<script type="text/javascript" src="<?=$url_base?>modules/carto/squelettes/scripts/carto.js"></script> |
<!-- CSS --> |
<link href="<?=$url_base?>modules/carto/squelettes/css/carto.css" rel="stylesheet" type="text/css" media="screen" /> |
<link rel="stylesheet" href="http://www.tela-botanica.org/commun/jquery/fancybox/1.3.4/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> |
<!--[if lt IE 7]> |
<style type="text/css"> |
#carte { |
height:expression(document.body.clientHeight-35); /* 80+20+20=120 */ |
width:expression(document.body.clientWidth-24); /* 200+20+20+20=260 */ |
} |
#panneau-lateral { |
height:expression(document.body.clientHeight-35); /* 80+20+20=120 */ |
} |
</style> |
<![endif]--> |
<? if ($num_taxon != '*') : ?> |
<style type="text/css"> |
#carte { |
left:0; |
} |
</style> |
<? endif ?> |
<!-- Stats : Google Analytics --> |
<script type="text/javascript"> |
//<![CDATA[ |
var _gaq = _gaq || []; |
_gaq.push(['_setAccount', 'UA-20092557-1']); |
_gaq.push(['_trackPageview']); |
(function() { |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
})(); |
//]]> |
</script> |
</head> |
<body onload="initialize()"> |
<body> |
<div id="zone-titre"> |
<h1 id="carte-titre"> |
<? if ($num_taxon == '*') : ?> |
<span id="commune-nbre"> </span> communes contenant des observations du <a href="http://www.tela-botanica.org/appli:cel" title="Carnet en Ligne" onclick="window.open(this.href); arreter(event); return false;">CEL</a> de <a href="http://www.tela-botanica.org/" onclick="window.open(this.href); arreter(event); return false;">Tela Botanica</a> |
<? else : ?> |
<span id="commune-nbre"> </span> communes pour <?=$taxon_nom?> - <a href="http://www.tela-botanica.org/appli:cel" title="Carnet en Ligne" onclick="window.open(this.href); arreter(event); return false;">CEL</a> de <a href="http://www.tela-botanica.org/" onclick="window.open(this.href); arreter(event); return false;">Tela Botanica</a> |
<span id="obs-nbre"> </span> observations de |
<span class="plantes-nbre"> </span> plantes sur |
<span id="commune-nbre"> </span> communes |
<? if ($num_taxon != '*') : ?> |
pour <?=$taxon_nom?> |
<? endif ?> |
- <a href="http://www.tela-botanica.org/appli:cel" title="Carnet en Ligne" onclick="window.open(this.href); arreter(event); return false;">CEL</a> (<a href="http://www.tela-botanica.org/" onclick="window.open(this.href); arreter(event); return false;">Tela Botanica</a>) |
</h1> |
<div id="zone-info"> |
<a href="<?=$url_base?>carto?carte=avertissement" onClick="ouvrirPopUp('<?=$url_base?>carto?carte=avertissement', 'Avertissement'); arreter(event); return false;"> |
308,7 → 83,7 |
<div id="pl-fermeture" title="Fermer le panneau latéral"><span><< Fermer [x]</span></div> |
<div id="pl-contenu"> |
<div id="pl-entete"> |
<h2>Filtre sur <?=count($taxons)?> plantes</h2> |
<h2>Filtre sur <span class="plantes-nbre"> </span> plantes</h2> |
<p> |
Cliquez sur un nom de plante pour filtrer les observations sur la carte.<br /> |
Pour revenir à l'état initial, cliquez à nouveau sur le nom sélectionné. |
318,9 → 93,9 |
<ol id="taxons"> |
<? foreach ($taxons as $taxon) : ?> |
<li id="taxon-<?=$taxon['nt']?>"> |
<a href="#" onclick="filtrerParTaxon(<?=$taxon['nt']?>);" title="<?=$taxon['famille']?>"> |
<?=$taxon['nom']?> |
</a> |
<span class="taxon" title="<?=$taxon['famille']?>"> |
<?=$taxon['nom']?> <span class="nt" title="Numéro taxonomique"><?=$taxon['nt']?></span> |
</span> |
</li> |
<? endforeach; ?> |
</ol> |
335,5 → 110,20 |
<img src="<?=$url_base?>modules/carto/squelettes/images/chargement.gif" alt="Chargement en cours..." /> |
<p>Chargement des observations en cours...</p> |
</div> |
<!-- Stats : Google Analytics --> |
<script type="text/javascript"> |
//<![CDATA[ |
var _gaq = _gaq || []; |
_gaq.push(['_setAccount', 'UA-20092557-1']); |
_gaq.push(['_trackPageview']); |
(function() { |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
})(); |
//]]> |
</script> |
</body> |
</html> |
/trunk/widget/modules/carto/squelettes/scripts/carto.js |
---|
New file |
0,0 → 1,354 |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// PARAMÊTRES et CONSTANTES |
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png'; |
var pointsOrigine = null; |
var boundsOrigine = null; |
var markerClusterer = null; |
var map = null; |
var infoBulle = new google.maps.InfoWindow(); |
var pointClique = null; |
var carteCentre = new google.maps.LatLng(46.4, 3.10); |
var carteOptions = { |
zoom: 6, |
mapTypeId: google.maps.MapTypeId.ROADMAP, |
mapTypeControlOptions: { |
mapTypeIds: ['OSM', |
google.maps.MapTypeId.ROADMAP, |
google.maps.MapTypeId.HYBRID, |
google.maps.MapTypeId.SATELLITE, |
google.maps.MapTypeId.TERRAIN] |
} |
}; |
var ctaLayer = null; |
var osmMapType = new google.maps.ImageMapType({ |
getTileUrl: function(coord, zoom) { |
return "http://tile.openstreetmap.org/" + |
zoom + "/" + coord.x + "/" + coord.y + ".png"; |
}, |
tileSize: new google.maps.Size(256, 256), |
isPng: true, |
alt: "OpenStreetMap", |
name: "OSM", |
maxZoom: 19 |
}); |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// INITIALISATION DU CODE |
//Déclenchement d'actions quand JQuery et le document HTML sont OK |
$(document).ready(function() { |
initialiserWidget(); |
}); |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// FONCTIONS |
function initialiserWidget() { |
afficherStats(); |
initialiserAffichageCarte(); |
initialiserAffichagePanneauLateral(); |
initialiserCarte(); |
initialiserInfoBulle(); |
chargerLimitesCommunales(); |
rafraichirCarte(); |
} |
function afficherStats() { |
// Ajout du nombre de communes où des observations ont eu lieu |
$('#commune-nbre').append(obs.stats.communes.formaterNombre()); |
// Ajout du nombre d'observations |
$('#obs-nbre').append(obs.stats.observations.formaterNombre()); |
// Ajout du nombre de plantes |
$('.plantes-nbre').append(plantesNbre.formaterNombre()); |
} |
function initialiserAffichageCarte() { |
$('#carte').height($(window).height() - 35); |
$('#carte').width($(window).width() - 24); |
if (nt != '*') { |
$('#carte').css('left', 0); |
} |
} |
function initialiserAffichagePanneauLateral() { |
$('#panneau-lateral').height($(window).height() - 35); |
if (nt == '*') { |
$('#pl-ouverture').bind('click', afficher); |
$('#pl-fermeture').bind('click', cacher); |
$('.taxon').live('click', filtrerParTaxon); |
} |
} |
function initialiserCarte() { |
map = new google.maps.Map(document.getElementById('carte'), carteOptions); |
// Ajout de la couche OSM à la carte |
map.mapTypes.set('OSM', osmMapType); |
} |
function initialiserInfoBulle() { |
google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle); |
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique); |
} |
function chargerLimitesCommunales() { |
if (urlsLimitesCommunales != null) { |
for (urlId in urlsLimitesCommunales) { |
var url = urlsLimitesCommunales[urlId]; |
ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true}); |
ctaLayer.setMap(map); |
} |
} |
} |
function rafraichirCarte() { |
var points = []; |
var bounds = new google.maps.LatLngBounds(); |
for (var i = 0; i < obs.stats.communes; ++i) { |
var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y); |
var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32)); |
var point = new google.maps.Marker({ |
position: maLatLng, |
map: map, |
icon: pointImage, |
stationId: obs.points[i].id |
}); |
bounds.extend(maLatLng); |
google.maps.event.addListener(point, 'click', function() { |
pointClique = this; |
infoBulle.open(map, this); |
var limites = map.getBounds(); |
var centre = limites.getCenter(); |
var nordEst = limites.getNorthEast(); |
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng()); |
map.panTo(centreSudLatLng); |
afficherMsgChargement(); |
chargerFormatObs(this.stationId, '*'); |
}); |
points.push(point); |
} |
if (pointsOrigine == null && boundsOrigine == null) { |
pointsOrigine = points; |
boundsOrigine = bounds; |
} |
executerMarkerClusterer(points, bounds); |
} |
function modifierContenuInfoBulle() { |
// Onglet Tableau : Jquery => TableSorter |
if ($("#observations table").get() != '') { |
ajouterTableauTriable("#observations table"); |
} |
// Onglet Liste : Jquery => FancyBox |
if ($("#observations ol").get() != '') { |
ajouterGaleriePhoto("a.cel-img"); |
} |
} |
function ajouterTableauTriable(element) { |
// add parser through the tablesorter addParser method |
$.tablesorter.addParser({ |
// Définition d'un id unique pour ce parsseur |
id: 'date_cel', |
is: function(s) { |
// retourne false si le parsseur n'est pas autodétecté |
return false; |
}, |
format: function(s) { |
// Transformation date jj/mm/aaaa en aaaa/mm/jj |
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1"); |
// Remplace la date par un nombre de millisecondes pour trier numériquement |
return $.tablesorter.formatFloat(new Date(s).getTime()); |
}, |
// set type, either numeric or text |
type: 'numeric' |
}); |
$(element).tablesorter({ |
headers: { |
1: { |
sorter:'date_cel' |
} |
} |
}); |
} |
function ajouterGaleriePhoto(element) { |
$(element).fancybox({ |
transitionIn : 'elastic', |
transitionOut : 'elastic', |
speedIn : 600, |
speedOut : 200, |
overlayShow : true |
}).live('click', function(e) { |
if (e.stopPropagation) { |
e.stopPropagation(); |
} |
return false; |
}); |
} |
function deplacerCartePointClique() { |
map.panTo(pointClique.position); |
} |
function executerMarkerClusterer(points, bounds) { |
if (markerClusterer) { |
markerClusterer.clearMarkers(); |
} |
markerClusterer = new MarkerClusterer(map, points); |
map.fitBounds(bounds); |
} |
function afficherMsgChargement() { |
var chargement = document.getElementById('chargement').cloneNode(true); |
chargement.setAttribute('id', 'chargement-copie'); |
infoBulle.setContent(chargement); |
} |
function chargerFormatObs(stationId, format) { |
var url = urlObsStation+ |
'&format='+format+'&'+ |
'station='+stationId; |
$.get(url, function(observations){ |
infoBulle.setContent(observations); |
}); |
} |
function arreter(event) { |
if (event.stopPropagation) { |
event.stopPropagation(); |
} else if (window.event) { |
window.event.cancelBubble = true; |
} |
return false; |
} |
function afficher() { |
$('#panneau-lateral').width(300); |
$('#pl-contenu').css('display', 'block'); |
$('#pl-ouverture').css('display', 'none'); |
$('#pl-fermeture').css('display', 'block'); |
$('#carte').css('left', '300px'); |
google.maps.event.trigger(map, 'resize'); |
}; |
function cacher() { |
$('#panneau-lateral').width(24); |
$('#pl-contenu').css('display', 'none'); |
$('#pl-ouverture').css('display', 'block'); |
$('#pl-fermeture').css('display', 'none'); |
$('#carte').css('left', '24px'); |
google.maps.event.trigger(map, 'resize'); |
}; |
function ouvrirPopUp(url, nom) { |
window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no'); |
}; |
function filtrerParTaxon() { |
var ntAFiltrer = $('.nt', this).text(); |
infoBulle.close(); |
$('#taxon-'+nt).removeClass('taxon-actif'); |
if (nt == ntAFiltrer) { |
nt = '*'; |
executerMarkerClusterer(pointsOrigine, boundsOrigine); |
} else { |
var url = urlObsCarte+'&'+ |
'num_taxon='+ntAFiltrer+'&'+ |
'formatRetour=jsonp'+'&'+ |
'callback=?'; |
$.getJSON(url, function (observations) { |
obs = observations; |
nt = ntAFiltrer; |
$('#taxon-'+nt).addClass('taxon-actif'); |
rafraichirCarte(); |
}); |
} |
}; |
/** |
* +-------------------------------------+ |
* Number.prototype.formaterNombre |
* +-------------------------------------+ |
* Params (facultatifs): |
* - Int decimales: nombre de decimales (exemple: 2) |
* - String signe: le signe precedent les decimales (exemple: "," ou ".") |
* - String separateurMilliers: comme son nom l'indique |
* Returns: |
* - String chaine formatee |
* @author ::mastahbenus:: |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant |
* @souce http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx |
*/ |
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) { |
var _sNombre = String(this), i, _sRetour = "", _sDecimales = ""; |
function is_int(nbre) { |
nbre = nbre.replace(',', '.'); |
return !(parseFloat(nbre)-parseInt(nbre) > 0); |
} |
if (decimales == undefined) { |
if (is_int(_sNombre)) { |
decimales = 0; |
} else { |
decimales = 2; |
} |
} |
if (signe == undefined) { |
if (is_int(_sNombre)) { |
signe = ''; |
} else { |
signe = '.'; |
} |
} |
if (separateurMilliers == undefined) { |
separateurMilliers = ' '; |
} |
function separeMilliers (sNombre) { |
var sRetour = ""; |
while (sNombre.length % 3 != 0) { |
sNombre = "0"+sNombre; |
} |
for (i = 0; i < sNombre.length; i += 3) { |
if (i == sNombre.length-1) separateurMilliers = ''; |
sRetour += sNombre.substr(i, 3) + separateurMilliers; |
} |
while (sRetour.substr(0, 1) == "0") { |
sRetour = sRetour.substr(1); |
} |
return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers)); |
} |
if (_sNombre.indexOf('.') == -1) { |
for (i = 0; i < decimales; i++) { |
_sDecimales += "0"; |
} |
_sRetour = separeMilliers(_sNombre) + signe + _sDecimales; |
} else { |
var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1)); |
if (sDecimalesTmp.length > decimales) { |
var nDecimalesManquantes = sDecimalesTmp.length - decimales; |
var nDiv = 1; |
for (i = 0; i < nDecimalesManquantes; i++) { |
nDiv *= 10; |
} |
_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv); |
} |
_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales; |
} |
return _sRetour; |
} |
/trunk/widget/modules/carto/squelettes/css/carto.css |
---|
231,8 → 231,24 |
#taxons { |
color:#999; |
} |
#taxons .taxon-actif, #taxons .taxon-actif a { |
color:#56B80E;} |
#taxons .taxon-actif, #taxons .taxon-actif span { |
color:#56B80E; |
} |
#taxons li span { |
border-bottom:1px dotted #666; |
color:#CCC; |
} |
#taxons li span:focus { |
outline:thin dotted; |
} |
#taxons li span:hover { |
color:#56B80E; |
border-bottom:1px dotted #56B80E; |
cursor:pointer; |
} |
.nt { |
display:none; |
} |
/*+-----------------------------------------------------------------------------------------------------------------+*/ |
/* Pop-up observations */ |
.info-bulle-contenu { |