Subversion Repositories eFlore/Applications.cel

Rev

Rev 2459 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2459 Rev 2460
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
-
 
3
/**
-
 
4
 * Classe de groupage des obs par quadtree pour la carto.
-
 
5
 *
-
 
6
 * @internal   Mininum PHP version : 5.2
-
 
7
 * @category   CEL
-
 
8
 * @package    Services
-
 
9
 * @subpackage Bibliothèques
-
 
10
 * @version    0.1
-
 
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
-
 
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
-
 
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
-
 
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
-
 
17
 */
2
class CartoGroupage {
18
class CartoGroupage {
3
	const MARQUEUR_GROUPE = 'GROUPE';
19
	const MARQUEUR_GROUPE = 'GROUPE';
4
	const MARQUEUR_COMMUNE = 'COMMUNE';
20
	const MARQUEUR_COMMUNE = 'COMMUNE';
5
	const MARQUEUR_STATION = 'STATION';
21
	const MARQUEUR_STATION = 'STATION';
6
 
22
 
7
	private static $seuilClusterisation = 200;
23
	private static $seuilClusterisation = 200;
8
	private static $zoomDefaut = 3;
24
	private static $zoomDefaut = 3;
9
	private static $zoomMaxClustering = 12;
25
	private static $zoomMaxClustering = 12;
10
	private static $pasZoomDefaut = 1;
26
	private static $pasZoomDefaut = 1;
11
	private static $pasZoomMaxClustering = 0.05;
27
	private static $pasZoomMaxClustering = 0.05;
12
	private static $profondeurMin = 0;
28
	private static $profondeurMin = 0;
13
	private static $profondeurMax = 8;
29
	private static $profondeurMax = 8;
14
 
30
 
15
	private static $pasCorrectionCentre = null;
31
	private static $pasCorrectionCentre = null;
16
	private static $coefficientReductionPas = null;
32
	private static $coefficientReductionPas = null;
17
	private static $coefficientProfondeurMax = null;
33
	private static $coefficientProfondeurMax = null;
18
 
34
 
19
	private static $nbElements = array('stations' => 0,'communes' => 0, 'points' => 0);
35
	private static $nbElements = array('stations' => 0,'communes' => 0, 'points' => 0);
20
	private static $listeNoeudsSelectionnes = array();
36
	private static $listeNoeudsSelectionnes = array();
21
	private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
37
	private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
22
	private static $id_traites = array();
38
	private static $id_traites = array();
23
	/*
39
	/*
24
	  +---------+---------+
40
	  +---------+---------+
25
	  |         |         |
41
	  |         |         |
26
	  |    A    |    B    |
42
	  |    A    |    B    |
27
	  |         |         |
43
	  |         |         |
28
	  +---------*---------+
44
	  +---------*---------+
29
	  |         |         |
45
	  |         |         |
30
	  |    D    |    C    |
46
	  |    D    |    C    |
31
	  |         |         |
47
	  |         |         |
32
	  +---------+---------+
48
	  +---------+---------+
33
 
49
 
34
	  Quatres cadrans sont considérés par le quad tree
50
	  Quatres cadrans sont considérés par le quad tree
35
	  * = centre de la fenetre
51
	  * = centre de la fenetre
36
	 */
52
	 */
37
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
53
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
38
		if (count($markers) > self::$seuilClusterisation) {
54
		if (count($markers) > self::$seuilClusterisation) {
39
 
-
 
40
			self::calculerProfondeurMax($zoom);
55
			self::calculerProfondeurMax($zoom);
41
			self::calculerPasCorrectionCentre($zoom);
56
			self::calculerPasCorrectionCentre($zoom);
42
 
57
 
43
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
58
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
44
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
59
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
45
 
-
 
46
		} else {
60
		} else {
47
			foreach($markers as &$marker) {
61
			foreach ($markers as &$marker) {
48
				if(!self::estUnPointAExclure($marker)) {
62
				if (!self::estUnPointAExclure($marker)) {
49
					$emplacement = self::formaterPointPourAjout($marker);
63
					$emplacement = self::formaterPointPourAjout($marker);
50
					self::mettreAJourBornes($marker);
64
					self::mettreAJourBornes($marker);
51
					$points = array($marker);
65
					$points = array($marker);
52
					$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
66
					$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
53
					self::$nbElements[$emplacement]++;
67
					self::$nbElements[$emplacement]++;
54
					self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
68
					self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
55
				}
69
				}
56
				self::$nbElements['points']++;
70
				self::$nbElements['points']++;
57
			}
71
			}
58
		}
72
		}
59
		return self::$listeNoeudsSelectionnes;
73
		return self::$listeNoeudsSelectionnes;
60
	}
74
	}
