Example #1
0
 /**
  * Calculate the box variables by the given size and center
  *
  * @param \Imagine\Image\Box $size
  * @param Point $center
  * @return array
  */
 public static function calculateBox(Box $size, Point $center)
 {
     $max_height_count = ceil($size->getHeight() / self::TILE_SIZE);
     $max_width_count = ceil($size->getWidth() / self::TILE_SIZE);
     $tile_height_start = floor($center->getY() / self::TILE_SIZE) - floor($max_height_count / 2);
     $tile_width_start = floor($center->getX() / self::TILE_SIZE) - floor($max_width_count / 2);
     $tile_height_stop = $tile_height_start + $max_height_count + 2;
     $tile_width_stop = $tile_width_start + $max_width_count + 2;
     $upper_y = $center->getY() - floor($size->getHeight() / 2) - $tile_height_start * self::TILE_SIZE;
     $upper_x = $center->getX() - floor($size->getWidth() / 2) - $tile_width_start * self::TILE_SIZE;
     return array('tiles' => ['start' => new Point($tile_width_start, $tile_height_start), 'stop' => new Point($tile_width_stop, $tile_height_stop)], 'crop' => new Point(round($upper_x + self::TILE_SIZE), round($upper_y + self::TILE_SIZE)), 'base' => new Box(($max_width_count + 2) * self::TILE_SIZE, ($max_height_count + 2) * self::TILE_SIZE));
 }
Example #2
0
 /**
  * Calculate the position of the blip on the map image.
  *
  * @param Point   $center Point on the image.
  * @param Box     $size   Size of the image.
  * @param integer $zoom   Zoom level of the map.
  *
  * @return Point
  */
 public function calculatePosition(Point $center, Box $size, $zoom)
 {
     $topLeft = new Point($center->getX() - $size->getWidth() / 2, $center->getY() - $size->getHeight() / 2);
     $blipPoint = Geo::calculatePoint($this->latLng, $zoom);
     return new Point($blipPoint->getX() - $topLeft->getX() - $this->imageSize[0] / 2, $blipPoint->getY() - $topLeft->getY() - $this->imageSize[1] / 2);
 }