Changeset 1236 for g-map/files/lib/data/gmap/GmapCluster.class.php
- Timestamp:
- 10/09/10 19:41:52 (3 years ago)
- Files:
-
- 1 modified
-
g-map/files/lib/data/gmap/GmapCluster.class.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
g-map/files/lib/data/gmap/GmapCluster.class.php
r1226 r1236 48 48 * @return object Google_Maps_Coordinate 49 49 */ 50 protected function getCluster(array $markers ) {50 protected function getCluster(array $markers, $return_ids = false) { 51 51 $count = count($markers); 52 $ids = array(); 52 53 53 54 /* Calculate average lat and lon of markers. */ … … 56 57 $lat_sum += $marker['lat']; 57 58 $lon_sum += $marker['lon']; 59 if($return_ids) { 60 $ids[] = $marker['id']; 61 } 58 62 } 59 63 $lat_avg = $lat_sum / $count; 60 64 $lon_avg = $lon_sum / $count; 61 65 62 returnarray(66 $data = array( 63 67 'count' => $count, 64 68 'lat' => $lat_avg, 65 69 'lon' => $lon_avg 66 70 ); 71 if(count($ids)) { 72 $data['ids'] = $ids; 73 } 74 75 return $data; 67 76 } 68 77 … … 71 80 * @param $markers Array of lat and lon locations. 72 81 */ 73 public function getMarkers(array $markers ) {82 public function getMarkers(array $markers, $pick = array()) { 74 83 $clustered = array(); 75 84 … … 102 111 return $clustered; 103 112 } 113 114 /** 115 * 116 * @param $markers Array of lat and lon locations. 117 */ 118 public function getIDs(array $markers, $lat, $lon) { 119 120 /* Loop until all markers have been compared. */ 121 while (count($markers)) { 122 $marker = array_pop($markers); 123 $cluster = array(); 124 125 /* Compare against all markers which are left. */ 126 foreach ($markers as $key => $target) { 127 $pixels = $this->pixelDistance($marker['lat'], $marker['lon'], $target['lat'], $target['lon'], $this->zoom); 128 129 /* If two markers are closer than given distance remove */ 130 /* target marker from array and add it to cluster. */ 131 if ($this->distance > $pixels) { 132 unset($markers[$key]); 133 $cluster[] = $target; 134 } 135 } 136 137 /* If a marker has been added to cluster, add also the one */ 138 /* we were comparing to and remove the original from array. */ 139 if (count($cluster) > 0) { 140 $cluster[] = $marker; 141 $cluster = $this->getCluster($cluster, true); 142 if(abs($cluster['lat'] - $lat) < 0.000000001 && abs($cluster['lon'] - $lon) < 0.000000001) { 143 return $cluster['ids']; 144 } 145 } else { 146 if(abs($marker['lat'] - $lat) < 0.000000001 && abs($marker['lon'] - $lon) < 0.000000001) { 147 return array($marker['id']); 148 } 149 } 150 } 151 return null; 152 } 104 153 }