61
 
75
 
62
	private function calculerCoefficientReductionPas() {
76
	private function calculerCoefficientReductionPas() {
63
		if(self::$coefficientReductionPas == null) {
77
		if (self::$coefficientReductionPas == null) {
64
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
78
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
65
		}
79
		}
66
 
-
 
67
		return self::$coefficientReductionPas;
80
		return self::$coefficientReductionPas;
68
	}
81
	}
69
 
82
 
70
	private function calculerPasCorrectionCentre($zoom) {
83
	private function calculerPasCorrectionCentre($zoom) {
71
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
84
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
72
	}
85
	}
73
 
86
 
74
	private function calculerCoefficientProfondeurMax() {
87
	private function calculerCoefficientProfondeurMax() {
75
		if(self::$coefficientProfondeurMax == null) {
88
		if (self::$coefficientProfondeurMax == null) {
76
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
89
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
77
		}
90
		}
78
 
-
 
79
		return self::$coefficientProfondeurMax;
91
		return self::$coefficientProfondeurMax;
80
	}
92
	}
81
 
93
 
82
	private function calculerProfondeurMax($zoom) {
94
	private function calculerProfondeurMax($zoom) {
83
		if($zoom > self::$zoomDefaut) {
95
		if ($zoom > self::$zoomDefaut) {
84
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
96
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
85
		} else {
97
		} else {
86
			self::$profondeurMax = 1;
98
			self::$profondeurMax = 1;
87
		}
99
		}
88
	}
100
	}
89
 
101
 
90
	public static function getNbElements() {
102
	public static function getNbElements() {
91
		return self::$nbElements;
103
		return self::$nbElements;
92
	}
104
	}
93
 
105
 
