Exemplo n.º 1
0
//$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))');
$t->is($bounds_world->getZoom(256),0,'Pour voir le monde sur une largeur/hauteur de 256 pix, il faut un zoom 0');
Exemplo n.º 2
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));
  }
Exemplo n.º 3
0
/**
 * Teste la sauvegarde d'équipes dans le backend
 * @author fabriceb
 * @since Feb 16, 2009 fabriceb
 */
include dirname(__FILE__) . '/../bootstrap/unit.php';
//$app='frontend';
//include(dirname(__FILE__).'/../bootstrap/functional.php');
$t = new lime_test(293, new lime_output_color());
$t->diag('GMapCoords Tests');
for ($zoom = 0; $zoom < 15; $zoom += 3) {
    for ($lat = 90; $lat >= -90; $lat -= 10) {
        $t->is(GMapCoord::fromPixToLat(GMapCoord::fromLatToPix($lat, $zoom), $zoom), (double) $lat, 'les projections mercator sur les latitudes marchent');
    }
    for ($lng = -180; $lng <= 180; $lng += 10) {
        $t->is(GMapCoord::fromPixToLng(GMapCoord::fromLngToPix($lng, $zoom), $zoom), (double) $lng, 'les projections mercator sur les longitudes marchent');
    }
}
$lat = 0;
$lng = 0;
$zoom = 0;
$pix = GMapCoord::fromLatToPix($lat, $zoom);
$t->is($pix, 128, 'Latitude 0 is at the middle of the map for zoom 0');
$pix = GMapCoord::fromLngToPix($lng, $zoom);
$t->is($pix, 128, 'Longitude 0 is at the middle of the map for zoom 0');
$lat = 0;
$lng = -180;
$zoom = 12;
$pix = GMapCoord::fromLatToPix($lat, $zoom);
$t->is($pix, 256 * pow(2, $zoom - 1), 'Latitude 0 is at the middle of the map whatever the zoom');
$pix = GMapCoord::fromLngToPix($lng, $zoom);