Rev 795 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.1.1 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2006 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-Fiche. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: effi_cel.action.php,v 1.9 2007-11-06 10:54:03 jp_milcent Exp $
/**
* Fichier d'action du module eFlore-Fiche : Cel
*
* Appel Carnet en ligne
*
*
*@package eFlore
*@subpackage ef_fiche
//Auteur original :
*@author David Delon <dd@clapas.net>
//Autres auteurs :
*@author aucun
*@copyright Tela-Botanica 2000-2006
*@version $Revision: 1.9 $ $Date: 2007-11-06 10:54:03 $
// +------------------------------------------------------------------------------------------------------+
*/
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
// TODO : CSS specifique (id)
class EfloreCartes {
private $tab_code_insee = array();
public $src_map;
private $cartesFormateur = null;
const MIME_MAP = 'text/html';
const MIME_PNG = 'image/png';
public function consulter($ressources, $param) {
// Initialisation des variables
$this->ressources = $ressources;
$this->param = $param;
if ($this->analyserRessources() == true) {
$resultat = $this->formerLegende();
} else {
$this->traiterParametres();
$resultat = $this->formerCarte();
}
return $resultat;
}
public function formerCarte() {
$this->creerFormateur();
$this->cartesFormateur->initialiserImage();
$inventories = '';
if ($this->cartesFormateur->testerParametresProjets() == true) {
$inventories = $this->cartesFormateur->chargerDonnees();
}
$retour = '';
if (is_array($inventories) && $inventories !== array()){
$this->chargerVille();// Connection referentiel communes
list($text, $merge) = $this->calculerRepartition($inventories);
// Définition des couleurs des points
$couleurs = $this->cartesFormateur->definirCouleurs();
if ($text) {
$usemap = $this->cartesFormateur->dessinerPoint($text, $merge, $couleurs);
}
if (isset($usemap)) {
$this->cartesFormateur->img();
$retour = $this->cartesFormateur->formaterCartes($usemap);
}
}
if ($retour == '') {
$retour = $this->formaterCarteVide();
}
$resultat = new ResultatService();
$resultat->corps = ($this->info['retour'] == self::MIME_MAP) ? $retour : file_get_contents($retour);
$resultat->mime = ($this->info['retour'] == self::MIME_MAP) ? self::MIME_MAP : self::MIME_PNG;
return $resultat;
}
public function creerFormateur(){
$projet = ucwords($this->info['projet']);
$Classe = $projet.'Formateur';
$chemin = dirname(__FILE__).DS.'cartes'.DS;
$cheminClasse = $chemin.$Classe.'.php';
$cheminInterface = $chemin.'Formateur.php';
if (file_exists($cheminInterface)) {
include_once $cheminInterface;
if (file_exists($cheminClasse)) {
include_once $cheminClasse;
$this->cartesFormateur = new $Classe($this->info);
} else {
$message = "La classe '$Classe' est introuvable.";Debug::printr($message);
throw new Exception($message);
}
}
}
private function analyserRessources() {
$ok = false;
if (isset($this->ressources[0]) && $this->ressources[0] == 'legende') {
$ok = true;
}
return $ok;
}
private function formerLegende() {
$classe = 'LegendeCartes';
require_once dirname(__FILE__).DS.'cartes'.DS.$classe.'.php';
$sousService = new $classe(new Conteneur());
$resultat = $sousService->consulter($this->ressources, $this->param);
return $resultat;
}
private function traiterParametres() {
$this->info['miniature'] = (isset($this->param['retour.format'])) ? $this->param['retour.format'] : false;
$this->info['src_map'] = ($this->info['miniature'] == 'min') ? 'france_utm_miniature.png' : 'france_utm_600x564.png';
$this->info['retour'] = (isset($this->param['retour'])) ? $this->param['retour'] : self::MIME_PNG ;
// Ajout du code du référentiel
$this->info['referentiel'] = 'bdtfx';
$projets = array('cenlr', 'cel', 'cbnmed', 'sophy', 'general');
if (isset($this->param['projet']) && in_array($this->param['projet'], $projets)) {
$this->info['projet'] = $this->param['projet'];
} else {
$this->info['projet'] = 'general';
}
// Récupération d'infos générales
// donnees exemple nn = 141; nt = 8522; nom = 'Acer campestre L.'; nom_ss_auteur = 'Acer campestre';
$this->info['nn'] = @$this->param['masque.nn'];
$this->info['nt'] = @$this->param['masque.nt'];
$this->info['nom'] = @$this->param['masque.ns'].' '.@$this->param['masque.au'];
$this->info['nom_ss_auteur'] = @$this->param['masque.ns'];
}
private function chargerVille() {
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector".
" FROM tb_cel.cel_zones_geo;";
$villes = $this->getBdd()->recupererTous($requete);
foreach ($villes as $ville) {
$this->tab_code_insee[$ville['insee_code']] = $ville;
}
}
private function calculerRepartition($inventories) {
$text = '';
// Recuperation du positionnement de la carte
$png_txt = file_get_contents(Config::get('Cartes.chemin').str_replace('png', 'txt', $this->info['src_map']));
parse_str($png_txt);
// "Resolution" calculer à partir du fichier $png_txt par fuseau
$p['31T'] = ($X231T - $X131T) / ($X231TUTM - $X131TUTM);
$p['32T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
$p['30T'] = ($X231T - $X131T ) / ($X231TUTM - $X131TUTM);
$text = array();
$merge = array();
foreach ($inventories as $inventory){
$utm = $this->cartesFormateur->chercherVille($inventory, $this->tab_code_insee);
// Ultime tentative
if (!$utm) {
$requete = "SELECT nom as name, code as insee_code, utm_x as x_utm, utm_y as y_utm, utm_secteur as sector".
" FROM tb_cel.cel_zones_geo WHERE nom LIKE ".$this->getBdd()->proteger($inventory['location']);
$utm = $this->getBdd()->recupererTous($requete);
}
// Si des doublons sur la commune : pas d'affichage , il vaut mieux ne rien afficher que d'afficher des erreurs.
if (sizeof($utm) == 1) {
$utm = $utm[0];
// On centre le point au milieu de la maille 10x10 par defaut ...
$utm = $this->chercherCentreMaille($utm);
// Calcul coordonnes x, y sur l'image
if ($utm['sector']=='31T') {// Fuseau 31 T
$x = (($utm['x_utm'] - $X131TUTM) * $p['31T'] ) + $X131T;
$y = $Y231T - (($utm['y_utm'] - $Y131TUTM) * $p['31T'] );
} elseif ($utm['sector'] == '32T') {// Fuseau 32 T : une rotation + translation est appliqu�e
$cosa = cos(deg2rad($angle3132));
$sina = sin(deg2rad($angle3132));
$xp = (($utm['x_utm'] - $X132TUTM) * $cosa) + (($utm['y_utm']- $Y132TUTM) * $sina);
$yp = (-($utm['x_utm'] - $X132TUTM)* $sina) + (($utm['y_utm'] - $Y132TUTM) * $cosa);
$x = ($xp * $p['32T'] ) + $X132T;
$y = $Y232T-($yp * $p['32T'] );
} elseif ($utm['sector'] == '30T') {// Fuseau 30 T : une rotation + translation est appliqu�e
$cosa = cos(deg2rad($angle3031));
$sina = sin(deg2rad($angle3031));
$xp = (($utm['x_utm'] - $X130TUTM) * $cosa) + (($utm['y_utm'] - $Y130TUTM) * $sina);
$yp = (-($utm['x_utm'] - $X130TUTM) * $sina) + (($utm['y_utm'] - $Y130TUTM) * $cosa);
$x = ($xp * $p['30T'] ) + $X130T;
$y = $Y230T - ($yp * $p['30T'] );
}
$x = round($x);
$y = round($y);
if ($utm['name'] != null) {
$name = utf8_decode($utm['name']);
}
$comment = ($this->info['retour'] == self::MIME_MAP) ? $this->cartesFormateur->formerCommentaire($utm, $inventory) : '';
// On stocke les commentaires pour affichage dans les tooltips
// Commentaire deja présent ? : on ajoute à la suite
list($text, $merge) = $this->cartesFormateur->stockerCommentaire($text, $merge, $name, $comment, $inventory['collection_code'],$x,$y);
}
}
return array($text, $merge);
}
private function formaterCarteVide() {
$this->cheminCartesBase = Config::get('Cartes.chemin');
$dest_map['vide'] = 'vide_'.$this->info['src_map'];
$img['vide'] = imagecreatefrompng($this->cheminCartesBase.$this->info['src_map']);
imagepng($img['vide'], Config::get('cache_stockageChemin').$dest_map['vide'], 9);
$retour = Config::get('cel_dst').$dest_map['vide'];
if ($this->info['retour'] == self::MIME_MAP) {
$retour = "<img src=\"".$retour."\" style=\"border:none; cursor:crosshair\" alt=\"\" />\n";
}
return $retour;
}
//+----------------------------------------------------------------------------------------------------------------+
// sous fonction de calculer répartition
private function chercherCentreMaille($utm) {
$pad = str_repeat ('0' ,(7 - strlen( $utm['x_utm'])));
$utm['x_utm'] = $pad.$utm['x_utm'];
$pad = str_repeat ('0' ,(7 - strlen( $utm['y_utm'])));
$utm['y_utm'] = $pad.$utm['y_utm'];
$utm['x_utm'] = substr($utm['x_utm'] ,0,3);
$utm['x_utm'] = $utm['x_utm'].'5000';
$utm['y_utm'] = substr($utm['y_utm'] ,0,3);
$utm['y_utm'] = $utm['y_utm'].'5000';
return $utm;
}
//+----------------------------------------------------------------------------------------------------------------+
// Méthodes d'accès aux objets du Framework
/**
* Méthode de connection à la base de données sur demande.
* Tous les services web n'ont pas besoin de s'y connecter.
*/
protected function getBdd() {
if (! isset($this->Bdd)) {
$this->Bdd = new Bdd();
}
return $this->Bdd;
}
}
?>