Example #1
0
  /**
   * Calculate the bounds corresponding to a specific center and zoom level for a give map size in pixels
   * 
   * @param GMapCoord $center_coord
   * @param integer $zoom
   * @param integer $width
   * @param integer $height
   * @return GMapBounds
   * @author fabriceb
   * @since Jun 2, 2009 fabriceb
   */
  public static function getBoundsFromCenterAndZoom(GMapCoord $center_coord, $zoom, $width, $height = null)
  {
    if (is_null($height))
    {
      $height = $width;
    }
    
    $center_lat = $center_coord->getLatitude();
    $center_lng = $center_coord->getLongitude();

    $pix = GMapCoord::fromLatToPix($center_lat, $zoom);
    $ne_lat = GMapCoord::fromPixToLat($pix - round(($height-1) / 2), $zoom);
    $sw_lat = GMapCoord::fromPixToLat($pix + round(($height-1) / 2), $zoom);
    
    $pix = GMapCoord::fromLngToPix($center_lng, $zoom);
    $sw_lng = GMapCoord::fromPixToLng($pix - round(($width-1) / 2), $zoom);
    $ne_lng = GMapCoord::fromPixToLng($pix + round(($width-1) / 2), $zoom);

    return new GMapBounds(new GMapCoord($sw_lat, $sw_lng), new GMapCoord($ne_lat, $ne_lng));
  }
Example #2
0
 */
include(dirname(__FILE__).'/../bootstrap/unit.php');
//$app='frontend';
//include(dirname(__FILE__).'/../bootstrap/functional.php');



$lat = 48.856536;
$lng =  2.339307;
$zoom = 11;

$pix = GMapCoord::fromLatToPix($lat, $zoom);
$ne_lat = GMapCoord::fromPixToLat($pix - 150, $zoom);
$sw_lat = GMapCoord::fromPixToLat($pix + 150, $zoom);

$pix = GMapCoord::fromLngToPix($lng, $zoom);
$sw_lng = GMapCoord::fromPixToLng($pix - 150, $zoom);
$ne_lng = GMapCoord::fromPixToLng($pix + 150, $zoom);

$bounds = new GMapBounds(new GMapCoord($sw_lat,$sw_lng),new GMapCoord($ne_lat,$ne_lng));

$t = new lime_test(15, new lime_output_color());

$t->diag('GMapBounds test');

$t->diag('->__toString Test');
$t->is($bounds->__toString(),'((48.7887237041, 2.23631017383), (48.9242565582, 2.44230382617))','On a déduit correctement les bounds à partir de la largeur de la carte, le centre et le zoom');

$t->diag('->getZoom Test');

$bounds_world = GMapBounds::createFromString('((-90, -180), (90, 180))');