Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 727 Rev 747
Line 1... Line 1...
1
<?php
1
<?php
Line -... Line 2...
-
 
2
 
-
 
3
/**
-
 
4
 * Classe qui genere la carte SVG pour les parametres de la requete qui a ete utilisee pour appeler
-
 
5
 * le web service
-
 
6
 *
-
 
7
 * @package framework-0.4
-
 
8
 * @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org>
-
 
9
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
-
 
10
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
11
 * @version $Id$
-
 
12
 * @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
-
 
13
 *
-
 
14
 */
-
 
15
 
2
 
16
 
Line 3... Line 17...
3
class FormateurSVG {
17
class FormateurSVG {
4
	
18
	
5
	private $documentXML;
19
	private $documentXML;
Line 27... Line 41...
27
	}
41
	}
Line 28... Line 42...
28
	
42
	
29
	private function chargerSVG($nomFichierSVG) {
43
	private function chargerSVG($nomFichierSVG) {
30
		$this->documentXML = new DOMDocument("1.0", "UTF-8");
44
		$this->documentXML = new DOMDocument("1.0", "UTF-8");
31
		$this->documentXML->load($nomFichierSVG);
-
 
32
		$this->supprimerNoeudsInutiles($this->documentXML->documentElement);
-
 
33
	}
-
 
34
	
-
 
35
	private function supprimerNoeudsInutiles(& $noeud) {
-
 
36
		$index = 0;
-
 
37
		while ($index < $noeud->childNodes->length) {
-
 
38
			if (get_class($noeud->childNodes->item($index)) != 'DOMElement') {
-
 
39
				$noeud->removeChild($noeud->childNodes->item($index));
-
 
40
			} else {
-
 
41
				$fils = $noeud->childNodes->item($index);
-
 
42
				$this->supprimerNoeudsInutiles($fils);
-
 
43
				$index ++;
-
 
44
			}
-
 
45
		}
45
		$this->documentXML->load($nomFichierSVG);
Line 46... Line 46...
46
	}
46
	}
47
	
47
	
48
	private function chargerCoordonnees() {
48
	private function chargerCoordonnees() {
Line 115... Line 115...
115
	
115
	
116
	
116
	
-
 
117
 
117
 
118
	public function formaterCarte($taxon) {
118
	public function formaterCarte($taxon) {
119
		$limitesCarte = $this->renvoyerLimitesCarte();
119
		$limitesCarte = $this->renvoyerLimitesCarte();
-
 
120
		foreach ($this->sources as $source) {
120
		$sourceDonnees = new SourceDonnees($limitesCarte, $taxon);
121
			$nomClasse = $source == 'floradata' ? 'DonneesFloradata' : 'DonneesMoissonnage';
121
		foreach ($this->sources as $source) {
122
			$rechercheBdd = new $nomClasse($limitesCarte, $taxon, $source);
122
			$nomMethode = "recupererStations".($source == 'floradata' ? 'Floradata' : 'Moissonnage');
123
			$stations = $rechercheBdd->recupererStations();
123
			$stations = $sourceDonnees->$nomMethode($source);
124
			$this->ajouterStations($stations, $source);
124
			$this->ajouterStations($stations, $source);
Line 145... Line 145...
145
	private function ajouterStations($stations, $source) {
145
	private function ajouterStations($stations, $source) {
146
		$grille = $this->recupererNoeuds('grille')->childNodes;
146
		$grille = $this->recupererNoeuds('grille')->childNodes;
147
		$index = 0;
147
		$index = 0;
148
		$maille = $grille->item($index);
148
		$maille = $grille->item($index);
149
		foreach ($stations as $station) {
149
		foreach ($stations as $station) {
-
 
150
			if (!isset($station['lat']) || !isset($station['lng']) || !isset($station['commune'])) {
-
 
151
				continue;
-
 
152
			}
150
			$idMaille = $maille->attributes->getNamedItem('id')->value;
153
			$idMaille = $maille->attributes->getNamedItem('id')->value;
151
			$bbox = explode('_', substr($idMaille, 5));
154
			$bbox = explode('_', substr($idMaille, 5));
152
			$bbox[0] = floatval($bbox[0]);
155
			$bbox[0] = floatval($bbox[0]);
153
			$bbox[1] = floatval($bbox[1]);
156
			$bbox[1] = floatval($bbox[1]);
154
			while ($index < $grille->length && (
157
			while ($index < $grille->length && (
Line 159... Line 162...
159
				$bbox = explode('_', substr($idMaille, 5));
162
				$bbox = explode('_', substr($idMaille, 5));
160
				$bbox[0] = floatval($bbox[0]);
163
				$bbox[0] = floatval($bbox[0]);
161
				$bbox[1] = floatval($bbox[1]);
164
				$bbox[1] = floatval($bbox[1]);
162
			}
165
			}
163
			if ($bbox[1] == $station['lat'] && $bbox[0] == $station['lng']) {
166
			if ($bbox[1] == $station['lat'] && $bbox[0] == $station['lng']) {
164
				$this->genererTitreMaille($station['nb_observations'], $source, $maille);
167
				$this->ajouterCommentaire($station, $source, $maille);
165
				$this->appliquerStyleMaille($source, $maille);
168
				$this->appliquerStyleMaille($source, $maille);
166
				$maille = $grille->item($index ++);
-
 
167
			}
169
			}
168
			if ($index == $grille->length) {
170
			if ($index == $grille->length) {
169
				break;
171
				break;
170
			}
172
			}
171
		}
173
		}
Line 182... Line 184...
182
			}
184
			}
183
		}
185
		}
184
	}
186
	}
Line 185... Line 187...
185
	
187
	
-
 
188
	private function appliquerStyleMaille($source, & $maille) {
186
	private function appliquerStyleMaille($source, & $maille) {
189
		if ($maille->hasAttribute('class') && $maille->attributes->getNamedItem('class')->value != $source) {
-
 
190
			$maille->setAttribute('class', 'tout');
187
		$style = $maille->hasAttribute('class') ? 'tout' : $source;
191
		} elseif (!$maille->hasAttribute('class')) {
-
 
192
			$maille->setAttribute('class', $source);
188
		$maille->setAttribute('class', $style);
193
		}
Line 189... Line 194...
189
	}
194
	}
190
	
195
	
191
	private function genererTitreMaille($observations, $source, & $maille) {
196
	private function ajouterCommentaire($station, $source, & $maille) {
192
		$texte = '';
197
		$commentaires = array();
-
 
198
		if ($maille->hasAttribute('title')) {
-
 
199
			$commentaires = explode("; ", $maille->attributes->getNamedItem('title')->value);
-
 
200
		}
-
 
201
		$commentaire = ucfirst($source)." : {$station['commune']}, ";
193
		if ($maille->hasAttribute('title')) {
202
		if (strlen($station['date']) == 4) {
-
 
203
			$commentaire .= "en {$station['date']} par {$station['auteur']}";
194
			$texte = $maille->attributes->getNamedItem('title')->value."\n$source : $observations observations";
204
		} else {
195
		} else {
205
			$date = preg_replace("/(\d{4})-(\d{2})-(\d{2})/", "$3/$2/$1", $station['date']);
-
 
206
			$commentaire .= "le {$date} par {$station['auteur']}";
196
			$texte = "$source : $observations observations";
207
		}
197
		}
208
		$commentaires[] = trim($commentaire);
Line 198... Line 209...
198
		$maille->setAttribute('title', $texte);
209
		$maille->setAttribute('title', implode('; ', $commentaires));