Subversion Repositories eFlore/Applications.cel

Rev

Rev 1004 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1004 Rev 1032
Line 1... Line 1...
1
<?php
1
<?php
2
class CartoGroupage {
2
class CartoGroupage {
Line 3... Line 3...
3
 
3
 
4
	private static $seuilClusterisation = 100;
4
	private static $seuilClusterisation = 200;
5
	private static $zoomDefaut = 3;
5
	private static $zoomDefaut = 3;
6
	private static $zoomMaxClustering = 12;
6
	private static $zoomMaxClustering = 12;
7
	private static $pasZoomDefaut = 1;
7
	private static $pasZoomDefaut = 1;
8
	private static $pasZoomMaxClustering = 0.05;
8
	private static $pasZoomMaxClustering = 0.05;
Line 33... Line 33...
33
	  Quatres cadrans sont considérés par le quad tree
33
	  Quatres cadrans sont considérés par le quad tree
34
	  * = centre de la fenetre
34
	  * = centre de la fenetre 
35
	 */
35
	 */
36
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
36
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
37
		if (count($markers) > self::$seuilClusterisation) {
37
		if(count($markers) > self::$seuilClusterisation) {
-
 
38
						
38
			self::calculerProfondeurMax($zoom);
39
			self::calculerProfondeurMax($zoom);
39
			self::calculerPasCorrectionCentre($zoom);
40
			self::calculerPasCorrectionCentre($zoom);
Line 40... Line 41...
40
 
41
 
41
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
42
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
42
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
-
 
Line -... Line 43...
-
 
43
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);	
43
		} else {
44
			
44
 
45
		} else {
45
			foreach($markers as $marker) {
46
			foreach($markers as $marker) {
46
				$points = array($marker);
47
				$points = array($marker);
47
				$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
48
				$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
Line 72... Line 73...
72
		return self::$coefficientProfondeurMax;
73
		return self::$coefficientProfondeurMax;
73
	}
74
	}
Line 74... Line 75...
74
 
75
	
75
	private function calculerProfondeurMax($zoom) {
76
	private function calculerProfondeurMax($zoom) {	
76
		if($zoom > self::$zoomDefaut) {
77
		if($zoom > self::$zoomDefaut) {	
77
			//self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
-
 
78
			self::$profondeurMax = $zoom-1;
78
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
79
		} else {
79
		} else {
80
			self::$profondeurMax = 1;
80
			self::$profondeurMax = 1;
81
		}
81
		}
Line 93... Line 93...
93
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
93
	 * @param float $swLat Latitude du coin sud ouest de la fenetre 
94
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
94
	 * @param float $swLng Longitude du coin sud ouest de la fenetre 
95
	 * @param int $profondeur profondeur courante de l'arbre
95
	 * @param int $profondeur profondeur courante de l'arbre
96
	 */
96
	 */
97
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
97
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
-
 
98
			
98
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
99
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
99
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
100
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
Line 100... Line 101...
100
 
101
						
101
		foreach ($noeud['points'] as &$point) {
102
		foreach ($noeud['points'] as &$point) {
102
				self::$nbElements['observations']++;
103
				self::$nbElements['observations']++;
103
				if (isset($point['type_emplacement'])) {
104
				$emplacement = isset($point['type_emplacement']) ? $point['type_emplacement'] : self::obtenirTypeEmplacementParId(&$point);
104
					self::$nbElements[$point['type_emplacement']]++;
-
 
105
				}
105
				self::$nbElements[$emplacement]++;
106
				unset($point['type_emplacement']);
106
				unset($point['type_emplacement']);
107
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
107
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
108
				self::ajouterFils($noeud,$cadran,$point);
108
				self::ajouterFils($noeud,$cadran,$point);
Line 109... Line 109...
109
		}
109
		}
Line 110... Line 110...
110
 
110
		
111
		$profondeur++;
111
		$profondeur++;
112
 
112
		
113
		if ($profondeur <= self::$profondeurMax) {
113
		if($profondeur <= self::$profondeurMax) {
114
			(isset($noeud['A'])) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
114
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
115
			(isset($noeud['B'])) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
115
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
Line 116... Line 116...
116
			(isset($noeud['C'])) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
116
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
117
			(isset($noeud['D'])) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
117
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
118
		}
118
		}
119
 
119
		
Line -... Line 120...
-
 
120
		if(self::estUnParentFeuilles($noeud)) {
-
 
121
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
-
 
122
		}
-
 
123
	}
-
 
124
	
-
 
125
	private static function obtenirTypeEmplacementParId($point) {
-
 
126
		$tableau_point_id = explode(':',$point['id'],2);
-
 
127
		switch($tableau_point_id[0]) {
-
 
128
			case 'STATION':
-
 
129
				$type_emplacement = 'stations';
-
 
130
			break;
-
 
131
			case 'COMMUNE':
-
 
132
				$type_emplacement = 'communes';
120
		if(self::estUnParentFeuilles($noeud)) {
133
			break;
121
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
134
		}
122
		}
135
		return $type_emplacement;
123
	}
136
	}
124
 
137
	
Line 138... Line 151...
138
		}
151
		}		
139
		return $cadran;
152
		return $cadran;
140
	}
153
	}
Line 141... Line 154...
141
 
154
	
142
	private static function ajouterFils(&$noeud, $cadran, &$point) {
-
 
143
		$fils = array('points' => array(), 'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
155
	private static function ajouterFils(&$noeud, $cadran, &$point) {
144
		if (isset($noeud[$cadran])) {
156
		if(!isset($noeud[$cadran])) {
145
			$fils = $noeud[$cadran];
157
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
146
		}
-
 
147
 
158
		}	
148
		$fils['points'][] = $point;
159
		$noeud[$cadran]['points'][] = $point;
149
		$fils['nbrePoints']++;
160
		$noeud[$cadran]['nbrePoints']++;
150
		$fils['latMoyenne'] += $point['lat'];
161
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
151
		$fils['lngMoyenne'] += $point['lng'];
-
 
152
		$noeud[$cadran] = $fils;
162
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
Line 153... Line 163...
153
	}
163
	}
154
 
164
	
155
	private static function ajouterGroupeOuPoint(&$noeud) {
165
	private static function ajouterGroupeOuPoint(&$noeud) {
Line 171... Line 181...
171
				self::estUneFeuille($noeud['C']) &&
181
				self::estUneFeuille($noeud['C']) && 
172
				self::estUneFeuille($noeud['D']);
182
				self::estUneFeuille($noeud['D']);
173
	}
183
	}
Line 174... Line 184...
174
 
184
	
-
 
185
	private static function estUneFeuille(&$noeud) {		
-
 
186
		return $noeud == null || 
175
	private static function estUneFeuille(&$noeud) {
187
		(!isset($noeud['A']) || $noeud['A'] == null) && 
-
 
188
		(!isset($noeud['B']) || $noeud['B'] == null) && 
-
 
189
		(!isset($noeud['C']) || $noeud['C'] == null) && 
176
		return $noeud == null || (!isset($noeud['A']) && !isset($noeud['B']) && !isset($noeud['C']) && !isset($noeud['D']));
190
		(!isset($noeud['D']) || $noeud['D'] == null);
177
	}
191
	}
178
}
192
}
179
?>
193
?>