94
	public static function mettreAJourBornes(&$point) {
106
	public static function mettreAJourBornes(&$point) {
95
		if (!is_numeric($point['lat']) || abs($point['lat']) > 90) return;
107
		if (!is_numeric($point['lat']) || abs($point['lat']) > 90) return;
96
		if (!is_numeric($point['lng']) || abs($point['lng']) > 180) return;
108
		if (!is_numeric($point['lng']) || abs($point['lng']) > 180) return;
97
 
109
 
98
		self::$bornesMax['latMin'] = ($point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
110
		self::$bornesMax['latMin'] = ($point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
99
		self::$bornesMax['lngMin'] = ($point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
111
		self::$bornesMax['lngMin'] = ($point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
100
		self::$bornesMax['latMax'] = ($point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
112
		self::$bornesMax['latMax'] = ($point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
101
		self::$bornesMax['lngMax'] = ($point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
113
		self::$bornesMax['lngMax'] = ($point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
102
	}
114
	}
103
 
115
 
104
	public static function getBornes() {
116
	public static function getBornes() {
105
		return self::$bornesMax;
117
		return self::$bornesMax;
106
	}
118
	}
107
 
119
 
108
	/**
120
	/**
109
	 *
121
	 *
110
	 * @param mixed $noeud Le noeud à traiter par le quadtree
122
	 * @param mixed $noeud Le noeud à traiter par le quadtree
111
	 * @param float $neLat Latitude du coin nord est de la fenetre
123
	 * @param float $neLat Latitude du coin nord est de la fenetre
112
	 * @param float $neLng Longitude du coin nord est de la fenetre
124
	 * @param float $neLng Longitude du coin nord est de la fenetre
113
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
125
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
114
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
126
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
115
	 * @param int $profondeur profondeur courante de l'arbre
127
	 * @param int $profondeur profondeur courante de l'arbre
116
	 */
128
	 */
117
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
129
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
118
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
130
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
119
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
131
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
120
 
132
 
121
		foreach ($noeud['points'] as &$point) {
133
		foreach ($noeud['points'] as &$point) {
122
			if(!self::estUnPointAExclure($point)) {
134
			if(!self::estUnPointAExclure($point)) {
123
				$emplacement = self::formaterPointPourAjout($point);
135
				$emplacement = self::formaterPointPourAjout($point);
124
				self::mettreAJourBornes($point);
136
				self::mettreAJourBornes($point);
125
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
137
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
126
				self::ajouterFils($noeud,$cadran,$point);
138
				self::ajouterFils($noeud,$cadran,$point);
127
				self::$nbElements[$emplacement]++;
139
				self::$nbElements[$emplacement]++;
128
			}
140
			}
129
			self::$nbElements['points']++;
141
			self::$nbElements['points']++;
130
		}
142
		}
131
 
143
 
132
		$profondeur++;
144
		$profondeur++;
133
 
145
 
134
		if($profondeur <= self::$profondeurMax) {
146
		if($profondeur <= self::$profondeurMax) {
135
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
147
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
136
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
148
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
137
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
149
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
138
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
150
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
139
		}
151
		}
140
 
152
 
141
		if(self::estUnParentFeuilles($noeud)) {
153
		if(self::estUnParentFeuilles($noeud)) {
142
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
154
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
143
		}
155
		}
144
	}
156
	}
145
 
157
 
146
	private static function estUnPointAExclure(&$point) {
158
	private static function estUnPointAExclure(&$point) {
147
		return self::estSensible($point) &&
159
		return self::estSensible($point) &&
148
		self::coordonneesCommuneSontNulles($point);
160
		self::coordonneesCommuneSontNulles($point);
149
	}
161
	}
150
 
162
 
151
	private static function coordonneesCommuneSontNulles(&$point) {
163
	private static function coordonneesCommuneSontNulles(&$point) {
152
		$coord_nulles = ($point['wgs84_latitude'] == null ||
164
		$coord_nulles = ($point['wgs84_latitude'] == null ||
153
		$point['wgs84_latitude'] == '' ||
165
		$point['wgs84_latitude'] == '' ||
154
		$point['wgs84_longitude'] == null ||
166
		$point['wgs84_longitude'] == null ||
155
		$point['wgs84_longitude'] == '');
167
		$point['wgs84_longitude'] == '');
156
		return $coord_nulles;
168
		return $coord_nulles;
157
	}
169
	}
158
 
170
 
159
	private static function coordonneesSontNulles(&$point) {
171
	private static function coordonneesSontNulles(&$point) {
160
		$coord_nulles = ($point['latitude'] == '000null' ||
172
		$coord_nulles = ($point['latitude'] == '000null' ||
161
				$point['latitude'] == 0 ||
173
			$point['latitude'] == 0 ||
162
				$point['latitude'] == '' ||
174
			$point['latitude'] == '' ||
163
				$point['longitude'] == '000null' ||
175
			$point['longitude'] == '000null' ||
164
				$point['longitude'] == 0 ||
176
			$point['longitude'] == 0 ||
165
				$point['longitude'] == '');
177
			$point['longitude'] == '');
166
		return $coord_nulles;
178
		return $coord_nulles;
167
	}
179
	}
168
 
180
 
169
	private static function estSensible(&$point) {
181
	private static function estSensible(&$point) {
170
		$sensible = isset($point['mots_cles_texte']) && substr_count(strtolower($point['mots_cles_texte']), 'sensible') != 0;
182
		$sensible = isset($point['mots_cles_texte']) && substr_count(strtolower($point['mots_cles_texte']), 'sensible') != 0;
171
		return $sensible;
183
		return $sensible;
172
	}
184
	}
173
 
185
 
174
	private static function formaterNomStation(&$point, $type_emplacement) {
186
	private static function formaterNomStation(&$point, $type_emplacement) {
175
		$station = '';
187
		$station = '';
176
		if($type_emplacement == 'stations' && $point['station'] != '' && $point['station'] != '000null') {
188
		if ($type_emplacement == 'stations' && $point['station'] != '' && $point['station'] != '000null') {
177
			$station = $point['station'];
189
			$station = $point['station'];
178
		} else {
190
		} else {
179
			$id_zone_geo = $point['ce_zone_geo'];
191
			$id_zone_geo = $point['ce_zone_geo'];
180
			$station = $point['zone_geo'].(($id_zone_geo != '' && $id_zone_geo != '000null') ? ' ('.self::formaterNomZoneGeo($id_zone_geo).')' : '');
192
			$station = $point['zone_geo'].(($id_zone_geo != '' && $id_zone_geo != '000null') ? ' ('.self::formaterNomZoneGeo($id_zone_geo).')' : '');
181
		}
193
		}
182
 
194
 
183
		return $station;
195
		return $station;
184
	}
196
	}
185
 
197
 
186
	private static function formaterNomZoneGeo($zone_geo) {
198
	private static function formaterNomZoneGeo($zone_geo) {
187
		$zone_geo = str_replace('INSEE-C:', '', $zone_geo);
199
		$zone_geo = str_replace('INSEE-C:', '', $zone_geo);
188
		$zone_geo = strlen($zone_geo) >= 2 ? substr($zone_geo, 0, 2) : $zone_geo;
200
		$zone_geo = strlen($zone_geo) >= 2 ? substr($zone_geo, 0, 2) : $zone_geo;
189
		return $zone_geo;
201
		return $zone_geo;
190
	}
202
	}
191
 
203
 
192
	private static function formaterPointPourAjout(&$point) {
204
	private static function formaterPointPourAjout(&$point) {
193
		if(isset($point['type_emplacement'])) {
205
		if (isset($point['type_emplacement'])) {
194
			return $point['type_emplacement'];
206
			return $point['type_emplacement'];
195
		}
207
		}
196
 
208
 
197
		if(self::coordonneesSontNulles($point) || self::estSensible($point)) {
209
		if (self::coordonneesSontNulles($point) || self::estSensible($point)) {
198
			$point_allege = array();
210
			$point_allege = array();
199
			$point_allege['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
211
			$point_allege['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
200
			$point_allege['type_emplacement'] = 'communes';
212
			$point_allege['type_emplacement'] = 'communes';
201
			$point_allege['nom'] = self::formaterNomStation($point, 'communes');
213
			$point_allege['nom'] = self::formaterNomStation($point, 'communes');
202
			$point_allege['lat'] = (float)$point['wgs84_latitude'];
214
			$point_allege['lat'] = (float)$point['wgs84_latitude'];
203
			$point_allege['lng'] = (float)$point['wgs84_longitude'];
215
			$point_allege['lng'] = (float)$point['wgs84_longitude'];
204
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
216
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
205
 
217
 
206
			$point = $point_allege;
218
			$point = $point_allege;
207
		} else {
219
		} else {
208
			$point_allege = array();
220
			$point_allege = array();
209
			$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['latitude'].'|'.$point['longitude'];
221
			$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['latitude'].'|'.$point['longitude'];
210
			$point_allege['type_emplacement'] = 'stations';
222
			$point_allege['type_emplacement'] = 'stations';
211
			$point_allege['nom'] = self::formaterNomStation($point, 'stations');
223
			$point_allege['nom'] = self::formaterNomStation($point, 'stations');
212
			$point_allege['lat'] = (float)$point['latitude'];
224
			$point_allege['lat'] = (float)$point['latitude'];
213
			$point_allege['lng'] = (float)$point['longitude'];
225
			$point_allege['lng'] = (float)$point['longitude'];
214
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
226
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
215
 
227
 
216
			$point = $point_allege;
228
			$point = $point_allege;
217
		}
229
		}
218
 
-
 
219
		return $point['type_emplacement'];
230
		return $point['type_emplacement'];
220
	}
231
	}
221
 
232
 
222
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
233
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
223
		if ($point['lng'] < $lngCentre) {
234
		if ($point['lng'] < $lngCentre) {
224
			if ($point['lat'] > $latCentre) {
235
			if ($point['lat'] > $latCentre) {
225
					$cadran = 'A';
236
					$cadran = 'A';
226
				} else {
237
				} else {
227
					$cadran = 'D';
238
					$cadran = 'D';
228
				}
239
				}
229
		} else {
240
		} else {
230
			if ($point['lat'] > $latCentre) {
241
			if ($point['lat'] > $latCentre) {
231
				$cadran = 'B';
242
				$cadran = 'B';
232
			} else {
243
			} else {
233
				$cadran = 'C';
244
				$cadran = 'C';
234
			}
245
			}
235
		}
246
		}
236
		return $cadran;
247
		return $cadran;
237
	}
248
	}
238
 
249
 
239
	private static function ajouterFils(&$noeud, $cadran, &$point) {
250
	private static function ajouterFils(&$noeud, $cadran, &$point) {
240
		if(!isset($noeud[$cadran])) {
251
		if(!isset($noeud[$cadran])) {
241
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
252
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
242
		}
253
		}
243
		$noeud[$cadran]['points'][] = $point;
254
		$noeud[$cadran]['points'][] = $point;
244
		$noeud[$cadran]['nbrePoints']++;
255
		$noeud[$cadran]['nbrePoints']++;
245
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
256
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
246
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
257
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
247
	}
258
	}
248
 
259
 
249
	private static function ajouterGroupeOuPoint(&$noeud) {
260
	private static function ajouterGroupeOuPoint(&$noeud) {
250
		$groupe = array();
261
		$groupe = array();
251
		if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
262
		if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
252
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
263
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
253
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
264
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
254
			$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
265
			$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
255
			$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
266
			$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
256
		} else {
267
		} else {
257
			$groupe = $noeud['points'][0];
268
			$groupe = $noeud['points'][0];
258
		}
269
		}
259
		return $groupe;
270
		return $groupe;
260
	}
271
	}
261
 
-
 
262
 
272
 
263
	private static function estUnParentFeuilles(&$noeud) {
273
	private static function estUnParentFeuilles(&$noeud) {
264
		return  self::estUneFeuille($noeud['A']) &&
274
		return  self::estUneFeuille($noeud['A']) &&
265
				self::estUneFeuille($noeud['B']) &&
275
				self::estUneFeuille($noeud['B']) &&
266
				self::estUneFeuille($noeud['C']) &&
276
				self::estUneFeuille($noeud['C']) &&
267
				self::estUneFeuille($noeud['D']);
277
				self::estUneFeuille($noeud['D']);
268
	}
278
	}
269
 
279
 
270
	private static function estUneFeuille(&$noeud) {
280
	private static function estUneFeuille(&$noeud) {
271
		return $noeud == null ||
281
		return $noeud == null ||
272
		(!isset($noeud['A']) || $noeud['A'] == null) &&
282
		(!isset($noeud['A']) || $noeud['A'] == null) &&
273
		(!isset($noeud['B']) || $noeud['B'] == null) &&
283
		(!isset($noeud['B']) || $noeud['B'] == null) &&
274
		(!isset($noeud['C']) || $noeud['C'] == null) &&
284
		(!isset($noeud['C']) || $noeud['C'] == null) &&
275
		(!isset($noeud['D']) || $noeud['D'] == null);
285
		(!isset($noeud['D']) || $noeud['D'] == null);
276
	}
286
	}
277
}
-
 
278
?>
-
 
279
287
}
-
 
288
280
289