Merged in feature/MAPG-15-use-map-bounds-from-the-database (pull request #2)
feature/MAPG-15-use-map-bounds-from-the-database
This commit is contained in:
commit
55b693df68
@ -15,20 +15,19 @@ class GuessController extends BaseController
|
|||||||
// demo map
|
// demo map
|
||||||
$mapId = 1;
|
$mapId = 1;
|
||||||
|
|
||||||
|
$stmt = $mysql->prepare('SELECT bound_south_lat, bound_west_lng, bound_north_lat, bound_east_lng FROM maps WHERE id=?');
|
||||||
|
$stmt->bind_param("i", $mapId);
|
||||||
|
$stmt->execute();
|
||||||
|
$map = $stmt->get_result()->fetch_assoc();
|
||||||
|
|
||||||
// using RAND() for the time being, could be changed in the future
|
// using RAND() for the time being, could be changed in the future
|
||||||
$stmt = $mysql->prepare('SELECT lat, lng FROM places WHERE map_id=? ORDER BY RAND() LIMIT 1');
|
$stmt = $mysql->prepare('SELECT lat, lng FROM places WHERE map_id=? ORDER BY RAND() LIMIT 1');
|
||||||
$stmt->bind_param("i", $mapId);
|
$stmt->bind_param("i", $mapId);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
$place = $stmt->get_result()->fetch_assoc();
|
||||||
|
|
||||||
$result = $stmt->get_result();
|
$realPosition = new Position($place['lat'], $place['lng']);
|
||||||
$row = $result->fetch_assoc();
|
$bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']);
|
||||||
|
|
||||||
$realPosition = new Position($row['lat'], $row['lng']);
|
|
||||||
|
|
||||||
// demo bounds
|
|
||||||
$bounds = new Bounds($realPosition);
|
|
||||||
$bounds->extend(new Position(48.07683,7.35758));
|
|
||||||
$bounds->extend(new Position(47.57496, 19.08077));
|
|
||||||
|
|
||||||
$this->variables = compact('realPosition', 'bounds');
|
$this->variables = compact('realPosition', 'bounds');
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,27 @@ class Bounds
|
|||||||
|
|
||||||
private bool $initialized = false;
|
private bool $initialized = false;
|
||||||
|
|
||||||
public function __construct(Position $position = null)
|
public static function createWithPosition(Position $position) : Bounds
|
||||||
{
|
{
|
||||||
if ($position === null) {
|
$instance = new static();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->initialize($position);
|
$instance->initialize($position);
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createDirectly(float $southLat, $westLng, $northLat, $eastLng) : Bounds
|
||||||
|
{
|
||||||
|
$instance = new static();
|
||||||
|
|
||||||
|
$instance->southLat = $southLat;
|
||||||
|
$instance->westLng = $westLng;
|
||||||
|
$instance->northLat = $northLat;
|
||||||
|
$instance->eastLng = $eastLng;
|
||||||
|
|
||||||
|
$instance->initialized = true;
|
||||||
|
|
||||||
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function extend(Position $position): void
|
public function extend(Position $position): void
|
||||||
|
Loading…
Reference in New Issue
Block a user