Development

Changeset 17898

You must first sign up to be able to contribute.

Changeset 17898

Show
Ignore:
Timestamp:
05/03/09 18:19:40 (5 years ago)
Author:
fabriceb
Message:

[sfEasyGMapPlugin]
* Replaced the mass center calculation by a minimal enclosing bounds center... much more practical
* GMapCoord::distance() function to calculate very efficiently approximate distance between markers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfEasyGMapPlugin/trunk/lib/GMap.class.php

    r17896 r17898  
    666666  public function centerAndZoomOnMarkers($margin = 0) 
    667667  { 
     668    $this->centerOnMarkers(); 
    668669    $this->zoomOnMarkers($margin); 
    669     $this->centerOnMarkers(); 
    670670  } 
    671671 
  • plugins/sfEasyGMapPlugin/trunk/lib/GMapBounds.class.php

    r17896 r17898  
    155155  } 
    156156   
     157   /** 
     158   * Get the coordinates of the center of the zone 
     159   * 
     160   * @return GMapCoord 
     161   * @author fabriceb 
     162   * @since 2008-12-03  
     163   */ 
     164  public function getCenterCoord() 
     165  { 
     166   
     167    return new GMapCoord($this->getCenterLat(), $this->getCenterLng()); 
     168  } 
     169   
    157170  /** 
    158171   * Hauteur du carrĂ© 
  • plugins/sfEasyGMapPlugin/trunk/lib/GMapCoord.class.php

    r17896 r17898  
    178178   * @since 2009-05-02 
    179179   */ 
    180   public static function getCenterCoord($coords)   
     180  public static function getMassCenterCoord($coords)   
    181181  { 
    182182    if (count($coords)==0) 
     
    195195   
    196196    return new GMapCoord($center_lat/count($coords),$center_lng/count($coords)); 
     197  } 
     198   
     199  /** 
     200   * Calculates the center of an array of coordiantes 
     201   *  
     202   * @param GMapCoord[] $coords 
     203   * @return GMapCoord 
     204   * @author fabriceb 
     205   * @since 2009-05-02 
     206   */ 
     207  public static function getCenterCoord($coords)   
     208  { 
     209    $bounds = GMapBounds::getBoundsContainingCoords($coords); 
     210   
     211    return $bounds->getCenterCoord(); 
    197212  } 
    198213   
  • plugins/sfEasyGMapPlugin/trunk/lib/GMapMarker.class.php

    r17896 r17898  
    218218  * 
    219219  **/ 
    220   public static function getCenterCoord($markers) 
     220  public static function getMassCenterCoord($markers) 
    221221  { 
    222222    $coords = array(); 
     
    226226    } 
    227227    
    228     return GMapCoord::getCenterCoord($coords); 
     228    return GMapCoord::getMassCenterCoord($coords); 
     229  } 
     230   
     231  /** 
     232  * 
     233  * @param GMapMarker[] $markers array of MArkers 
     234  * @return GMapCoord 
     235  * @author fabriceb 
     236  * @since 2009-05-02 
     237  * 
     238  **/ 
     239  public static function getCenterCoord($markers) 
     240  { 
     241    $bounds = GMapBounds::getBoundsContainingMarkers($markers); 
     242   
     243    return $bounds->getCenterCoord(); 
    229244  } 
    230245   
  • plugins/sfEasyGMapPlugin/trunk/modules/sfEasyGMapPlugin/actions/actions.class.php

    r16301 r17898  
    127127  } 
    128128   
     129  /** 
     130   * Here we learn to: 
     131   *  - adapt the map to the current markers using complex but hidden formulas :-) 
     132   */ 
     133  public function executeSample4() 
     134  { 
     135    $this->gMap = new GMap(); 
     136    $this->gMap->setWidth(512); 
     137    $this->gMap->setHeight(400); 
     138 
     139    $this->gMap->addMarker( 
     140      new GMapMarker(51.245475,6.821373) 
     141    ); 
     142    $this->gMap->addMarker( 
     143      new GMapMarker(46.262248,6.115969) 
     144    ); 
     145    $this->gMap->addMarker( 
     146      new GMapMarker(48.848959,2.341577) 
     147    ); 
     148    $this->gMap->addMarker( 
     149      new GMapMarker(48.718952,2.219180) 
     150    ); 
     151    $this->gMap->addMarker( 
     152      new GMapMarker(47.376420,8.547995) 
     153    ); 
     154    $this->gMap->centerAndZoomOnMarkers(0.3); 
     155 
     156    $this->setTemplate('sample1'); 
     157  } 
     158   
    129159} 
  • plugins/sfEasyGMapPlugin/trunk/modules/sfEasyGMapPlugin/templates/sample1Success.php

    r11741 r17898  
    22 
    33<h1>The Map</h1> 
    4 <?php include_map($gMap,array('width'=>'512px','height'=>'400px')); ?> 
     4<?php include_map($gMap); ?> 
    55 
    66Search on the map: 
  • plugins/sfEasyGMapPlugin/trunk/package.xml

    r17896 r17898  
    7878         <file role="data" name="GMapBoundsTest.php" /> 
    7979     <file role="data" name="GMapCoordTest.php" /> 
     80     <file role="data" name="GMapTest.php" /> 
    8081       </dir>     
    8182     </dir> 
  • plugins/sfEasyGMapPlugin/trunk/test/unit/GMapTest.php

    r17896 r17898  
    4545$t->diag('->getMarkersCenterCoord test'); 
    4646 
    47 $t->is($gMap->getMarkersCenterCoord()->__toString(),'48.4904108, 5.2092188','The center of our markers is ok'); 
     47$t->is($gMap->getMarkersCenterCoord()->__toString(),'48.7538615, 5.3835875','The center of our markers is ok'); 
    4848$gMap->centerOnMarkers(); 
    49 $t->is($gMap->getCenterCoord()->__toString(),'48.4904108, 5.2092188','The center of the map is ok'); 
     49$t->is($gMap->getCenterCoord()->__toString(),'48.7538615, 5.3835875','The center of the map is ok'); 
    5050 
    5151$t->diag('->getMarkersFittingZoom test'); 
     
    5656 
    5757$gMap->centerAndZoomOnMarkers(); 
    58 $t->is($gMap->getCenterCoord()->__toString(),'48.4904108, 5.2092188','The center of the map is ok'); 
     58$t->is($gMap->getCenterCoord()->__toString(),'48.7538615, 5.3835875','The center of the map is ok'); 
    5959$t->is($gMap->getZoom(),7,'The zoom of the map is ok'); 
    6060