/trunk/services/modules/0.1/commun/Commun.php |
---|
12,27 → 12,25 |
public function consulter($ressources, $parametres) { |
$this->recupererRessourcesEtParametres($ressources, $parametres); |
$retour = null; |
try { |
if (!$this->verifierExistenceSourcesDonnees()) { |
$message = "Source de donnees indisponible"; |
throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
} else { |
$this->chargerNomSource(); |
$this->verifierParametres(); |
$this->chargerNomService(); |
$objetTraitement = new $this->nomService($this->parametresRecherche); |
$methode = $this->genererNomMethodeAExecuter(); |
$retour = $objetTraitement->$methode(); |
if ($this->ressources[0] == 'mailles') { |
$retour = $this->recupererMaillage(); |
} else { |
$this->chargerNomSource(); |
$this->chargerNomService(); |
$retour = $this->executerServicePourSource(); |
} |
} |
} catch (Exception $erreur) { |
$retour = $erreur; |
} |
return $retour; |
} |
41,15 → 39,6 |
$this->parametres = $parametres; |
} |
private function chargerNomService() { |
$this->nomService = ucfirst($this->parametres['source']) . 'Formateur'; |
Projets::chargerConfigurationSource($this->parametres['source']); |
} |
private function genererNomMethodeAExecuter() { |
return 'recuperer' . ucfirst($this->ressources[0]); |
} |
private function verifierExistenceSourcesDonnees() { |
$sourcesDisponibles = explode(',', Config::get('sources_dispo')); |
$estDisponible = false; |
64,14 → 53,6 |
return $estDisponible; |
} |
private function chargerNomSource() { |
if (isset($this->parametres['source'])) { |
$this->nomSource = $this->parametres['source']; |
} else { |
$this->nomSource = Config::get('source_defaut'); |
} |
} |
private function verifierParametres() { |
$this->verificateur = new VerificateurParametres($this->parametres); |
$this->verificateur->verifierParametres(); |
86,7 → 67,36 |
$this->parametresRecherche = $this->verificateur->renvoyerResultatVerification(); |
} |
private function chargerNomSource() { |
if (isset($this->parametres['source'])) { |
$this->nomSource = $this->parametres['source']; |
} else { |
$this->nomSource = Config::get('source_defaut'); |
} |
} |
private function chargerNomService() { |
$this->nomService = ucfirst($this->parametres['source']) . 'Formateur'; |
Projets::chargerConfigurationSource($this->parametres['source']); |
} |
private function recupererMaillage() { |
$maillage = new Maillage($this->parametresRecherche->bbox, $this->parametresRecherche->zoom); |
$maillage->genererMaillesVides(); |
$formateurJSON = new FormateurJson(); |
return $formateurJSON->formaterMaillesVides($maillage->formaterSortie(true)); |
} |
private function executerServicePourSource() { |
$objetTraitement = new $this->nomService($this->parametresRecherche); |
$methode = $this->genererNomMethodeAExecuter(); |
return $objetTraitement->$methode(); |
} |
private function genererNomMethodeAExecuter() { |
return 'recuperer' . ucfirst($this->ressources[0]); |
} |
} |
?> |
/trunk/services/modules/0.1/sources/SophyFormateur.php |
---|
30,96 → 30,25 |
* |
*/ |
class SophyFormateur { |
class SophyFormateur extends Formateur { |
private $criteresRecherche; |
private $bdd; |
public function __construct($criteresRecherche) { |
$this->criteresRecherche = $criteresRecherche; |
} |
public function recupererStations() { |
$stations = array(); |
$nombreStations = $this->obtenirNombreStationsDansBbox(); |
$seuilMaillage = Config::get('seuil_maillage'); |
$nombreParametresNonSpatiaux = $this->calculerNombreCriteresNonSpatiaux(); |
if ($nombreStations >= $seuilMaillage && $nombreParametresNonSpatiaux == 0) { |
// pas besoin de rechercher les stations correspondant a ces criteres |
// recuperer les mailles se trouvant dans l'espace de recherche demande |
$stations = $this->recupererMaillesDansBbox(); |
} else { |
$requeteSql = $this->construireRequeteStations(); |
$stations = $this->getBdd()->recupererTous($requeteSql); |
$zoom = $this->criteresRecherche->zoom; |
$zoomMaxMaillage = Config::get('zoom_maximal_maillage'); |
if ($zoom <= $zoomMaxMaillage && count($stations) >= $seuilMaillage) { |
// generer un maillage a partir des stations recuperees dans la base de donnees |
$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, 'sophy'); |
$maillage->genererMaillesVides(); |
$maillage->ajouterPoints($stations); |
$stations = $maillage->formaterSortie(); |
} |
} |
// mettre en forme les informations au format JSON |
$formateurJSON = new FormateurJson('sophy'); |
$donneesFormatees = $formateurJSON->formaterStations($stations); |
return $donneesFormatees; |
} |
public function recupererObservations() { |
$requeteSql = $this->construireRequeteObservations(); |
$observations = $this->getBdd()->recupererTous($requeteSql); |
$this->recupererNumeroNomenclaturauxTaxons($observations); |
$nomStation = $this->obtenirNomsStationsSurPoint(); |
$formateurJSON = new FormateurJson('sophy'); |
$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomStation); |
return $donneesFormatees; |
} |
private function calculerNombreCriteresNonSpatiaux() { |
$nombreParametresNonSpatiaux = 0; |
$criteresSpatiaux = array('zoom', 'bbox', 'longitude', 'latitude'); |
foreach ($this->criteresRecherche as $nomCritere => $valeur) { |
if (!in_array($nomCritere, $criteresSpatiaux)) { |
$nombreParametresNonSpatiaux ++; |
} |
} |
return $nombreParametresNonSpatiaux; |
} |
// ------------------------------------------------------------------------ // |
// Fonctions de construction des criteres de recherches pour la requete SQL // |
// ------------------------------------------------------------------------ // |
private function getBdd() { |
if (!isset($this->bdd)) { |
$this->bdd = new Bdd(); |
} |
$this->bdd->requeter("USE ".Config::get('bdd_nom')); |
return $this->bdd; |
} |
private function construireRequeteStations() { |
protected function construireRequeteStations() { |
$requete = |
"SELECT DISTINCT lieu_station_nom AS nom, lieu_station_latitude AS latitude, ". |
"lieu_station_longitude AS longitude, 'STATION' AS type_site ". |
"SELECT COUNT(guid) AS observations, lieu_station_nom AS nom, lieu_station_latitude AS latitude, ". |
"lieu_station_longitude AS longitude, 'STATION' AS type_site, lieu_commune_code_insee AS code_insee ". |
"FROM sophy_tapir WHERE 1 ". |
$this->construireWhereDepartement().' '. |
$this->construireWhereAuteur().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesBbox().' '. |
"GROUP BY lieu_station_latitude, lieu_station_longitude"; |
"GROUP BY lieu_station_longitude, lieu_station_latitude"; |
return $requete; |
} |
private function construireRequeteObservations() { |
protected function construireRequeteObservations() { |
$requete = |
"SELECT observation_id AS id_obs, nom_scientifique_complet AS nomSci, ". |
"observation_date AS date, lieu_station_nom AS lieu, observateur_nom_complet AS observateur ". |
126,6 → 55,7 |
"FROM sophy_tapir WHERE 1 ". |
$this->construireWhereAuteur().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesPoint().' '. |
"ORDER BY nom_scientifique_complet, date, observateur"; |
132,34 → 62,66 |
return $requete; |
} |
private function construireWhereTaxon() { |
protected function construireWhereTaxon() { |
$sql = ''; |
if (isset($this->criteresRecherche->taxon)) { |
$taxon = $this->criteresRecherche->taxon; |
$criteres = "nom_scientifique_complet LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $this->criteresRecherche->taxon); |
$sousTaxons = $referentiel->recupererSousTaxons(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres .= " OR nom_scientifique_complet LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
$taxons = $this->criteresRecherche->taxon; |
$criteres = array(); |
foreach ($taxons as $taxon) { |
$nomRang = $this->getNomRang($taxon); |
$criteres[] = "nom_scientifique_complet LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
if ($nomRang == 'espece') { |
$criteres = array_merge($criteres, $this->concatenerTaxonsSousEspeces($taxon)); |
} elseif ($nomRang == 'genre') { |
$criteres = array_merge($criteres, $this->concatenerTaxonsFamilles($taxon)); |
} |
} |
$sql = "AND ($criteres)"; |
$sql = "AND (".implode(' OR ',array_unique($criteres)).")"; |
} |
return $sql; |
} |
protected function concatenerTaxonsSousEspeces($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsSousEspeces(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_scientifique_complet LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
protected function concatenerTaxonsFamilles($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsFamilles(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_scientifique_complet LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
// TODO : completer le corps des methodes construire where pour referentiel et departement |
private function construireWhereReferentiel() { |
protected function construireWhereReferentiel() { |
$sql = ''; |
return $sql; |
} |
private function construireWhereDepartement() { |
protected function construireWhereDepartement() { |
$sql = ''; |
if (isset($this->criteresRecherche->departement)) { |
$valeurs_a_proteger = $this->criteresRecherche->departement; |
foreach ($valeurs_a_proteger as $valeur) { |
$aProteger = $this->getBdd()->proteger($valeur . '%'); |
$valeurs_protegees[] = "lieu_commune_code_insee LIKE {$aProteger}"; |
} |
$valeurs = implode(' OR ', $valeurs_protegees); |
$sql = "AND ($valeurs)"; |
} |
return $sql; |
} |
private function construireWhereAuteur() { |
protected function construireWhereAuteur() { |
$sql = ''; |
if (isset($this->criteresRecherche->auteur)) { |
$auteur = $this->getBdd()->proteger($this->criteresRecherche->auteur); |
167,8 → 129,30 |
} |
return $sql; |
} |
protected function construireWhereDate() { |
$sql = ''; |
$dateDebut = isset($this->criteresRecherche->dateDebut) ? $this->criteresRecherche->dateDebut : null; |
$dateFin = isset($this->criteresRecherche->dateFin) ? $this->criteresRecherche->dateFin : null; |
if (!is_null($dateDebut) || !is_null($dateFin)) { |
$dateDebut = !is_null($dateDebut) ? substr($dateDebut, 0, 4) : null; |
$dateFin = !is_null($dateFin) ? substr($dateFin, 0, 4) : date('Y'); |
$condition = ''; |
if ($dateDebut == $dateFin) { |
$condition = "observation_date=".$dateDebut; |
} elseif (is_null($dateFin)) { |
$condition = "observation_date>=".$dateDebut; |
} elseif (is_null($dateDebut)) { |
$condition = "observation_date<=".$dateFin; |
} else { |
$condition = "observation_date BETWEEN ".$dateDebut." AND ".$dateFin; |
} |
$sql = "AND ($condition)"; |
} |
return $sql; |
} |
private function construireWhereCoordonneesBbox() { |
protected function construireWhereCoordonneesBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$sql = "AND lieu_station_longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']." ". |
"AND lieu_station_latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']; |
175,13 → 159,13 |
return $sql; |
} |
private function construireWhereCoordonneesPoint() { |
protected function construireWhereCoordonneesPoint() { |
$sql = "AND lieu_station_latitude=".$this->criteresRecherche->latitude." ". |
"AND lieu_station_longitude=".$this->criteresRecherche->longitude; |
return $sql; |
} |
private function obtenirNomsStationsSurPoint() { |
protected function obtenirNomsStationsSurPoint() { |
$requete = "SELECT DISTINCTROW lieu_station_nom FROM sophy_tapir WHERE 1 ". |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesPoint(); |
193,7 → 177,7 |
return implode(', ', $nomsStations); |
} |
private function obtenirNombreStationsDansBbox() { |
protected function obtenirNombreStationsDansBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$zoom = $this->criteresRecherche->zoom; |
$requete = |
204,60 → 188,23 |
return $resultat['total_points']; |
} |
private function recupererMaillesDansBbox() { |
protected function recupererMaillesDansBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$zoom = $this->criteresRecherche->zoom; |
$requete = |
"SELECT zoom, position_latitude, position_longitude, limite_sud AS sud, limite_ouest AS ouest, ". |
"limite_nord AS nord, limite_est AS est, nombre_sites AS points, 'MAILLE' AS type_site ". |
"FROM mailles_sophy WHERE zoom=".$zoom." AND limite_sud<=".$bbox['nord']." ". |
"SELECT limite_sud AS latitudeSud, limite_ouest AS longitudeOuest, limite_est AS longitudeEst, ". |
"limite_nord AS latitudeNord, nombre_sites, nombre_observations FROM mailles_sophy ". |
"WHERE zoom=".$zoom." AND limite_sud<=".$bbox['nord']." ". |
"AND limite_nord>=".$bbox['sud']." AND limite_ouest<=". $bbox['est']." ". |
"AND limite_est>=".$bbox['ouest']; |
return $this->getBdd()->recupererTous($requete); |
$mailles = $this->getBdd()->recupererTous($requete, Bdd::MODE_OBJET); |
// placer les totaux des nombres de stations dans des mailles vides |
$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, $this->nomSource); |
$maillage->genererMaillesVides(); |
$maillage->ajouterMailles($mailles); |
return $maillage->formaterSortie(); |
} |
private function recupererNumeroNomenclaturauxTaxons(& $observations) { |
for ($index = 0; $index < count($observations); $index ++) { |
$taxon = isset($this->criteresRecherche->taxon) ? $this->criteresRecherche->taxon : null; |
if (is_null($taxon) && strlen(trim($observations[$index]['nomSci'])) > 0) { |
if (isset($this->criteresRecherche->taxon)) { |
$taxon = $this->rechercherTaxonDansReferentiel($observations[$index]['nomSci'], |
$this->criteresRecherche->referentiel); |
} else { |
$taxon = $this->obtenirNumeroTaxon($observations[$index]['nomSci']); |
} |
} |
if (!is_null($taxon)) { |
$observations[$index]['nn'] = $taxon['nn']; |
$observations[$index]['num_referentiel'] = $taxon['referentiel']; |
} else { |
$observations[$index]['nn'] = ''; |
} |
} |
} |
private function rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel) { |
$referentiel = new Referentiel($nomReferentiel); |
$taxon = $referentiel->obtenirNumeroNomenclatural($nomScientifique); |
return $taxon; |
} |
private function obtenirNumeroTaxon($nomScientifique) { |
$taxonTrouve = null; |
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles(); |
foreach ($listeReferentiels as $nomReferentiel) { |
$taxon = $this->rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel); |
if (!is_null($taxon)) { |
$taxonTrouve = $taxon; |
break; |
} |
} |
return $taxonTrouve; |
} |
} |
?> |
/trunk/services/modules/0.1/sources/FloradataFormateur.php |
---|
43,10 → 43,8 |
} |
public function recupererStations() { |
// recuperer les informations au niveau de la base de donnees |
$requeteSql = $this->construireRequeteStations(); |
$stations = $this->getBdd()->recupererTous($requeteSql); |
$zoomMaxMaillage = Config::get('zoom_maximal_maillage'); |
$seuilMaillage = Config::get('seuil_maillage'); |
$zoom = $this->criteresRecherche->zoom; |
53,14 → 51,11 |
$bbox = $this->criteresRecherche->bbox; |
// TODO: gérer une notion d'échelle plutot que de zoom (pour les clients SIG) |
if (count($stations) > $seuilMaillage && intval($zoom)<= $zoomMaxMaillage) { |
// partitionnement des donnees en mailles |
$maillage = new Maillage($bbox, $zoom); |
$maillage->genererMaillesVides(); |
$maillage->ajouterPoints($stations); |
$stations = $maillage->formaterSortie(); |
} |
// mettre en forme les informations au format JSON |
$formateurJSON = new FormateurJson('floradata'); |
$donneesFormatees = $formateurJSON->formaterStations($stations); |
return $donneesFormatees; |
67,12 → 62,9 |
} |
public function recupererObservations() { |
// recuperer les informations sur les stations repondant a ces parametres |
$requeteSql = $this->construireRequeteObservations(); |
$observations = $this->getBdd()->recupererTous($requeteSql); |
$nomSite = $this->obtenirNomStation(); |
// mettre en forme les informations au format JSON |
$formateurJSON = new FormateurJson('floradata'); |
$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomSite); |
return $donneesFormatees; |
93,21 → 85,27 |
} |
private function construireRequeteStations() { |
$bbox = $this->criteresRecherche->bbox; |
$selectTypeSite = |
"IF(". |
"(longitude IS NULL OR latitude IS NULL) ". |
"OR (longitude=0 AND latitude=0) ". |
"OR (longitude=999.99999 AND latitude=999.99999)". |
"OR (mots_cles_texte LIKE '%sensible%') ". |
"OR NOT (". |
"longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']." ". |
"AND latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']. |
")". |
", 'COMMUNE', 'STATION'". |
")"; |
$requete = |
'SELECT ce_zone_geo, zone_geo, station, longitude, latitude, nom AS "nom_commune",'. |
'wgs84_longitude AS "lng_commune", wgs84_latitude AS "lat_commune", '. |
$selectTypeSite.' AS "type_site" '. |
'FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo '. |
'WHERE transmission=1 '. |
"SELECT COUNT(id_observation) AS observations, ce_zone_geo, zone_geo, station, ". |
"longitude, latitude, nom AS nom_commune,wgs84_longitude AS lng_commune, ". |
"wgs84_latitude AS lat_commune, ".$selectTypeSite." AS type_site ". |
"FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ". |
"WHERE transmission=1 ". |
$this->construireWhereDepartement().' '. |
$this->construireWhereAuteur().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesBbox().' '. |
118,11 → 116,12 |
private function construireRequeteObservations() { |
$requete = |
"SELECT id_observation AS id_obs, nom_ret_nn AS nn, nom_ret AS nomSci, ". |
"Date(date_transmission) AS date, milieu AS lieu, nom_referentiel, ". |
"Date(date_observation) AS date, milieu AS lieu, nom_referentiel, ". |
"Concat(prenom_utilisateur, ' ', nom_utilisateur) AS observateur, ce_utilisateur AS observateurId ". |
"FROM cel_obs WHERE transmission=1 ". |
$this->construireWhereAuteur().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesPoint().' '. |
"ORDER BY nom_ret, date, observateur"; |
129,22 → 128,55 |
return $requete; |
} |
private function construireWhereTaxon() { |
protected function construireWhereTaxon() { |
$sql = ''; |
if (isset($this->criteresRecherche->taxon)) { |
$taxon = $this->criteresRecherche->taxon; |
$criteres = "nom_ret LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $this->criteresRecherche->taxon); |
$sousTaxons = $referentiel->recupererSousTaxons(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres .= " OR nom_ret LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
$taxons = $this->criteresRecherche->taxon; |
$criteres = array(); |
foreach ($taxons as $taxon) { |
$nomRang = $this->getNomRang($taxon); |
if ($nomRang == 'genre') { |
$criteres[] = "famille=".$this->getBdd()->proteger($taxon['nom']); |
} else { |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
if ($nomRang == 'espece') { |
$criteres = array_merge($criteres, $this->concatenerTaxonsSousEspeces($taxon)); |
} |
} |
} |
$sql = "AND ($criteres)"; |
$sql = "AND (".implode(' OR ',array_unique($criteres)).")"; |
} |
return $sql; |
} |
protected function getNomRang($taxon) { |
$nomsRangs = array('famille', 'genre', 'espece', 'sous_espece'); |
for ($index = 0; $index < count($nomsRangs) |
&& Config::get("rang.".$nomsRangs[$index]) != $taxon['rang']; $index ++); |
$position = $index == count($nomsRangs) ? count($nomsRangs)-1 : $index; |
return $nomsRangs[$position]; |
} |
protected function concatenerTaxonsSousEspeces($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsSousEspeces(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
protected function concatenerTaxonsFamilles($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsFamilles(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
private function construireWhereReferentiel() { |
$sql = ''; |
if (isset($this->criteresRecherche->referentiel) && !isset($this->criteresRecherche->taxon)) { |
176,15 → 208,49 |
return $sql; |
} |
private function construireWhereDate() { |
$sql = ''; |
if (isset($this->criteresRecherche->nbJours)) { |
$nbJours = $this->criteresRecherche->nbJours; |
$sql = "AND (Datediff(Curdate(), date_creation)<={$nbJours})"; |
} else { |
$sql = $this->construireWhereDateDebutEtFin(); |
} |
return $sql; |
} |
private function construireWhereDateDebutEtFin() { |
$sql = ''; |
$dateDebut = isset($this->criteresRecherche->dateDebut) ? $this->criteresRecherche->dateDebut : null; |
$dateFin = isset($this->criteresRecherche->dateFin) ? $this->criteresRecherche->dateFin : null; |
if (!is_null($dateDebut) || !is_null($dateFin)) { |
$dateFin = !is_null($dateFin) ? $dateFin : date('Y-m-d'); |
$condition = ''; |
if ($dateDebut == $dateFin) { |
$condition = "Date(date_observation)=".$this->getBdd()->proteger($dateDebut); |
} elseif (is_null($dateFin)) { |
$condition = "Date(date_observation)>=".$this->getBdd()->proteger($dateDebut); |
} elseif (is_null($dateDebut)) { |
$condition = "Date(date_observation)<=".$this->getBdd()->proteger($dateFin); |
} else { |
$condition = "Date(date_observation) BETWEEN ".$this->getBdd()->proteger($dateDebut)." ". |
"AND ".$this->getBdd()->proteger($dateFin); |
} |
$sql = "AND ($condition)"; |
} |
return $sql; |
} |
private function construireWhereCoordonneesBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$sql = |
"AND (". |
"(". |
"longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']." ". |
"AND latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']." ". |
"AND (wgs84_longitude IS NULL OR wgs84_latitude IS NULL)". |
"latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']." ". |
"AND longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']. |
") OR (". |
"((longitude IS NULL OR latitude IS NULL) OR (longitude=0 AND latitude=0) ". |
"OR (longitude>180 AND latitude>90)) AND ". |
"wgs84_longitude BETWEEN ".$bbox['ouest']." AND ". $bbox['est']." ". |
"AND wgs84_latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']. |
")". |
193,12 → 259,18 |
} |
private function construireWhereCoordonneesPoint() { |
$commune = $this->obtenirCoordonneesCommune(); |
$condition = "(longitude=".$this->criteresRecherche->longitude." ". |
"AND latitude=".$this->criteresRecherche->latitude.")"; |
if (!is_null($commune)) { |
$condition .= " OR (longitude IS NULL AND latitude IS NULL AND ce_zone_geo=". |
$this->getBdd()->proteger($commune['id_zone_geo']).")"; |
$longitude = $this->criteresRecherche->longitude; |
$latitude = $this->criteresRecherche->latitude; |
$condition = "(longitude=".$longitude." AND latitude=".$latitude." ". |
"AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%'))"; |
if ($this->criteresRecherche->typeSite == 'commune') { |
$commune = $this->obtenirCoordonneesCommune(); |
$condition .= |
" OR (". |
"((longitude IS NULL OR latitude IS NULL) OR (longitude=0 AND latitude=0) ". |
"OR (longitude>180 AND latitude>90)) ". |
"AND ce_zone_geo=".$this->getBdd()->proteger($commune['id_zone_geo']). |
")"; |
} |
return "AND ($condition)"; |
} |
/trunk/services/modules/0.1/sources/BaznatFormateur.php |
---|
New file |
0,0 → 1,210 |
<?php |
/** |
* |
* Classe en charge de recuperer les donnees d'observation ou liees a leur localisation |
* Le jeu de donnees a interroger est partage en commun avec l'application EFlore |
* |
* On passera en parametre lors de la creation d'une instance un objet contenant la liste des criteres |
* qui vont restreindre le nombre de resultats a renvoyer |
* |
* Les deux operations suivantes peuvent etre utilisees dans les services : |
* - recupererStations : va rechercher dans la base de donnees tous les points d'observations |
* correspondant aux criteres de recherche demandes. La precision des lieux d'observation est |
* soit un point precis, soit ramenee au niveau de la commune dans laquelle l'observation a ete faite |
* En fonction du niveau de zoom et du nombre de resultats trouves, la presentation se fera |
* soit par les points localisant les stations pour des niveaux de zoom eleves ou pour un nombre |
* de stations inferieur a un seuil, ou par des mailles de 64*64 pixels dans le cas contraire |
* |
* - recupererObservations : va rechercher dans la base de donnees les donnees sur des observations |
* a partir des coordonnees longitude et latitude d'une station (+ des parametres additionnels) |
* |
* Les donnees seront renvoyees au format JSON |
* |
* @package framework-0.3 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org) |
* |
*/ |
class BaznatFormateur extends Formateur { |
protected function construireRequeteStations() { |
$requete = |
"SELECT COUNT(guid) AS observations, commune AS nom, code_insee_commune AS code_insee, ". |
"latitude, longitude, 'STATION' AS type_site FROM baznat_tapir WHERE 1 ". |
$this->construireWhereDepartement().' '. |
$this->construireWhereAuteur().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesBbox().' '. |
"GROUP BY longitude, latitude"; |
return $requete; |
} |
protected function construireRequeteObservations() { |
$requete = |
"SELECT code_observation AS id_obs, nom_scientifique AS nomSci, date_observation AS date, ". |
"commune AS lieu, observateur FROM baznat_tapir WHERE 1 ". |
$this->construireWhereAuteur().' '. |
$this->construireWhereReferentiel().' '. |
$this->construireWhereDate().' '. |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesPoint().' '. |
"ORDER BY nom_scientifique, date, observateur"; |
return $requete; |
} |
protected function construireWhereTaxon() { |
$sql = ''; |
if (isset($this->criteresRecherche->taxon)) { |
$taxons = $this->criteresRecherche->taxon; |
$criteres = array(); |
foreach ($taxons as $taxon) { |
$nomRang = $this->getNomRang($taxon); |
$criteres[] = "nom_scientifique LIKE ".$this->getBdd()->proteger($taxon['nom']."%"); |
if ($nomRang == 'espece') { |
$criteres = array_merge($criteres, $this->concatenerTaxonsSousEspeces($taxon)); |
} elseif ($nomRang == 'genre') { |
$criteres = array_merge($criteres, $this->concatenerTaxonsFamilles($taxon)); |
} |
} |
$sql = "AND (".implode(' OR ',array_unique($criteres)).")"; |
} |
return $sql; |
} |
protected function concatenerTaxonsSousEspeces($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsSousEspeces(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_scientifique LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
protected function concatenerTaxonsFamilles($taxon) { |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon); |
$sousTaxons = $referentiel->recupererTaxonsFamilles(); |
$criteres = array(); |
foreach ($sousTaxons as $sousTaxon) { |
$criteres[] = "nom_scientifique LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%"); |
} |
return $criteres; |
} |
// TODO : completer le corps des methodes construire where pour referentiel et departement |
protected function construireWhereReferentiel() { |
$sql = ''; |
return $sql; |
} |
protected function construireWhereDepartement() { |
$sql = ''; |
if (isset($this->criteresRecherche->departement)) { |
$valeurs_a_proteger = $this->criteresRecherche->departement; |
foreach ($valeurs_a_proteger as $valeur) { |
$aProteger = $this->getBdd()->proteger($valeur . '%'); |
$valeurs_protegees[] = "code_insee_commune LIKE {$aProteger}"; |
} |
$valeurs = implode(' OR ', $valeurs_protegees); |
$sql = "AND ($valeurs)"; |
} |
return $sql; |
} |
protected function construireWhereAuteur() { |
$sql = ''; |
if (isset($this->criteresRecherche->auteur)) { |
$aProteger = $this->getBdd()->proteger('%'.$this->criteresRecherche->auteur.'%'); |
$sql = "AND observateur LIKE {$aProteger}"; |
} |
return $sql; |
} |
protected function construireWhereDate() { |
$sql = ''; |
$dateDebut = isset($this->criteresRecherche->dateDebut) ? $this->criteresRecherche->dateDebut : null; |
$dateFin = isset($this->criteresRecherche->dateFin) ? $this->criteresRecherche->dateFin : null; |
if (!is_null($dateDebut) || !is_null($dateFin)) { |
$dateDebut = !is_null($dateDebut) ? substr($dateDebut, 0, 4) : null; |
$dateFin = !is_null($dateFin) ? substr($dateFin, 0, 4) : date('Y'); |
$condition = ''; |
if ($dateDebut == $dateFin) { |
$condition = "date_observation=".$dateDebut; |
} elseif (is_null($dateFin)) { |
$condition = "date_observation>=".$dateDebut; |
} elseif (is_null($dateDebut)) { |
$condition = "date_observation<=".$dateFin; |
} else { |
$condition = "date_observation BETWEEN ".$dateDebut." AND ".$dateFin; |
} |
$sql = "AND ($condition)"; |
} |
return $sql; |
} |
protected function construireWhereCoordonneesBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$sql = |
"AND longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']." ". |
"AND latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']; |
return $sql; |
} |
protected function construireWhereCoordonneesPoint() { |
$sql = |
"AND latitude=".$this->criteresRecherche->latitude." ". |
"AND longitude=".$this->criteresRecherche->longitude; |
return $sql; |
} |
protected function obtenirNomsStationsSurPoint() { |
$requete = |
"SELECT DISTINCTROW commune FROM baznat_tapir WHERE 1 ". |
$this->construireWhereTaxon().' '. |
$this->construireWhereCoordonneesPoint(); |
$stations = $this->getBdd()->recupererTous($requete); |
$nomsStations = array(); |
foreach ($stations as $station) { |
$nomsStations[] = $station['commune']; |
} |
return implode(', ', $nomsStations); |
} |
protected function obtenirNombreStationsDansBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$zoom = $this->criteresRecherche->zoom; |
$requete = |
"SELECT zoom, Sum(nombre_sites) AS total_points FROM mailles_baznat ". |
"WHERE zoom=".$zoom." AND limite_sud<=".$bbox['nord']." AND limite_nord>=".$bbox['sud']." ". |
"AND limite_ouest<=".$bbox['est']." AND limite_est>=".$bbox['ouest']." GROUP BY zoom"; |
$resultat = $this->getBdd()->recuperer($requete); |
return $resultat['total_points']; |
} |
protected function recupererMaillesDansBbox() { |
$bbox = $this->criteresRecherche->bbox; |
$zoom = $this->criteresRecherche->zoom; |
$requete = |
"SELECT limite_sud AS latitudeSud, limite_ouest AS longitudeOuest, limite_est AS longitudeEst, ". |
"limite_nord AS latitudeNord, nombre_sites, nombre_observations FROM mailles_baznat ". |
"WHERE zoom=".$zoom." AND limite_sud<=".$bbox['nord']." ". |
"AND limite_nord>=".$bbox['sud']." AND limite_ouest<=". $bbox['est']." ". |
"AND limite_est>=".$bbox['ouest']; |
$mailles = $this->getBdd()->recupererTous($requete, Bdd::MODE_OBJET); |
$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, $this->nomSource); |
$maillage->genererMaillesVides(); |
$maillage->ajouterMailles($mailles); |
return $maillage->formaterSortie(); |
} |
} |
?> |
/trunk/services/modules/0.1/sources/Formateur.php |
---|
New file |
0,0 → 1,149 |
<?php |
abstract class Formateur { |
protected $criteresRecherche; |
protected $bdd; |
protected $nomSource = ''; |
public function __construct($criteresRecherche) { |
$this->criteresRecherche = $criteresRecherche; |
$this->nomSource = Config::get('nom_source'); |
} |
public function recupererStations() { |
$stations = null; |
if ($this->estTraitementRecuperationAutorise()) { |
$stations = $this->traiterRecupererStations(); |
} |
return $stations; |
} |
public function recupererObservations() { |
$stations = null; |
if ($this->estTraitementRecuperationAutorise()) { |
$stations = $this->traiterRecupererObservations(); |
} |
return $stations; |
} |
protected function estTraitementRecuperationAutorise() { |
return (!( |
isset($this->criteresRecherche->nbJours) || |
(isset($this->criteresRecherche->referentiel) && |
$this->criteresRecherche->referentiel != Config::get('referentiel_source')) |
)); |
} |
protected function traiterRecupererStations() { |
$stations = array(); |
$nombreStations = $this->obtenirNombreStationsDansBbox(); |
$seuilMaillage = Config::get('seuil_maillage'); |
$nombreParametresNonSpatiaux = $this->calculerNombreCriteresNonSpatiaux(); |
if ($nombreStations >= $seuilMaillage && $nombreParametresNonSpatiaux == 0) { |
// pas besoin de rechercher les stations correspondant a ces criteres |
// recuperer les mailles se trouvant dans l'espace de recherche demande |
$stations = $this->recupererMaillesDansBbox(); |
} else { |
$requeteSql = $this->construireRequeteStations(); |
$stations = $this->getBdd()->recupererTous($requeteSql); |
$zoom = $this->criteresRecherche->zoom; |
$zoomMaxMaillage = Config::get('zoom_maximal_maillage'); |
if ($zoom <= $zoomMaxMaillage && count($stations) >= $seuilMaillage) { |
$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, $this->nomSource); |
$maillage->genererMaillesVides(); |
$maillage->ajouterPoints($stations); |
$stations = $maillage->formaterSortie(); |
} |
} |
$formateurJSON = new FormateurJson($this->nomSource); |
$donneesFormatees = $formateurJSON->formaterStations($stations); |
return $donneesFormatees; |
} |
protected function traiterRecupererObservations() { |
$requeteSql = $this->construireRequeteObservations(); |
$observations = $this->getBdd()->recupererTous($requeteSql); |
$this->recupererNumeroNomenclaturauxTaxons($observations); |
$nomStation = $this->obtenirNomsStationsSurPoint(); |
$formateurJSON = new FormateurJson($this->nomSource); |
$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomStation); |
return $donneesFormatees; |
} |
protected function calculerNombreCriteresNonSpatiaux() { |
$nombreParametresNonSpatiaux = 0; |
$criteresAIgnorer = array('zoom', 'bbox', 'longitude', 'latitude', 'referentiel'); |
foreach ($this->criteresRecherche as $nomCritere => $valeur) { |
if (!in_array($nomCritere, $criteresAIgnorer)) { |
echo $nomCritere.chr(13); |
$nombreParametresNonSpatiaux ++; |
} |
} |
return $nombreParametresNonSpatiaux; |
} |
protected function getBdd() { |
if (!isset($this->bdd)) { |
$this->bdd = new Bdd(); |
} |
$this->bdd->requeter("USE ".Config::get('bdd_nom')); |
return $this->bdd; |
} |
protected function getNomRang($taxon) { |
$nomsRangs = array('famille', 'genre', 'espece', 'sous_espece'); |
for ($index = 0; $index < count($nomsRangs) |
&& Config::get("rang.".$nomsRangs[$index]) != $taxon['rang']; $index ++); |
$position = $index == count($nomsRangs) ? count($nomsRangs)-1 : $index; |
return $nomsRangs[$position]; |
} |
protected function recupererNumeroNomenclaturauxTaxons(& $observations) { |
for ($index = 0; $index < count($observations); $index ++) { |
$taxons = isset($this->criteresRecherche->taxon) ? $this->criteresRecherche->taxon : null; |
if (!is_null($taxons)) { |
foreach ($taxons as $taxon) { |
if ($observations[$index]['nomSci'] == 0) { |
continue; |
} |
if (isset($this->criteresRecherche->taxon)) { |
$taxon = $this->rechercherTaxonDansReferentiel($observations[$index]['nomSci'], |
$this->criteresRecherche->referentiel); |
} else { |
$taxon = $this->obtenirNumeroTaxon($observations[$index]['nomSci']); |
} |
if (!is_null($taxon)) { |
$observations[$index]['nn'] = $taxon['nn']; |
$observations[$index]['num_referentiel'] = $taxon['referentiel']; |
} else { |
$observations[$index]['nn'] = ''; |
} |
} |
} |
} |
} |
protected function rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel) { |
$referentiel = new Referentiel($nomReferentiel); |
$taxon = $referentiel->obtenirNumeroNomenclatural($nomScientifique); |
return $taxon; |
} |
protected function obtenirNumeroTaxon($nomScientifique) { |
$taxonTrouve = null; |
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles(); |
foreach ($listeReferentiels as $nomReferentiel) { |
$taxon = $this->rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel); |
if (!is_null($taxon)) { |
$taxonTrouve = $taxon; |
break; |
} |
} |
return $taxonTrouve; |
} |
} |
?> |
/trunk/services/configurations/config.defaut.ini |
---|
77,11 → 77,17 |
carte.zoom_minimal = 3 |
carte.zoom_maximal = 18 |
zoom_maximal_maillage = 13 |
seuil_maillage = 500 |
seuil_maillage = 250 |
; valeurs des rangs au niveau de la classification des taxons |
rang.genre = 180 |
rang.famille = 220 |
rang.espece = 290 |
rang.sous_espece = 320 |
; +------------------------------------------------------------------------------------------------------+ |
; Autres informations |
sources_dispo = "floradata,sophy" |
sources_dispo = "floradata,sophy,baznat" |
source_defaut = "floradata" |
services_dispo = "stations,observations" |
referentiels_dispo = "bdtfx_v1_01,bdtxa_v1_00" |
/trunk/services/configurations/config_baznat.ini |
---|
New file |
0,0 → 1,16 |
; Encodage : UTF-8 |
; Nom du projet |
nom_source = "baznat" |
; Nom de la base utilisée. |
bdd_nom = "tb_eflore" |
; URL de base des services de ce projet |
url_service="{ref:url_base}service:moissonnage:0.1/baznat" |
referentiel_source = 'bdtfx'; |
[meta-donnees] |
dureecache = 3600 |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/services/configurations/config_sophy.ini |
---|
9,6 → 9,7 |
; URL de base des services de ce projet |
url_service="{ref:url_base}service:moissonnage:0.1/sophy" |
referentiel_source = 'bdtfx'; |
[meta-donnees] |
dureecache = 3600 |
/trunk/services/bibliotheque/Maillage.php |
---|
10,7 → 10,7 |
private $indexLatitude; |
private $mailles; |
private $bdd = null; |
private $bdd = null; |
66,6 → 66,7 |
") ORDER BY axe, position"; |
$indexMailles = $this->getBdd()->recupererTous($requete); |
foreach ($indexMailles as $index) { |
if ($index['axe'] == 'lng') { |
$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']); |
89,7 → 90,7 |
public function ajouterPoints(& $points) { |
foreach ($points as $index => $point) { |
foreach ($points as $point) { |
list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point); |
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude); |
$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point); |
96,6 → 97,15 |
} |
} |
public function ajouterMailles(& $mailles) { |
foreach ($mailles as $maille) { |
$longitude = ($maille->longitudeOuest + $maille->longitudeEst) / 2; |
$latitude = ($maille->latitudeSud + $maille->latitudeNord) / 2; |
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude); |
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille); |
} |
} |
private function obtenirCoordonneesPoint($point) { |
$longitude = 0; |
$latitude = 0; |
123,107 → 133,31 |
return array($indexLongitude, $indexLatitude); |
} |
public function formaterSortie() { |
public function formaterSortie($toutesLesMailles = false) { |
$mailles_resume = array(); |
foreach ($this->mailles as $ligne) { |
foreach ($ligne as $maille) { |
$nombrePoints = $maille->getNombrePoints(); |
if ($nombrePoints == 0) |
continue; |
$mailles_resume[] = array( |
'zoom' => $this->zoom, |
'sud' => $maille->getLatitudeSud(), |
'ouest' => $maille->getLongitudeOuest(), |
'nord' => $maille->getLatitudeNord(), |
'est' => $maille->getLongitudeEst(), |
'points' => $nombrePoints, |
'type_site' => 'MAILLE' |
); |
} |
} |
if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0) |
return array(); |
return $mailles_resume; |
} |
public function formaterPourInsertionBdd() { |
$mailles_resume = array(); |
foreach ($this->mailles as $ligne) { |
foreach ($ligne as $maille) { |
if ($maille->getNombrePoints() > 0) { |
if ($nombrePoints > 0 || $toutesLesMailles) { |
$mailles_resume[] = array( |
'zoom' => $this->zoom, |
'sud' => $maille->getLatitudeSud(), |
'ouest' => $maille->getLongitudeOuest(), |
'nord' => $maille->getLatitudeNord(), |
'est' => $maille->getLongitudeEst(), |
'indexLat' => $maille->getIndexLatitude(), |
'indexLng' => $maille->getIndexLongitude(), |
'points' => $maille->getNombrePoints() |
'zoom' => $this->zoom, |
'sud' => $maille->getLatitudeSud(), |
'ouest' => $maille->getLongitudeOuest(), |
'nord' => $maille->getLatitudeNord(), |
'est' => $maille->getLongitudeEst(), |
'points' => $nombrePoints, |
'observations' => $maille->getNombreObservations(), |
'type_site' => 'MAILLE' |
); |
} |
} |
} |
if (count($mailles_resume[0]) == 0) |
if (count($mailles_resume) == 0 || count($mailles_resume[0]) == 0) |
return array(); |
return $mailles_resume; |
} |
public function zoomer() { |
$this->zoom += 1; |
} |
// redecoupage des mailles en 4 (fonction quadtree) |
// TODO : revoir le fonctionnement de cette methode (pour utilisation par les scripts uniquement) |
public function redecouperMailles() { |
$bdd = new Bdd(); |
while (count($this->indexLatitude) > 0) { |
array_pop($this->indexLatitude); |
} |
while (count($this->indexLongitude) > 0) { |
array_pop($this->indexLongitude); |
} |
$mailles = $this->resumePourInsertionBdd(); |
while (count($this->mailles) > 0) { |
array_pop($this->mailles); |
} |
foreach ($mailles as $maille) { |
$indexLat = 2 * $maille['indexLat']; |
$indexLng = 2 * $maille['indexLng']; |
// rechercher les nouvelles coordonnees des mailles au niveau de zoom inferieur |
$requete = "SELECT axe,position,debut,fin FROM mailles_index WHERE zoom=". $this->zoom ." AND ((axe='lat'" |
. " AND (position={$indexLat} OR position=" . ($indexLat+1) . ")) OR (axe='lng' AND" |
. " (position={$indexLng} OR position=" . ($indexLng+1) . "))) ORDER BY If(axe='lat',0,1)"; |
$resultats = $bdd->recupererTous($requete); |
$this->indexLatitude[$indexLat] = array($resultats[0]['debut'], $resultats[0]['fin']); |
$this->indexLatitude[$indexLat+1] = array($resultats[1]['debut'], $resultats[1]['fin']); |
$this->indexLongitude[$indexLng] = array($resultats[2]['debut'], $resultats[2]['fin']); |
$this->indexLongitude[$indexLng+1] = array($resultats[3]['debut'], $resultats[3]['fin']); |
} |
ksort($this->indexLatitude); |
ksort($this->indexLongitude); |
// creer et ajouter les nouvelles mailles a partir des nouveaux index |
foreach ($this->indexLatitude as $indexLat => $intervalleLat) { |
$ligne = array(); |
foreach ($this->indexLongitude as $indexLng => $intervalleLng) { |
$ligne[] = new Maille($intervalleLat[0], $intervalleLng[0], $intervalleLat[1], |
$intervalleLng[1], $indexLat, $indexLng); |
} |
$this->mailles[] = $ligne; |
} |
} |
public function getNombreMailles() { |
return count($this->mailles); |
} |
} |
?> |
/trunk/services/bibliotheque/VerificateurParametres.php |
---|
22,6 → 22,7 |
* On va verifier la disponibilite du referentiel pour ce service |
* |
* - num_taxon : numero taxonomique d'une espece |
* - nn : numero nomenclatural d'une espece |
* On va rechercher sa presence dans les referentiels disponibles |
* (les informations principales sur ce taxon seront renvoyees) |
* |
30,6 → 31,13 |
* |
* - auteur : l'auteur de l'observation |
* |
* - type_site : pour les observations, le type de point correspondant a la station cliquee |
* (STATION ou COMMUNE). Cela indique le niveau de precision ramene aux coordonnees des observations |
* |
* - date_debut et date_fin : intervalle de dates d'observation. On verifie que ce sont des dates valides |
* et que date_debut <= date_fin. Le programme peut accepter la presence d'un seul de ces deux |
* parametres : soit une date de debut, soit une date de fin |
* |
* La fonction principale de verification des parametres va parcourir tous les parametres, et verifier |
* pour chacun d'eux la validite de leurs valeurs. Dans le cas ou une valeur anormale est detectee |
* ou qu'elle se trouve en dehors de l'intervalle des resultats acceptes, une liste de messages d'erreur |
55,6 → 63,7 |
private $parametres = array(); |
private $validation = null; |
private $erreurs = array(); |
private $dateTraitee = false; |
private $bboxMonde = null; |
93,6 → 102,22 |
break; |
case 'num_taxon' : $this->traiterParametreTaxon($valeur); |
break; |
case 'nn' : $this->traiterParametreNomenclatural($valeur); |
break; |
case 'type_site' : $this->traiterParametreTypeSite($valeur); |
break; |
case 'nb_jours' : $this->traiterParametreNbJours($valeur); |
break; |
case 'date_debut' : |
case 'date_fin' : { |
$dateDebut = isset($this->parametres['date_debut']) ? $this->parametres['date_debut'] : null; |
$dateFin = isset($this->parametres['date_fin']) ? $this->parametres['date_fin'] : null; |
if (!$this->dateTraitee) { |
$this->traiterParametresDate($dateDebut, $dateFin); |
$this->dateTraitee = true; |
} |
break; |
} |
// autres parametres ==> les ignorer |
default : break; |
} |
207,7 → 232,9 |
private function estUnCodeDepartementValide($departement) { |
// expression reguliere pour verifier que c'est un nombre entier a 2 ou 3 chiffres |
$estUnDepartementValide = true; |
if (preg_match('/^\d{2,3}$/', $departement) != 1) { |
if ($departement == '2A' || $departement == '2B') { |
$estUnDepartementValide = true; |
} elseif (preg_match('/^\d{2,3}$/', $departement) != 1) { |
$estUnDepartementValide = false; |
} else { |
if ((intval($departement) < 1 || intval($departement) > 95) |
214,7 → 241,7 |
&& (intval($departement) < 971 || intval($departement) > 978)) { |
$estUnDepartementValide = false; |
} |
} |
} |
return $estUnDepartementValide; |
} |
224,6 → 251,10 |
} |
} |
private function traiterParametreTypeSite($typeSite) { |
$this->validation->typeSite = strtolower(trim($typeSite)); |
} |
private function traiterParametreReferentiel($referentiel) { |
if (!isset($this->validation->referentiel) && $referentiel != '*') { |
$referentielAUtiliser = $this->affecterNomCompletReferentiel($referentiel); |
251,29 → 282,51 |
private function traiterParametreTaxon($numeroTaxon) { |
if ($numeroTaxon != '*') { |
$taxon = null; |
if (isset($this->validation->referentiel)) { |
$taxon = $this->renvoyerTaxonDansReferentiel($numeroTaxon, $this->validation->referentiel); |
} else { |
// parcours de tous les referentiels jusqu'a retrouver le taxon dans sa liste |
$taxon = $this->rechercherTaxonDansReferentiels($numeroTaxon); |
$listeTaxons = explode(',', $numeroTaxon); |
foreach ($listeTaxons as $nt) { |
$taxon = null; |
if (isset($this->validation->referentiel)) { |
$taxon = $this->renvoyerTaxonDansReferentiel($nt, 'nt', $this->validation->referentiel); |
} else { |
$taxon = $this->rechercherTaxonDansReferentiels($nt, 'nt'); |
} |
if (is_null($taxon)) { |
$message = "Le numéro de taxon n'a pas permis de retrouver le taxon associé."; |
$this->ajouterErreur($message); |
} else { |
$this->ajouterTaxonAListe($taxon); |
$this->validation->referentiel = $taxon['referentiel']; |
} |
} |
if (is_null($taxon)) { |
$message = "Le numéro de taxon n'a pas permis de retrouver le taxon associé."; |
$this->ajouterErreur($message); |
} else { |
$this->validation->taxon = $taxon; |
$this->validation->referentiel = $taxon['referentiel']; |
} |
} |
private function traiterParametreNomenclatural($numeroNomenclatural) { |
if ($numeroNomenclatural != '*') { |
$listeTaxons = explode(',', $numeroNomenclatural); |
foreach ($listeTaxons as $nn) { |
$taxon = null; |
if (isset($this->validation->referentiel)) { |
$taxon = $this->renvoyerTaxonDansReferentiel($nn, 'nn', $this->validation->referentiel); |
} else { |
$taxon = $this->rechercherTaxonDansReferentiels($nn, 'nn'); |
} |
if (is_null($taxon)) { |
$message = "Le numéro nomenclatural n'a pas permis de retrouver le taxon associé."; |
$this->ajouterErreur($message); |
} else { |
$this->ajouterTaxonAListe($taxon); |
$this->validation->referentiel = $taxon['referentiel']; |
} |
} |
} |
} |
private function rechercherTaxonDansReferentiels($numeroTaxon) { |
private function rechercherTaxonDansReferentiels($numeroTaxon, $typeNumero) { |
$taxon = null; |
$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles(); |
foreach ($listeReferentiels as $nomReferentiel) { |
$taxon = $this->renvoyerTaxonDansReferentiel($numeroTaxon, $nomReferentiel); |
$taxon = $this->renvoyerTaxonDansReferentiel($numeroTaxon, $typeNumero, $nomReferentiel); |
if (!is_null($taxon)) { |
break; |
} |
281,13 → 334,69 |
return $taxon; |
} |
private function renvoyerTaxonDansReferentiel($numeroTaxon, $nomReferentiel) { |
private function renvoyerTaxonDansReferentiel($numeroTaxon, $typeNumero, $nomReferentiel) { |
$referentiel = new Referentiel($nomReferentiel); |
$referentiel->chargerTaxon($numeroTaxon); |
$referentiel->chargerTaxon($typeNumero, $numeroTaxon); |
$taxon = $referentiel->renvoyerTaxon(); |
return $taxon; |
} |
private function ajouterTaxonAListe($taxon) { |
if (!isset($this->validation->taxon)) { |
$this->validation->taxon = array($taxon); |
} elseif (!in_array($taxon, $this->validation->taxon)) { |
$this->validation->taxon[] = $taxon; |
} |
} |
private function traiterParametresDate($dateDebut, $dateFin) { |
$statutValidite = $this->verifierValiditeDate($dateDebut, 'début') |
+ $this->verifierValiditeDate($dateFin, 'fin'); |
if ($statutValidite == 2) { |
if (!is_null($dateDebut) && !is_null($dateFin) && $dateDebut > $dateFin) { |
$message = "Intervalle de dates incorrect : date de fin avant la date de début"; |
$this->ajouterErreur($message); |
} else { |
$this->validation->dateDebut = $dateDebut; |
$this->validation->dateFin = $dateFin; |
} |
} |
} |
private function verifierValiditeDate(& $date, $position) { |
$statutValidite = is_null($date) ? 1 : 0; |
$moisParDefaut = $position == 'début' ? 1 : 12; |
$jourParDefaut = $position == 'début' ? 1 : 31; |
if (!is_null($date)) { |
$split = explode("-", $date); |
$annee = intval($split[0]); |
$mois = isset($split[1]) ? intval($split[1]) : $moisParDefaut; |
$jour = isset($split[2]) ? intval($split[2]) : $jourParDefaut; |
if (!$this->estDateValide($jour, $mois, $annee)) { |
$message = "Date de {$position} saisie non valide"; |
$this->ajouterErreur($message); |
} else { |
$date = $annee."-".(($mois<10)?"0".$mois:$mois)."-".(($jour<10)?"0".$jour:$jour); |
$dateDuJour = date('Y-m-d'); |
if ($date > $dateDuJour) { |
$message = "La date de {$position} saisie postérieure à la date du jour : {$dateDuJour}"; |
$this->ajouterErreur($message); |
} else { |
$statutValidite = 1; |
} |
} |
} |
return $statutValidite; |
} |
private function estDateValide($jour, $mois, $annee) { |
$estBissextile = (($annee % 4 == 0 && $annee % 100 != 0) || ($annee % 400 == 0)); |
$dureeFevrier = $estBissextile ? 29 : 28; |
$dureeMois = array(1 => 31, 2 => $dureeFevrier, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, |
8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31); |
return ($annee >= 1900 && $mois >= 1 && $mois <= 12 && $jour >= 1 && $jour <= $dureeMois[$mois]); |
} |
private function verifierPresenceParametreSpatial() { |
$presenceParametreSpatial = false; |
if (isset($this->parametres['bbox']) |
300,6 → 409,16 |
} |
} |
private function traiterParametreNbJours($nbJours) { |
// verifier que c'est un nombre entier positif (avec expression reguliere) |
if (preg_match('/^\d+$/', $nbJours) != 1) { |
$message = "La valeur passée pour le nombre de jours doit être un entier positif."; |
$this->ajouterErreur($message); |
} elseif ($nbJours > 0) { |
$this->validation->nbJours = intval($nbJours); |
} |
} |
} |
?> |
/trunk/services/bibliotheque/FormateurJson.php |
---|
5,7 → 5,7 |
private $sourceDonnees; |
public function __construct($source) { |
public function __construct($source = '') { |
$this->sourceDonnees = $source; |
} |
14,23 → 14,24 |
$objetJSON = new StdClass(); |
$objetJSON->type = "FeatureCollection"; |
$objetJSON->stats = new StdClass(); |
$objetJSON->stats->communes = 0; |
$objetJSON->stats->stations = 0; |
$objetJSON->stats->source = $this->sourceDonnees; |
$objetJSON->stats->formeDonnees = ''; |
if (count($stations) > 0) { |
$objetJSON->stats->formeDonnees = ($stations[0]['type_site'] == 'MAILLE') ? 'maille' : 'point'; |
} |
$objetJSON->stats->sites = 0; |
$objetJSON->stats->observations = 0; |
$objetJSON->features = array(); |
foreach ($stations as $station) { |
$stationJSON = NULL; |
// construction d'un objet feature adapte a la structure des donnees spatiales |
if ($station['type_site'] == 'MAILLE') { |
$stationJSON = $this->formaterMaille($station); |
$objetJSON->stats->sites += $station['points']; |
} else { |
if ($station['type_site'] == 'STATION') { |
$objetJSON->stats->communes ++; |
} else { |
$objetJSON->stats->stations ++; |
} |
$objetJSON->stats->sites ++; |
$stationJSON = $this->formaterPoint($station); |
} |
$objetJSON->stats->observations += $station['observations']; |
if (!is_null($stationJSON)) { |
$objetJSON->features[] = $stationJSON; |
} |
44,6 → 45,7 |
$json->geometry = new StdClass(); |
$json->properties = new StdClass(); |
$json->geometry->type = "Point"; |
$json->properties->source = $this->sourceDonnees; |
$json->properties->typeSite = $station['type_site']; |
if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') { |
$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']); |
54,7 → 56,6 |
if ($this->sourceDonnees == 'floradata') { |
$json->properties->nom = $this->construireNomStationFloradata($station); |
} else { |
$station['code_insee'] = ''; |
$codeDepartement = $this->extraireCodeDepartement($station['code_insee']); |
$json->properties->nom = trim($station['nom'])." ({$codeDepartement})"; |
} |
71,7 → 72,7 |
if (strlen($nom) == 0) { |
$nom = 'station sans nom, '.trim($station['zone_geo']); |
} |
$nom .= " ({$codeDepartement})";; |
$nom .= " ({$codeDepartement})"; |
} |
return $nom; |
} |
87,9 → 88,6 |
private function formaterMaille($maille) { |
if ($maille['points'] == 0) { |
return null; |
} |
$json = new StdClass(); |
$json->type = "Feature"; |
$json->geometry = new StdClass(); |
102,7 → 100,8 |
array(floatval($maille['sud']), floatval($maille['ouest'])) |
); |
$json->properties = new StdClass(); |
$json->properties->typeSite = $maille['type_site']; |
$json->properties->source = $this->sourceDonnees; |
$json->properties->typeSite = 'MAILLE'; |
$json->properties->nombrePoints = $maille['points']; |
return $json; |
} |
136,6 → 135,20 |
return $url; |
} |
public function formaterMaillesVides($mailles) { |
$objetJSON = new StdClass(); |
$objetJSON->type = "FeatureCollection"; |
$objetJSON->stats = new StdClass(); |
$objetJSON->stats->source = ''; |
$objetJSON->stats->formeDonnees = 'maille'; |
$objetJSON->stats->sites = 0; |
$objetJSON->features = array(); |
foreach ($mailles as $maille) { |
$objetJSON->features[] = $this->formaterMaille($maille); |
} |
return $objetJSON; |
} |
} |
?> |
/trunk/services/bibliotheque/Maille.php |
---|
10,7 → 10,9 |
private $indexLongitude; |
private $points = array(); |
private $nombrePoints = 0; |
private $nombrePoints; |
private $observations = array(); |
private $nombreObservations; |
public function __construct($sud, $ouest, $nord, $est, $indexLat, $indexLng) { |
22,9 → 24,11 |
$this->indexLongitude = $indexLng; |
} |
public function ajouterPoint(& $point) { |
public function ajouterPoint($point) { |
$this->points[] = $point; |
$this->nombrePoints ++; |
$this->observations[] = $point['observations']; |
$this->nombreObservations += $point['observations']; |
} |
public function getLatitudeNord() { |
51,18 → 55,31 |
return $this->indexLongitude; |
} |
public function getPoints() { |
return $this->points; |
} |
public function getNombrePoints() { |
return $this->nombrePoints; |
} |
public function getPoint($index = 0) { |
return (!isset($this->points[$index])) ? NULL : $this->points[$index]; |
public function getObservations() { |
return $this->observations; |
} |
public function getNombreObservations() { |
return $this->nombreObservations; |
} |
public function totalNonNul() { |
return !is_null($this->nombrePoints); |
return count($this->points) > 0; |
} |
public function combinerMailles(& $maille) { |
$this->nombrePoints += $maille->nombre_sites; |
$this->nombreObservations += $maille->nombre_observations; |
} |
} |
?> |
/trunk/services/bibliotheque/Referentiel.php |
---|
31,24 → 31,19 |
* |
*/ |
define("RANG_FAMILLE", 180); |
class Referentiel { |
private $nomComplet; |
private $nomCourt; |
private $taxon; |
private $bdd = null; |
private $nomsChampsBdtfx = array('nn' => 'num_nom_retenu', 'nt' => 'num_taxonomique', 'ns' => 'nom_sci'); |
private $nomsChampsBdtxa = array('nn' => 'num_nom_retenu', 'nt' => 'num_tax', 'ns' => 'nom_sci'); |
private $champs; |
public function __construct($nomReferentiel, $taxon = null) { |
$this->nomComplet = $nomReferentiel; |
$this->nomCourt = current(explode('_', $nomReferentiel)); |
58,9 → 53,7 |
} |
$this->taxon = $taxon; |
} |
public function renvoyerNomCompletReferentiel() { |
return $this->nomComplet; |
} |
69,15 → 62,16 |
return $this->taxon; |
} |
public function chargerTaxon($numTaxon) { |
public function chargerTaxon($typeNumero, $numTaxon) { |
$taxon = null; |
// verifier que le numero de taxon soit bien une chaine de caracteres composee uniquement |
// que de nombres entiers avant de construire la requete SQL a executer |
if (preg_match('/^\d+$/', $numTaxon) == 1) { |
$champWhere = $typeNumero == 'nt' ? $this->champs['nt']: 'num_nom'; |
$requete = |
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ". |
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ". |
$this->champs['nt']."={$numTaxon} AND num_nom=".$this->champs['nn']." ". |
$champWhere."={$numTaxon} AND num_nom=".$this->champs['nn']." ". |
"ORDER BY rang, If(num_nom=".$this->champs['nn'].", 0, 1) LIMIT 0, 1"; |
$taxon = $this->getBdd()->recuperer($requete); |
if ($taxon == false) { |
89,10 → 83,21 |
$this->taxon = $taxon; |
} |
private function getBdd() { |
if (is_null($this->bdd)) { |
$this->bdd = new Bdd(); |
} |
$nomBdd = Config::get('bdd_eflore'); |
if (is_null($nomBdd)) { |
$nomBdd = Config::get('bdd_nom'); |
} |
$this->bdd->requeter("USE ".$nomBdd); |
return $this->bdd; |
} |
public function recupererSousTaxons($listeNn = null) { |
public function recupererTaxonsSousEspeces($listeNn = null) { |
$sousTaxons = array(); |
if (!is_null($this->taxon) && $this->taxon['rang'] >= RANG_FAMILLE) { |
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.espece')) { |
if (is_null($listeNn)) { |
$listeNn = $this->taxon['nn']; |
} |
109,28 → 114,24 |
} |
// recherche de sous taxons au niveau inferieur (parcours recursif de la methode) |
if (count($resultats) > 0) { |
$sousTaxons = array_merge($sousTaxons, $this->recupererSousTaxons($nouvelleListeNn)); |
$sousTaxons = array_merge($sousTaxons, $this->recupererTaxonsSousEspeces($nouvelleListeNn)); |
} |
} |
return $sousTaxons; |
} |
private function getBdd() { |
if (is_null($this->bdd)) { |
$this->bdd = new Bdd(); |
public function recupererTaxonsFamilles() { |
$sousTaxons = array(); |
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.genre')) { |
$requete = |
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ". |
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ". |
"num_tax_sup=".$this->taxon['nn']." AND num_nom=".$this->champs['nn']; |
$sousTaxons = $this->getBdd()->recupererTous($requete); |
} |
$nomBdd = Config::get('bdd_eflore'); |
if (is_null($nomBdd)) { |
$nomBdd = Config::get('bdd_nom'); |
} |
$this->bdd->requeter("USE ".$nomBdd); |
return $this->bdd; |
return $sousTaxons; |
} |
public static function recupererListeReferentielsDisponibles() { |
$tableau = array(); |
$tableauPartiel = explode(',', Config::get('referentiels_dispo')); |
/trunk/widget/modules/carto/Carto.php |
---|
5,13 → 5,20 |
const SERVICE_CARTO_NOM = 'carto'; |
const SERVICE_CARTO_ACTION_DEFAUT = 'carto'; |
private $carte = null; |
private $source = null; |
private $carte = null; |
private $source = null; |
private $titre = null; |
private $logo = null; |
private $urlSite = null; |
private $numeroNomenclatural = '*'; |
private $numeroTaxon = '*'; |
private $auteur = '*'; |
private $referentiel = '*'; |
private $departement = '*'; |
private $auteur = '*'; |
private $dateDebut = '*'; |
private $dateFin = '*'; |
private $nbJours = 0; |
/** |
43,10 → 50,17 |
extract($this->parametres); |
$this->carte = (isset($carte) ? $carte : self::SERVICE_CARTO_ACTION_DEFAUT); |
$this->source = (isset($source) ? $source : $this->config['carto']['sourceParDefaut']); |
$this->logo = (isset($logo) ? $logo : null); |
$this->titre = (isset($titre) ? $titre : null); |
$this->urlSite = (isset($url_site) ? $url_site : null); |
$this->numeroTaxon = (isset($num_taxon) ? $num_taxon : '*'); |
$this->numeroNomenclatural = (isset($nn) ? $nn : '*'); |
$this->departement = (isset($dept) ? $dept : '*'); |
$this->referentiel = (isset($referentiel) ? $referentiel : '*'); |
$this->auteur = (isset($auteur) ? $auteur : '*'); |
$this->dateDebut = (isset($date_debut) ? $date_debut : '*'); |
$this->dateFin = (isset($date_fin) ? $date_fin : '*'); |
$this->nbJours = (isset($nb_jours) ? intval($nb_jours) : 0); |
} |
/** |
60,18 → 74,27 |
$widget['donnees']['url_serivce_carto'] = $this->contruireUrlServiceCarto(); |
$widget['donnees']['url_base'] = $url_base; |
$widget['donnees']['source'] = $this->source; |
$widget['donnees']['titre'] = $this->titre; |
$widget['donnees']['logo'] = $this->logo; |
$widget['donnees']['url_site'] = $this->urlSite; |
$widget['donnees']['auteur'] = $this->auteur; |
$widget['donnees']['nn'] = $this->numeroNomenclatural; |
$widget['donnees']['num_taxon'] = $this->numeroTaxon; |
$widget['donnees']['auteur'] = $this->auteur; |
$widget['donnees']['departement'] = $this->departement; |
$widget['donnees']['referentiel'] = $this->referentiel; |
$widget['donnees']['date_debut'] = $this->dateDebut; |
$widget['donnees']['date_fin'] = $this->dateFin; |
$widget['donnees']['nb_jours'] = $this->nbJours; |
$widget['donnees']['communeImageUrl'] = $this->config['carto']['communeImageUrl']; |
$widget['donnees']['pointImageUrl'] = $this->config['carto']['pointImageUrl']; |
$widget['donnees']['liensVersSources'] = $this->config['carto']['liensVersSources']; |
$widget['donnees']['sourcesDispo'] = $this->config['carto']['sourcesDispo']; |
$widget['donnees']['nomSourcesDispo'] = $this->config['carto']['nomSourcesDispo']; |
$widget['donnees']['listeSources'] = $this->config['carto']['sourcesDispo']; |
$widget['donnees']['nomListeSources'] = $this->config['carto']['nomSourcesDispo']; |
$widget['donnees']['titreLegende'] = $this->config['carto']['titreLegende']; |
$widget['donnees']['urlLimitesCommunales'] = $this->obtenirUrlsLimitesCommunales(); |
$widget['donnees']['zoomMaximumMaillage'] = $this->config['carto']['zoomMaximumMaillage']; |
$widget['donnees']['seuilMaillage'] = $this->config['carto']['seuilMaillage']; |
$widget['squelette'] = 'carto'; |
return $widget; |
/trunk/widget/modules/carto/squelettes/scripts/carto.js |
---|
1,35 → 1,62 |
// Javascript Document |
// ============================================================== |
// FONCTIONS ADDITIONNELLES POUR GERER LES URLS |
// =================================================================================== |
// FONCTIONS ADDITIONNELLES POUR GERER LES URLS ET L'OUVERTRURE DE NOUVELLE FENETRE |
function convertirEnParametresUrl(objet) { |
var parametresUrl = ''; |
for (attribut in objet) { |
if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' || |
objet[attribut] == null) |
objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0) |
continue; |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut].toString(); |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut]; |
} |
return parametresUrl; |
}; |
function estParametreDansUrl(nomParametre) { |
var estDansUrl = false; |
var listeParametres = location.search.substring(1).split("&"); |
function recupererParametreDansUrl(nomParametre, chaineRecherche) { |
var split = chaineRecherche.split('?'); |
chaineRecherche = split[split.length-1]; |
var valeurParametre = null; |
var listeParametres = chaineRecherche.split("&"); |
for (var index = 0; index < listeParametres.length; index ++) { |
var split = listeParametres[index].split("="); |
if (split[0] == nomParametre) { |
estDansUrl = true; |
valeurParametre = split[1]; |
break; |
} |
} |
return estDansUrl; |
return valeurParametre; |
}; |
// ============================================================= |
function estValeurDansTableau(tableau, valeur) { |
var index; |
for (index = 0; index < tableau.length && tableau[index] != valeur; index ++); |
return (tableau.length > 0 && index != tableau.length); |
} |
function ouvrirNouvelleFenetre(element, event) { |
window.open(element.href); |
return arreter(event); |
} |
function arreter(event) { |
if (event.stopPropagation) { |
event.stopPropagation(); |
} else if (window.event) { |
window.event.cancelBubble = true; |
} |
if (event.preventDefault) { |
event.preventDefault(); |
} |
event.returnValue = false; |
return false; |
} |
// ============================================================= |
var map = null, |
optionsCoucheOSM = { |
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,' |
37,7 → 64,7 |
maxZoom: 18 |
}, |
optionsCoucheGoogle = { |
attribution: 'Map data ©' + new Date().getFullYear() + ' <a href="http://maps.google.com">Google</a>', |
attribution: 'Map data ©'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>', |
maxZoom: 18 |
}, |
coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", |
51,16 → 78,25 |
zoom : 6, |
minZoom : 3, |
maxBounds : [[-85.051129, -180], [85.051129, 180]], |
layers : [couchePlanGoogle] |
layers : [coucheOSM] |
}, |
zoom = 6, |
legende = null, |
coucheDepartement = null, |
infoBulle = null; |
var coucheSites = new L.FeatureGroup(), |
points = new Array(), |
coucheSites = new L.FeatureGroup(), |
sources = new Object(), |
formeDonnees = '', |
popupMaille = null; |
overlays = []; |
var requeteChargementPoints = null, |
chargementMaillesEnCours = false, |
doitRafraichirCarte = true, |
chargementCommunesEnCours = false, |
timer = null, |
url = ''; |
73,12 → 109,12 |
function initialiserWidget() { |
initialiserCarte(); |
dimensionnerOverlay(); |
initialiserPanneauControle(); |
initialiserSources(); |
initialiserListeners(); |
initialiserPanneauControle(); |
chargerLimitesCommunales(); |
if (!estParametreDansUrl('source')) { |
initialiserSources(); |
} |
chargerMaillesVides(); |
programmerRafraichissementCarte(); |
} |
89,7 → 125,18 |
} |
}); |
function dimensionnerOverlay() { |
var taille = '1.6'; |
var tailleMaxIcones = 20; |
var padding_icones = 8; |
$("#zone-titre h1").css('font-size', (taille)+'em'); |
$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px"); |
$('#zone-titre').height(tailleMaxIcones*2); |
var left = ($(window).width()-$('#zone-titre').width())/2; |
$('#zone-titre').css('left',left); |
} |
function dimensionnerCarte() { |
$('#map').height($(window).height()); |
$('#map').width($(window).width()); |
103,13 → 150,15 |
couchePlanGoogle.addTo(map); |
coucheSatelliteGoogle.addTo(map); |
var echelle = new L.Control.Scale({ |
maxWidth : 100, |
maxWidth : 32, |
metric : true, |
imperial : false, |
updateWhenIdle : true |
}); |
map.addControl(echelle); |
zoom = map.getZoom(); |
} |
function initialiserListeners() { |
map.on('moveend', surChangementVueSurCarte); |
map.on('zoomend', surChangementVueSurCarte); |
121,39 → 170,32 |
function initialiserPanneauControle() { |
var baseMaps = { |
"OSM" : coucheOSM, |
"OpenStreetMap" : coucheOSM, |
"Plan" : couchePlanGoogle, |
"Satellite" : coucheSatelliteGoogle |
}; |
var overlayMaps = {}; |
if (!estParametreDansUrl('source')) { |
for (var index = 0; index < nomSources.length; index ++) { |
overlayMaps[nomSources[index]] = new L.LayerGroup(); |
} |
for (var index = 0; index < listeSources.length; index ++) { |
sources[listeSources[index]] = estValeurDansTableau(source, listeSources[index]); |
overlayMaps[listeSources[index]] = new L.LayerGroup(); |
} |
L.control.layers(baseMaps, overlayMaps).addTo(map); |
coucheOSM.bringToBack(); |
couchePlanGoogle.bringToFront(); |
coucheOSM.bringToFront(); |
couchePlanGoogle.bringToBack(); |
coucheSatelliteGoogle.bringToBack(); |
// garder par defaut la couche plan google comme selectionnee dans le panel |
var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector'); |
selecteursFonds[0].checked = false; |
selecteursFonds[1].checked = true; |
selecteursFonds[0].checked = true; |
selecteursFonds[1].checked = false; |
selecteursFonds[2].checked = false; |
} |
function chargerLimitesCommunales() { |
coucheDepartement = new L.KML(null, {async : true}).addTo(map); |
if (urlsLimitesCommunales != null) { |
for (var index = 0; index < urlsLimitesCommunales.length; index ++) { |
var url = urlsLimitesCommunales[index]; |
var coucheDepartement = new L.KML(url, {async: true}); |
coucheDepartement.on("loaded", function(e) { |
map.fitBounds(e.target.getBounds()); |
}); |
map.addLayer(coucheDepartement); |
} |
coucheDepartement.addKMLFiles(urlsLimitesCommunales); |
} |
} |
160,68 → 202,166 |
function initialiserSources() { |
overlays = $('.leaflet-control-layers-overlays .leaflet-control-layers-selector'); |
$.each(overlays, function (index, input) { |
input.value = sources[index]; |
input.value = listeSources[index]; |
input.id = 'overlay' + (index+1); |
var lien = '<a href="' + liensVersSources[index] + '" target="_blank">' + nomSources[index] + '</a>'; |
var lien = '<a href="' + liensVersSources[index] + '" target="_blank">' + nomListeSources[index] + '</a>'; |
$('#overlay' + (index+1) + ' ~ span').html(lien); |
input.type = 'radio'; |
input.checked = (sources[index] == source); |
input.onchange = function(event) { |
// evenement sur selection/deselection overlay dans sa checkbox |
input.checked = sources[listeSources[index]]; |
input.onclick = function(event) { |
changerSource(event.target.value); |
} |
}); |
} |
function determinerSourcesSelectionnees() { |
var sourcesSelectionnees = new Array(); |
for (source in sources) { |
if (sources[source] == true) { |
sourcesSelectionnees.push(source); |
} |
} |
return sourcesSelectionnees; |
} |
function surChangementVueSurCarte() { |
if (doitRafraichirCarte == false) { |
doitRafraichirCarte = true; |
} else { |
programmerRafraichissementCarte(); |
supprimerTousLayers(); |
zoom = map.getZoom(); |
chargerMaillesVides(); |
} |
} |
function programmerRafraichissementCarte() { |
if(timer != null) { |
function chargerMaillesVides() { |
chargementMaillesEnCours = true; |
if (timer != null) { |
window.clearTimeout(timer); |
} |
if(requeteChargementPoints != null) { |
requeteChargementPoints.abort(); |
requeteChargementPoints = null; |
} |
if (requeteChargementPoints != null) { |
stopperRequeteAjax(); |
} |
timer = window.setTimeout(function() { |
supprimerLocalisations(); |
afficherMessageChargement('stations'); |
chargerLocalisations(); |
}, 400); |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : "floradata", |
"bbox" : coordonneesBordure, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "mailles?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
}, 400); |
} |
function programmerRafraichissementCarte(source) { |
source = (source == null || source == 'null') ? null : source; |
if (!chargementMaillesEnCours) { |
if (timer != null) { |
window.clearTimeout(timer); |
} |
if (requeteChargementPoints != null) { |
if (source == null) { |
stopperRequeteAjax(); |
} |
} |
timer = window.setTimeout("rafraichirDonnnees('"+source+"')", 250); |
} else { |
window.setTimeout("programmerRafraichissementCarte('"+source+"')", 400); |
} |
} |
function supprimerLocalisations() { |
function stopperRequeteAjax() { |
requeteChargementPoints.abort(); |
requeteChargementPoints = null; |
} |
function rafraichirDonnnees(source) { |
source = (source == null || source == 'null') ? null : source; |
if (coucheDepartement == null || coucheDepartement.getStatus() == KML_READY) { |
if (source != null) { |
chargerLocalisations(source); |
} else { |
supprimerLocalisations(); |
for (source in sources) { |
if (sources[source] == true) { |
chargerLocalisations(source); |
} |
} |
} |
} else { |
window.setTimeout("rafraichirDonnnees('"+source+"')", 800); |
} |
} |
function supprimerTousLayers() { |
coucheSites.clearLayers(); |
points = []; |
formeDonnees = ''; |
} |
function supprimerLocalisations(source) { |
source = (typeof(source) == 'undefined') ? null : source; |
if (source != null) { |
var sourceUrl = recupererParametreDansUrl('source', url); |
if (requeteChargementPoints != null && sourceUrl == source && source != null) { |
stopperRequeteAjax(); |
} |
coucheSites.eachLayer(function(layer) { |
supprimerLayer(layer, source); |
}); |
if (source != null) { |
supprimerPointsListe(source); |
} |
var sourcesSelectionnees = determinerSourcesSelectionnees(); |
if (sourcesSelectionnees.length == 1 && determinerNombreMarqueurs(sourcesSelectionnees[0]) > 0) { |
transformerMaillesEnPoints(sourcesSelectionnees[0]); |
} |
var sontPointsAffiches = (points.length>0 && determinerNombreMailles(false)==0); |
formeDonnees = sontPointsAffiches ? 'point' : 'maille'; |
} |
} |
function estLayerUtilisePourSource(layer, source) { |
return ( |
(layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[source]) != 'undefined') || |
(layer.typeSite != 'MAILLE' && layer.source == source) |
); |
} |
function supprimerLayer(layer, source) { |
if (estLayerUtilisePourSource(layer, source)) { |
if (layer.typeSite == 'MAILLE') { |
supprimerSourceDansMaille(layer, source); |
} else { |
coucheSites.removeLayer(layer); |
} |
} |
} |
function changerSource(projetClique) { |
// deselctionner les autres boutons des controles d'overlays dans le panel |
var indexProjetClique; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].value != projetClique) { |
overlays[index].checked = false; |
if (overlays[index].value == projetClique) { |
indexProjetClique = index; |
} |
} |
// afficher les sites dans la carte pour le projet selectionne |
if (infoBulle != null) { |
masquerInfoBulle(); |
masquerInfoBulle(); |
sources[projetClique] = overlays[indexProjetClique].checked; |
if (sources[projetClique] == true) { |
programmerRafraichissementCarte(projetClique); |
} else { |
supprimerLocalisations(projetClique); |
} |
source = projetClique; |
programmerRafraichissementCarte(); |
} |
function afficherMessageChargement(element) { |
var divTmplElement = 'tpl-chargement-' + element; |
$("#zone-chargement").append($("#" + divTmplElement).text()); |
$("#zone-chargement").css('display', 'block'); |
if ($("#zone-chargement").css('display') == 'none') { |
var divTmplElement = 'tpl-chargement-' + element; |
$("#zone-chargement").append($("#" + divTmplElement).text()); |
$("#zone-chargement").css('display', 'block'); |
} |
} |
function masquerMessageChargement() { |
245,37 → 385,43 |
return (requeteChargementPoints != null && requeteChargementPoints.readyState != 4); |
} |
function retourRequeteOK() { |
function estStatutRequeteOK() { |
return ((requeteChargementPoints.status == 200 || requeteChargementPoints.status == 304) |
|| requeteChargementPoints.status == 0); |
} |
function chargerLocalisations() { |
// generer l'URL du script a interroger sur le serveur |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : source, |
"num_taxon" : num_taxon, |
"referentiel" : referentiel, |
"dept" : dept, |
"auteur" : auteur, |
"bbox" : coordonneesBordure, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
function chargerLocalisations(source) { |
if (requeteEnCours()) { |
window.setTimeout("chargerLocalisations('"+source+"')", 400); |
} else { |
afficherMessageChargement('stations'); |
// generer l'URL du script a interroger sur le serveur |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : source, |
"num_taxon" : numTaxon, |
"referentiel" : referentiel, |
"dept" : dept, |
"nn" : nn, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"bbox" : coordonneesBordure, |
"nb_jours" : nbJours, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
} |
} |
function calculerCoordonneesBordure() { |
var bordure = map.getBounds(); |
var ouest = bordure.getSouthWest().lng, |
sud = Math.max(bordure.getSouthWest().lat, -85.051129), |
est = bordure.getNorthEast().lng, |
nord = Math.min(bordure.getNorthEast().lat, 85.051129); |
var ouest = bordure.getSouthWest().lng.toFixed(6), |
sud = Math.max(bordure.getSouthWest().lat, -85.051129).toFixed(6), |
est = bordure.getNorthEast().lng.toFixed(6), |
nord = Math.min(bordure.getNorthEast().lat, 85.051129).toFixed(6); |
// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees |
// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur) |
if (ouest < -180) { |
293,104 → 439,178 |
function traiterDonneesStations() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
if (!retourRequeteOK()) { |
if (!estStatutRequeteOK()) { |
alert(texte); |
} else { |
var donneesJSON = eval("(function(){return " + texte + ";})()"); |
if (typeof(donneesJSON) != 'undefined' && typeof(donneesJSON.features) != 'undefined') { |
ajouterObjets(donneesJSON); |
if (donneesJSON != null && typeof(donneesJSON.features) != 'undefined') { |
ajouterStationsSurCarte(donneesJSON); |
} |
} |
} |
function ajouterObjets(data) { |
coucheSites.clearLayers(); |
var contientMailles = (data.features[0].properties.typeSite == 'MAILLE'); |
for (var index = 0; index < data.features.length; index ++) { |
switch (data.features[index].properties.typeSite) { |
case 'MAILLE' : ajouterMaille(data.features[index]); |
break; |
case 'COMMUNE' : |
case 'STATION' : ajouterPoint(data.features[index]); |
break; |
function ajouterStationsSurCarte(data) { |
if (doitTransformerEnMaille(data.stats)) { |
if (points.length > 0 && data.stats.source != '') { |
combinerMaillesEtPoints(); |
} |
formeDonnees = 'maille'; |
} else { |
formeDonnees = data.stats.formeDonnees; |
} |
if (contientMailles && legende == null) { |
var sourceDonnees = data.stats.source; |
for (var index = 0; index < data.features.length; index ++) { |
ajouterStation(data.features[index]); |
} |
if (formeDonnees == 'maille' && data.stats.sites > 0) { |
afficherLegende(); |
} else if (legende != null) { |
regenererInfobulleMailles(); |
} else { |
masquerLegende(); |
} |
if (chargementMaillesEnCours) { |
chargementMaillesEnCours = false; |
programmerRafraichissementCarte(); |
} |
} |
function ajouterMaille(feature) { |
function ajouterStation(feature) { |
if (feature.properties.typeSite == 'MAILLE') { |
traiterMaille(feature); |
} else { |
ajouterPoint(feature); |
} |
} |
function doitTransformerEnMaille(statsFeatures) { |
var condition1 = (formeDonnees == 'point' && statsFeatures.formeDonnees =='maille'); |
var condition2 = (formeDonnees == 'maille' && statsFeatures.formeDonnees =='point' |
&& determinerNombreMailles(false) > 0); |
var condition3 = (statsFeatures.formeDonnees == 'point' && map.getZoom() <= ZOOM_MAXIMUM_MAILLAGE |
&& (points.length+statsFeatures.sites) > SEUIL_MAILLAGE); |
return (condition1 || condition2 || condition3); |
} |
// ==================================================================== |
// Gestion des mailles |
var optionsMaille = { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillOpacity : 0.6 |
}; |
function determinerNombreMailles(prendToutesMailles) { |
var nombreMailles = 0; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
var nombrePoints = 0; |
for (var source in layer.nombrePoints) { |
nombrePoints = layer.nombrePoints[source]; |
} |
if (prendToutesMailles || nombrePoints>0) { |
nombreMailles ++; |
} |
} |
}); |
return nombreMailles; |
} |
function traiterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]); |
coordonnees.push(sommet); |
} |
var objet = new L.Polygon(coordonnees, { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillColor : getColor(feature.properties.nombrePoints), |
fillOpacity : 0.6 |
}); |
objet.typeSite = feature.properties.typeSite; |
objet.nombrePoints = feature.properties.nombrePoints; |
objet.on('click', clicSurMaille); |
coucheSites.addLayer(objet); |
// afficher le nombre de points inclus dans la maille |
afficherNombreStationsDansMaille(objet); |
var maille = rechercherMailleExistante(coordonnees); |
if (maille) { |
mettreAJourMaille(maille, feature); |
} else if (feature.properties.nombrePoints > 0) { |
ajouterMaille(feature); |
} |
} |
function afficherNombreStationsDansMaille(maille) { |
// comme la div qui contiendra la valeur du nombre de stations va se placer dans la page |
// au centre de la maille (et qui va servir de point d'ancrage pour le bord gauche par defaut) |
// il est necessaire de creer un decalage vers la gauche en fonction du nombre de chiffres |
var decalage = calculerDecalagePositionnementNombre(maille.nombrePoints); |
var sudMaille = maille._originalPoints[0].y, |
ouestMaille = maille._originalPoints[0].x, |
nordMaille = maille._originalPoints[2].y, |
estMaille = maille._originalPoints[2].x, |
centreMaille = new L.Point((ouestMaille+estMaille)/2 - decalage, (sudMaille+nordMaille)/2); |
var divIcon = new L.divIcon({ |
className : "nombre-sites", |
html : maille.nombrePoints |
function rechercherMailleExistante(coordonnees) { |
var mailleTrouvee = null; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
if (sontMaillesIdentiques(coordonnees, layer._latlngs)) { |
mailleTrouvee = layer; |
return; |
} |
} |
}); |
var marqueurDiv = new L.Marker(map.layerPointToLatLng(centreMaille), { |
icon : divIcon, |
maille : maille.getBounds() |
}); |
marqueurDiv.on('click', clicSurMaille); |
coucheSites.addLayer(marqueurDiv); |
return mailleTrouvee; |
} |
function calculerDecalagePositionnementNombre(nombrePoints) { |
var recul = 0; |
if (nombrePoints >= 10000) { |
recul = 14; |
} else if (nombrePoints >= 1000) { |
recul = 9; |
} else if (nombrePoints >= 100) { |
recul = 5; |
function sontMaillesIdentiques(coordonnees1, coordonnees2) { |
return ( |
coordonnees1[0].lat == coordonnees2[0].lat && |
coordonnees1[0].lng == coordonnees2[0].lng && |
coordonnees1[2].lat == coordonnees2[2].lat && |
coordonnees1[2].lng == coordonnees2[2].lng |
); |
} |
function ajouterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]); |
coordonnees.push(sommet); |
} |
return recul; |
var maille = new L.Polygon(coordonnees); |
maille.setStyle(optionsMaille); |
maille.typeSite = feature.properties.typeSite; |
maille.nombrePoints = new Object(); |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
coucheSites.addLayer(maille); |
colorerMaille(maille); |
} |
function clicSurMaille(event) { |
if (event.target._zIndex != null) { |
map.fitBounds(event.target.options.maille) |
function mettreAJourMaille(maille, feature) { |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
/*if (typeof(maille.nombrePoints[feature.properties.source]) == 'undefined') { |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
} else { |
map.fitBounds(event.target.getBounds()); |
maille.nombrePoints[feature.properties.source] += nombreAAjouter; |
}*/ |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
colorerMaille(maille); |
} |
function regenererInfobulleMailles() { |
$('.leaflet-clickable').addClass('tooltip'); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
genererInfobulle(layer); |
} |
}); |
} |
function colorerMaille(maille) { |
var nombrePoints = 0; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints += maille.nombrePoints[sourceMaille]; |
} |
if (nombrePoints > 0) { |
maille.on('click', surClicMaille); |
maille.setStyle({fillColor : genererCouleur(nombrePoints), fillOpacity: 0.45, opacity: 0.7}); |
} else { |
maille.setStyle({fillOpacity: 0, opacity: 0}); |
maille.off('click', surClicMaille); |
} |
} |
// generer la couleur a afficher pour les mailles |
function getColor(nombrePoints) { |
function surClicMaille(event) { |
map.fitBounds(event.layer.getBounds()); |
} |
function genererCouleur(nombrePoints) { |
var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64}, |
seuils = [1, 10, 50 ,100, 500, 1000, 2500], |
pas = 26, |
400,46 → 620,16 |
} |
couleur.vert -= position*pas; |
return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')'; |
/*var codeHexa = 'rgb(231,224,64)'; |
if (nombrePoints >= 2500) { |
codeHexa = 'rgb(231,68,64)'; |
} else if (nombrePoints >= 1000) { |
codeHexa = 'rgb(231,94,64)'; |
} else if (nombrePoints >= 500) { |
codeHexa = 'rgb(231,120,64)'; |
} else if (nombrePoints >= 100) { |
codeHexa = 'rgb(231,146,64)'; |
} else if (nombrePoints >= 50) { |
codeHexa = 'rgb(231,172,64)'; |
} else if (nombrePoints >= 10) { |
codeHexa = 'rgb(231,198,64)'; |
} |
return codeHexa;*/ |
} |
function ajouterPoint(feature) { |
var iconePoint = new L.Icon({ iconUrl : pointImageUrl, iconSize : [16, 16] }), |
iconeCommune = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }), |
icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune, |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]), |
marker = new L.Marker(point, { |
icon : icone, |
type : feature.properties.typeSite, |
title : feature.properties.nom |
}).addTo(map); |
marker.on('click', surClicMarqueur); |
coucheSites.addLayer(marker); |
} |
function afficherLegende() { |
legende = new L.Control({position : 'bottomright'}); |
legende.onAdd = function(map) { |
return construireContenuHtmlLegende(); |
}; |
map.addControl(legende); |
if (legende == null) { |
legende = new L.Control({position : 'bottomright'}); |
legende.onAdd = function(map) { |
return construireContenuHtmlLegende(); |
}; |
map.addControl(legende); |
} |
} |
function construireContenuHtmlLegende() { |
450,7 → 640,7 |
for (var i = 0; i < seuils.length; i ++) { |
div.innerHTML += |
'<div class="legend">'+ |
'<span style="background:' + getColor(seuils[i] + 1) + '"></span>'+ |
'<span style="background:' + genererCouleur(seuils[i] + 1) + '"></span>'+ |
seuils[i]+ (i + 1 < seuils.length ? '–' + seuils[i + 1] : '+')+ |
'</div>'; |
} |
458,12 → 648,156 |
} |
function masquerLegende() { |
map.removeControl(legende); |
legende = null; |
if (legende != null) { |
map.removeControl(legende); |
legende = null; |
} |
} |
function supprimerSourceDansMaille(maille, sourceSuppression) { |
if (typeof(maille.nombrePoints[sourceSuppression]) != 'undefined') { |
maille.nombrePoints[sourceSuppression] = 0; |
colorerMaille(maille); |
genererInfobulle(maille); |
} |
} |
function genererInfobulle(maille) { |
var nombrePoints = 0, |
nombreSources = 0; |
contenuTexte = ''; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints = maille.nombrePoints[sourceMaille]; |
if (nombrePoints > 0) { |
contenuTexte += (contenuTexte.length==0 ?'' : '\n')+ |
sourceMaille+' : '+maille.nombrePoints[sourceMaille]; |
} |
nombreSources ++; |
} |
if (nombreSources > 0) { |
$(maille._path).addClass('tooltip'); |
$(maille._path).attr('title',contenuTexte); |
} |
} |
// ==================================================================== |
// Gestion des marqueurs |
function ajouterPoint(feature) { |
var iconePoint = new L.Icon({ iconUrl : pointImageUrl, iconSize : [16, 16] }), |
iconeCommune = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }), |
icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune, |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]), |
marker = new L.Marker(point, { |
icon : icone, |
title : feature.properties.nom |
}) |
marker.typeSite = feature.properties.typeSite; |
marker.source = feature.properties.source; |
marker.on('click', surClicMarqueur); |
points.push(marker); |
if (formeDonnees != 'maille') { |
coucheSites.addLayer(marker); |
} else { |
ajouterPointDansMaille(marker); |
} |
} |
function ajouterPointDansMaille(point) { |
var maille = null; |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && layer.getBounds().contains(point.getLatLng())) { |
maille = layer; |
return; |
} |
}); |
if (typeof(maille.nombrePoints[point.source]) == 'undefined') { |
maille.nombrePoints[point.source] = 1; |
} else { |
maille.nombrePoints[point.source] += 1; |
} |
colorerMaille(maille); |
} |
function combinerMaillesEtPoints() { |
enleverMarqueursCarte(); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
var nombrePoints = compterNombrePointsDansMaille(layer); |
ajouterNombrePointsDansMaille(layer, nombrePoints); |
} |
}); |
} |
function determinerNombreMarqueurs(source) { |
var nombrePoints = 0; |
for (var index = 0; index < points.length; index ++) { |
if (points[index].source == source) { |
nombrePoints += 1; |
} |
} |
return nombrePoints; |
} |
function enleverMarqueursCarte() { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite != 'MAILLE') { |
coucheSites.removeLayer(layer); |
} |
}); |
} |
function compterNombrePointsDansMaille(maille) { |
var nombrePoints = {}; |
for (var index = 0; index < points.length; index ++) { |
if (maille.getBounds().contains(points[index].getLatLng())) { |
var source = points[index].source; |
if (typeof(nombrePoints[source]) == 'undefined') { |
nombrePoints[source] = 1; |
} else { |
nombrePoints[source] += 1; |
} |
} |
} |
return nombrePoints; |
} |
function ajouterNombrePointsDansMaille(maille, nombrePoints) { |
for (sourceDonnees in nombrePoints) { |
if (typeof(maille.nombrePoints[sourceDonnees]) == 'undefined') { |
maille.nombrePoints[sourceDonnees] = nombrePoints[sourceDonnees]; |
} else { |
maille.nombrePoints[sourceDonnees] += nombrePoints[sourceDonnees]; |
} |
} |
colorerMaille(maille); |
} |
function supprimerPointsListe(sourceDonnees) { |
var index = 0; |
while (index < points.length) { |
if (points[index].source == sourceDonnees) { |
points.splice(index, 1); |
} else { |
index ++; |
} |
} |
} |
function transformerMaillesEnPoints(sourceDonnees) { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[sourceDonnees]) != 'undefined') { |
supprimerSourceDansMaille(layer, sourceDonnees); |
} |
}); |
for (var index = 0; index < points.length; index ++) { |
coucheSites.addLayer(points[index]); |
} |
} |
function surClicMarqueur(event) { |
var latitude = event.target.getLatLng().lat; |
var longitude = event.target.getLatLng().lng; |
470,12 → 804,17 |
pointClique = event.target; |
afficherMessageChargement('observations'); |
var parametres = { |
"source" : source, |
"num_taxon" : num_taxon, |
"source" : pointClique.source, |
"num_taxon" : numTaxon, |
"referentiel" : referentiel, |
"auteur" : auteur, |
"nn" : nn, |
"type_site" : pointClique.typeSite, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"longitude" : longitude, |
"latitude" : latitude |
"latitude" : latitude, |
"nb_jours" : nbJours |
}; |
url = urlBase + "observations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesObservations; |
485,18 → 824,19 |
function traiterDonneesObservations() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
if (!retourRequeteOK()) { |
if (!estStatutRequeteOK()) { |
alert(texte); |
} else { |
obsJSON = eval("(function(){return " + texte + ";})()"); |
viderListeObservations(); |
if (obsJSON.total > 0) { |
doitRafraichirCarte = false; |
map.setView(new L.LatLng(pointClique.getLatLng().lat, pointClique.getLatLng().lng), map.getZoom()); |
afficherInfoBulle(); |
} else if (infoBulle != null) { |
masquerInfoBulle(); |
if (obsJSON != null) { |
viderListeObservations(); |
if (obsJSON.total > 0) { |
doitRafraichirCarte = false; |
map.setView(new L.LatLng(pointClique.getLatLng().lat, pointClique.getLatLng().lng), map.getZoom()); |
afficherInfoBulle(); |
} else if (infoBulle != null) { |
masquerInfoBulle(); |
} |
} |
} |
} |
506,8 → 846,10 |
} |
// ==================================================================== |
// Gestion de l'infobulle |
// Gestion de l'infobulle |
var obsJSON = null, |
pointClique = null, |
550,7 → 892,7 |
} |
function masquerInfoBulle() { |
if (map.hasLayer(infoBulle) && infoBulle != null) { |
if (infoBulle != null && map.hasLayer(infoBulle)) { |
map.removeLayer(infoBulle); |
} |
infoBulle = null; |
581,7 → 923,6 |
obsStation.push(obsJSON.observations[index]); |
} |
} |
// ajouter les observations dans le code HTML |
var obsPage = []; |
for (var index = 0; index < obsStation.length; index ++) { |
obsPage.push(obsStation[index]); |
619,12 → 960,10 |
} |
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) { |
// doit retourner false si le parsseur n'est pas autodétecté |
// doit retourner false si le parseur n'est pas autodétecté |
return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s); |
}, |
format: function(date) { |
633,7 → 972,6 |
// Remplace la date par un nombre de millisecondes pour trier numériquement |
return $.tablesorter.formatFloat(new Date(date).getTime()); |
}, |
// set type, either numeric or text |
type: 'numeric' |
}); |
$(element).tablesorter({ |
641,7 → 979,7 |
1: { |
sorter:'date_cel' |
} |
} |
} |
}); |
} |
652,6 → 990,6 |
function afficherTexteStationId() { |
var latitude = pointClique.getLatLng().lat; |
var longitude = pointClique.getLatLng().lng; |
var texteStationId = pointClique.options.type + ':' + latitude + '|' + longitude; |
var texteStationId = pointClique.typeSite+':'+latitude+'|'+longitude+', SOURCE:'+pointClique.source; |
$('#obs-station-id').text(texteStationId); |
} |
/trunk/widget/modules/carto/squelettes/scripts/L.KML.js |
---|
25,7 → 25,17 |
* |
*/ |
// Adaptation Alexandre GALIBERT : |
// - Define fill opacity for polygons at 0 for transparent rendering |
// - Disable creation of icons for KML elements |
// - Specific beahaviour to add an array of files by their urls. A variable will define |
// the status of the processing (BUSY or READY) and managed with a counter for the number |
// of files remaining to parse. Once all files parsed, the map zooms on KML spatial elements |
const KML_READY = 0; |
const KML_BUSY = 1; |
L.KML = L.FeatureGroup.extend({ |
options: { |
async: true |
34,6 → 44,8 |
initialize: function(kml, options) { |
L.Util.setOptions(this, options); |
this._kml = kml; |
this._status = KML_READY; |
this._onWaiting = 0; |
this._layers = {}; |
if (kml) { |
57,6 → 69,14 |
req.send(null); |
}, |
addKMLFiles: function(urlList, options, async) { |
this._status = KML_BUSY; |
this._onWaiting = urlList.length; |
for (var index = 0; index < urlList.length; index ++) { |
this.addKML(urlList[index], options, async); |
} |
}, |
addKML: function(url, options, async) { |
var _this = this; |
var cb = function(gpx, options) { _this._addKML(gpx, options) }; |
75,7 → 95,16 |
} |
this.latLngs = L.KML.getLatLngs(xml); |
this.fire("loaded"); |
this._onWaiting --; |
if (this._onWaiting == 0) { |
this._status = KML_READY; |
this._map.fitBounds(this.getBounds()); |
} |
}, |
getStatus: function() { |
return this._status; |
}, |
latLngs: [] |
}); |
137,14 → 166,15 |
options.color = "#" + value.substring(2, 8); |
} else if (key === 'width') { |
options.weight = value; |
} else if (key === 'Icon') { |
} /*else if (key === 'Icon') { |
ioptions = _parse(e); |
if (ioptions.href) { options.href = ioptions.href; } |
} else if (key === 'href') { |
}*/ else if (key === 'href') { |
options.href = value; |
} |
} |
} |
options.fillOpacity = 0; |
return options; |
} |
/trunk/widget/modules/carto/squelettes/css/carto.css |
---|
150,12 → 150,17 |
padding:0; |
margin:0; |
position:absolute; |
top:0; |
top:20px; |
left:0; |
width:100%; |
width:auto; |
height:35px; |
overflow:hidden; |
background-color:#4A4B4C; |
background-color:#DDDDDD; |
z-index : 3000; |
border-radius: 4px; |
border: 1px solid black; |
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05) inset; |
display: inline-block; |
} |
#zone-info { |
position:absolute; |
174,7 → 179,7 |
display:inline-block; |
margin:0; |
padding:0.2em; |
color:#CCCCCC; |
color:black; |
} |
#carte-titre {/*Hack CSS fonctionne seulement dans ie6, 7 & 8 */ |
display:inline !hackCssIe6Et7;/*Hack CSS pour ie6 & ie7 */ |
181,6 → 186,13 |
display /*\**/:inline\9;/*Hack CSS pour ie8 */ |
} |
#logo { |
position:absolute; |
z-index:3000; |
top:20px; |
left:45px; |
} |
/*+-----------------------------------------------------------------------------------------------------------------+*/ |
/* message de chargement de donnees */ |
#zone-chargement { |
477,7 → 489,7 |
line-height:18px; |
} |
.info h4 { |
font-size: 15px; |
font-size: 1.2em; |
margin: 0 0 5px; |
color: #555; |
} |
493,7 → 505,7 |
opacity: 0.7; |
} |
.nombre-sites { |
font-size:13px; |
font-size:0.75em; |
font-family:sans-serif; |
text-align:center; |
color:black; |
/trunk/widget/modules/carto/squelettes/carto.tpl.html |
---|
29,19 → 29,30 |
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script> |
<script type="text/javascript"> |
//<![CDATA[ |
var source = '<?= $source ?>', |
num_taxon = '<?= $num_taxon ?>', |
dept = '<?= $departement ?>', |
auteur = '<?= $auteur ?>', |
referentiel = '<?= $referentiel ?>', |
urlBase = '<?= $url_serivce_carto ?>/projets/', |
urlsLimitesCommunales = <?= $urlLimitesCommunales ?>, |
communeImageUrl = '<?= $communeImageUrl ?>', |
pointImageUrl = '<?= $pointImageUrl ?>', |
liensVersSources = '<?= $liensVersSources ?>'.split(','), |
titreLegende = '<?= $titreLegende ?>', |
sources = '<?= $sourcesDispo ?>'.split(','), |
nomSources = '<?= $nomSourcesDispo ?>'.split(','); |
var source = '<?= $source ?>'.split(','); |
var logo = '<?=$logo ?>'; |
var titreCarte = '<?= ($titre != null) ? addslashes($titre) : null; ?>'; |
var urlLogo = '<?= ($logo != null) ? "$logo" : null; ?>'; |
var urlSite = '<?= ($url_site != null) ? "$url_site" : null; ?>'; |
var nn = '<?= $nn ?>'; |
var numTaxon = '<?= $num_taxon ?>'; |
var dept = '<?= $departement ?>'; |
var auteur = '<?= $auteur ?>'; |
var referentiel = '<?= $referentiel ?>'; |
var dateDebut = '<?= $date_debut ?>'; |
var dateFin = '<?= $date_fin ?>'; |
var nbJours = '<?=$nb_jours ?>'; |
var urlBase = '<?= $url_serivce_carto ?>/projets/'; |
var urlsLimitesCommunales = <?= $urlLimitesCommunales ?>; |
var communeImageUrl = '<?= $communeImageUrl ?>'; |
var pointImageUrl = '<?= $pointImageUrl ?>'; |
var liensVersSources = '<?= $liensVersSources ?>'.split(','); |
var titreLegende = '<?= $titreLegende ?>'; |
var listeSources = '<?= $listeSources ?>'.split(','); |
var nomListeSources = '<?= $nomListeSources ?>'.split(','); |
const ZOOM_MAXIMUM_MAILLAGE = <?= $zoomMaximumMaillage ?>; |
const SEUIL_MAILLAGE = <?= $seuilMaillage ?>; |
//]]> |
</script> |
<script src="http://maps.google.com/maps/api/js?v=3.5&sensor=true&language=fr®ion=FR" type="text/javascript"></script> |
57,7 → 68,7 |
<!-- +-------------------------------------------------------------------------------------------+ --> |
<!-- Blocs chargés à la demande : par défaut avec un style display à none --> |
<!-- Squelette du message de chargement des observations --> |
<!-- Squelette du message de chargement des stations et observations --> |
<script id="tpl-chargement-stations" type="text/x-jquery-tmpl"> |
<div id="chargement-stations"> |
<img src="<?=$url_base?>modules/carto/squelettes/images/chargement.gif" alt="Chargement en cours..." /> |
64,8 → 75,6 |
<p>Chargement des stations en cours...</p> |
</div> |
</script> |
<!-- Squelette du message de chargement des observations --> |
<script id="tpl-chargement-observations" type="text/x-jquery-tmpl"> |
<div id="chargement-observations"> |
<img src="<?=$url_base?>modules/carto/squelettes/images/chargement.gif" alt="Chargement en cours..." /> |
73,6 → 82,27 |
</div> |
</script> |
<?php if($logo != null) : ?> |
<div id="logo"> |
<?php if($url_site != null) : ?> |
<a href="<?= $url_site; ?>" |
title="<?= $url_site; ?>" |
onclick="ouvrirNouvelleFenetre(this, event)"> |
<img height="60px" class="image-logo" src="<?= $logo ?>" alt="logo" /> |
</a> |
<?php else : ?> |
<img class="image-logo" src="<?= $logo ?>" alt="logo" /> |
<?php endif; ?> |
</div> |
<?php endif; ?> |
<?php if($titre !== "0" && $titre != null) : ?> |
<div id="zone-titre" class="element-overlay"> |
<h1 id="carte-titre"> |
<span id="carte-titre-infos"><?= htmlspecialchars($titre); ?></span> |
</h1> |
</div> |
<?php endif; ?> |
<!-- Squelette du contenu d'une info-bulle observation --> |
<script id="tpl-obs" type="text/x-jquery-tmpl"> |
<div id="info-bulle" style="width:{largeur}px;"> |
/trunk/widget/modules/carto/config.defaut.ini |
---|
4,11 → 4,15 |
pointImageUrl = "http://www.tela-botanica.org/commun/icones/carto/point2.png" |
sourcesDispo = "floradata,sophy" |
sourceParDefaut = "floradata" |
liensVersSources = "http://www.tela-botanica.org/appli:cel,http://sophy.u-3mrs.fr/" |
nomSourcesDispo = "Observations Floradata,Données Sophy" |
titreLegende = "Stations dans maille" |
liensVersSources = "http://www.tela-botanica.org/page:cel,http://sophy.u-3mrs.fr/" |
nomSourcesDispo = "Observations Flora Data,Données Sophy" |
titreLegende = "Nombre Stations par maille" |
; Chemin vers le dossier contenant les fichiers kmz des limites communales |
communesKmzChemin = "/home/telabotap/www/carto/kml/communes/,/home/telabotap/www/carto/kml/communes_incompletes/" |
; Template de l'url où charger les fichiers kml des limites communales. |
limitesCommunaleUrlTpl = "http://www.tela-botanica.org/carto/kml/%s/%s" |
;parametres lies a l'affichage des donnees sur la carte |
zoomMaximumMaillage = 13 |
seuilMaillage = 250 |