Changeset 12719 for extensions/rv_gmaps/trunk/include/cluster_maker.php
- Timestamp:
- Dec 11, 2011, 8:55:04 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_gmaps/trunk/include/cluster_maker.php
r3447 r12719 3 3 function cluster_area_compare( &$a, &$b ) 4 4 { 5 $aa = bounds_lat_range($a ['bounds']) * bounds_lon_range($a['bounds']);6 $ab = bounds_lat_range($b ['bounds']) * bounds_lon_range($b['bounds']);5 $aa = bounds_lat_range($a->bounds) * bounds_lon_range($a->bounds); 6 $ab = bounds_lat_range($b->bounds) * bounds_lon_range($b->bounds); 7 7 return -$aa+$ab; // biggest first 8 } 9 10 final class Cluster 11 { 12 public $bounds; 13 public $items; 14 15 function __construct($b = array(), $i = array()) 16 { 17 $this->bounds = $b; 18 $this->items = $i; 19 } 8 20 } 9 21 … … 30 42 $this->bounds = bounds_add($this->bounds, $img['lat'], $img['lon'] ); 31 43 32 $pending_split = array( 33 array( 34 'bounds' => $this->bounds, 35 'items' => array_keys( $this->_image_map ), 36 ) 37 ); 44 $pending_split = array( new Cluster($this->bounds, array_keys($this->_image_map) ) ); 38 45 $result = array(); 39 46 … … 51 58 foreach( $splitted as $k => $split ) 52 59 echo("sub $k: " . var_export($split['bounds'],true)."\n" );*/ 53 $total_iterations += count($current ['items']);60 $total_iterations += count($current->items); 54 61 $next_level_to_split = array_merge($next_level_to_split, $splitted ); 55 62 if ( count($result)+count($pending_split)+count($next_level_to_split) >= $maxNbMarkers ) … … 66 73 usort( $pending_split, 'cluster_area_compare' ); 67 74 } 75 68 76 $merged = $this->_try_merge_clusters( $result, $maxLatPrecision, $maxLonPrecision ); 69 77 $this->debug_str = get_elapsed_time($start, get_moment()) .' gen:'.$total_generations.' alg:'.count($this->_image_map).'+'.$total_iterations; … … 79 87 for ($i=0; $i<count($clusters)-1; $i++) 80 88 { 81 $ci = bounds_center( $clusters[$i] ['bounds']);89 $ci = bounds_center( $clusters[$i]->bounds ); 82 90 for ($j=$i+1; $j<count($clusters); $j++) 83 91 { 84 $cj = bounds_center( $clusters[$j]['bounds'] ); 85 if ( abs($ci['lat']-$cj['lat']) < $maxLatPrecision/2 86 and abs($ci['lon']-$cj['lon']) < $maxLonPrecision/2 ) 92 $cj = bounds_center( $clusters[$j]->bounds ); 93 $rlat = abs($ci['lat']-$cj['lat']) / $maxLatPrecision; 94 $rlon = abs($ci['lon']-$cj['lon']) / $maxLonPrecision; 95 if ( $rlat<1 && $rlon<1 96 && $rlat+$rlon<1.1) 87 97 { 88 98 //print_r( "i=$i; j=$j \n"); var_export( $clusters[$i]['bounds'] ); var_export( $clusters[$j]['bounds'] ); 89 $clusters[$i] ['items'] = array_merge( $clusters[$i]['items'], $clusters[$j]['items']);99 $clusters[$i]->items = array_merge( $clusters[$i]->items, $clusters[$j]->items ); 90 100 if ( empty($this->_image_ranks) ) 91 101 $this->_image_ranks = array_flip( array_keys($this->_image_map) ); 92 usort( $clusters[$i] ['items'], array($this, '_image_rank_compare') );93 $clusters[$i] ['bounds'] = bounds_union($clusters[$i]['bounds'], $clusters[$j]['bounds']);102 usort( $clusters[$i]->items, array($this, '_image_rank_compare') ); 103 $clusters[$i]->bounds = bounds_union($clusters[$i]->bounds, $clusters[$j]->bounds ); 94 104 array_splice( $clusters, $j, 1); 95 105 $j--; 96 $ci = bounds_center( $clusters[$i] ['bounds']);106 $ci = bounds_center( $clusters[$i]->bounds ); 97 107 $ret++; 98 108 } … … 109 119 function _split_cluster($cluster, $maxLatPrecision, $maxLonPrecision) 110 120 { 111 $latRange = bounds_lat_range($cluster ['bounds']);112 $lonRange = bounds_lon_range($cluster ['bounds']);121 $latRange = bounds_lat_range($cluster->bounds); 122 $lonRange = bounds_lon_range($cluster->bounds); 113 123 114 124 $lat_nb_tiles = max( 1, $latRange/$maxLatPrecision ); … … 146 156 } 147 157 148 if ( $cluster ['bounds']['count'] > 200 )158 if ( $cluster->bounds['count'] > 200 ) 149 159 { 150 160 if ($lat_step>4*$maxLatPrecision) $lat_step = $lat_step/2; … … 159 169 160 170 $clusters = array(); 161 foreach ( $cluster ['items']as $id )171 foreach ( $cluster->items as $id ) 162 172 { 163 173 $lon = $this->_image_map[$id]['lon']; 164 174 $lat = $this->_image_map[$id]['lat']; 165 175 166 $idx_lon = floor ( ( $lon - $cluster ['bounds']['w'] ) / $lon_step );167 $idx_lat = floor ( ( $lat - $cluster ['bounds']['s'] ) / $lat_step );176 $idx_lon = floor ( ( $lon - $cluster->bounds['w'] ) / $lon_step ); 177 $idx_lat = floor ( ( $lat - $cluster->bounds['s'] ) / $lat_step ); 168 178 169 179 $idx = $lon_nb_tiles * $idx_lat + $idx_lon; … … 171 181 if ( !isset($clusters[$idx]) ) 172 182 { 173 $clusters[$idx] = array( 174 'bounds' => array(), 175 'items' => array(), 176 ); 183 $clusters[$idx] = new Cluster(); 177 184 } 178 array_push( $clusters[$idx] ['items'], $id );179 $clusters[$idx] ['bounds'] = bounds_add( $clusters[$idx]['bounds'], $lat, $lon );185 array_push( $clusters[$idx]->items, $id ); 186 $clusters[$idx]->bounds = bounds_add( $clusters[$idx]->bounds , $lat, $lon ); 180 187 } 181 188 return $clusters;
Note: See TracChangeset
for help on using the changeset viewer.