Show
Ignore:
Timestamp:
10/09/10 19:41:52 (3 years ago)
Author:
d0nut
Message:

may finish gmap 2.0.0 RC 3

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • g-map/files/lib/data/gmap/GmapCluster.class.php

    r1226 r1236  
    4848         * @return   object Google_Maps_Coordinate 
    4949         */ 
    50         protected function getCluster(array $markers) { 
     50        protected function getCluster(array $markers, $return_ids = false) { 
    5151                $count = count($markers); 
     52                $ids = array(); 
    5253 
    5354                /* Calculate average lat and lon of markers. */ 
     
    5657                   $lat_sum += $marker['lat']; 
    5758                   $lon_sum += $marker['lon']; 
     59                   if($return_ids) { 
     60                        $ids[] = $marker['id']; 
     61                   } 
    5862                } 
    5963                $lat_avg = $lat_sum / $count; 
    6064                $lon_avg = $lon_sum / $count; 
    6165                 
    62                 return array( 
     66                $data = array( 
    6367                        'count' => $count, 
    6468                        'lat' => $lat_avg, 
    6569                        'lon' => $lon_avg 
    6670                ); 
     71                if(count($ids)) { 
     72                        $data['ids'] = $ids; 
     73                } 
     74                 
     75                return $data; 
    6776        } 
    6877 
     
    7180         * @param       $markers        Array of lat and lon locations. 
    7281         */ 
    73         public function getMarkers(array $markers) { 
     82        public function getMarkers(array $markers, $pick = array()) { 
    7483                $clustered = array(); 
    7584 
     
    102111                return $clustered; 
    103112        } 
     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        } 
    104153}