Example #1
0
 /**
  * Calculate the bounds corresponding to a specific center and zoom level for a give map size in pixels
  * 
  * @param EGMapCoord $center_coord
  * @param integer $zoom
  * @param integer $width
  * @param integer $height
  * @return EGMapBounds
  * @author fabriceb
  * @since Jun 2, 2009 fabriceb
  */
 public static function getBoundsFromCenterAndZoom(EGMapCoord $center_coord, $zoom, $width, $height = null)
 {
     if (is_null($height)) {
         $height = $width;
     }
     $center_lat = $center_coord->getLatitude();
     $center_lng = $center_coord->getLongitude();
     $pix = EGMapCoord::fromLatToPix($center_lat, $zoom);
     $ne_lat = EGMapCoord::fromPixToLat($pix - round(($height - 1) / 2), $zoom);
     $sw_lat = EGMapCoord::fromPixToLat($pix + round(($height - 1) / 2), $zoom);
     $pix = EGMapCoord::fromLngToPix($center_lng, $zoom);
     $sw_lng = EGMapCoord::fromPixToLng($pix - round(($width - 1) / 2), $zoom);
     $ne_lng = EGMapCoord::fromPixToLng($pix + round(($width - 1) / 2), $zoom);
     return new EGMapBounds(new EGMapCoord($sw_lat, $sw_lng), new EGMapCoord($ne_lat, $ne_lng));
 }