Merged in feature/MAPG-44-possibility-to-add-pov-data-to-locations (pull request #169)

Feature/MAPG-44 possibility to add pov data to locations
This commit is contained in:
Bence Pőcze 2020-07-03 23:12:56 +00:00
commit 43aef22c4e
6 changed files with 149 additions and 14 deletions

View File

@ -0,0 +1,8 @@
ALTER TABLE
`places`
ADD
`pov_heading` decimal(6, 3) NOT NULL DEFAULT 0.0,
ADD
`pov_pitch` decimal(5, 3) NOT NULL DEFAULT 0.0,
ADD
`pov_zoom` decimal(5, 4) NOT NULL DEFAULT 0.0;

View File

@ -8,6 +8,7 @@
rounds: [],
scoreSum: 0,
panoId: null,
pov: null,
panorama: null,
map: null,
guessMarker: null,
@ -35,6 +36,7 @@
}
Game.panoId = this.response.panoId;
Game.pov = this.response.pov;
if (this.response.history) {
for (var i = 0; i < this.response.history.length; ++i) {
@ -116,7 +118,7 @@
document.getElementById('currentRound').innerHTML = String(Game.rounds.length) + '/' + String(Game.NUMBER_OF_ROUNDS);
Game.loadPano(Game.panoId);
Game.loadPano(Game.panoId, Game.pov);
},
handleErrorResponse: function (error) {
@ -129,13 +131,13 @@
});
},
loadPano: function (panoId) {
loadPano: function (panoId, pov) {
if (Game.adaptGuess) {
document.getElementById('guess').classList.add('adapt');
}
Game.panorama.setPov({ heading: 0, pitch: 0 });
Game.panorama.setZoom(0);
Game.panorama.setPov({ heading: pov.heading, pitch: pov.pitch });
Game.panorama.setZoom(pov.zoom);
Game.panorama.setPano(panoId);
},
@ -199,6 +201,7 @@
}
Game.panoId = this.response.panoId;
Game.pov = this.response.pov;
}, data);
},

View File

@ -41,7 +41,10 @@ class GameFlowController
$session->set('state', $state);
$data = ['panoId' => $place->getPanoIdCached()];
$data = [
'panoId' => $place->getPanoIdCached(),
'pov' => $place->getPov()->toArray()
];
} else {
$rounds = count($state['rounds']);
$last = $state['rounds'][$rounds - 1];
@ -59,7 +62,10 @@ class GameFlowController
$data = [
'history' => $history,
'panoId' => $last['panoId']
'panoId' => $last['panoId'],
'pov' => isset($last['pov']) ? // should be checked not to break with old sessions
$last['pov']->toArray() :
['heading' => 0.0, 'pitch' => 0.0, 'zoom' => 0.0],
];
}
@ -103,10 +109,12 @@ class GameFlowController
$this->addNewRoundToState($state, $place, $placesWithoutPano);
$panoId = $place->getPanoIdCached();
$pov = $place->getPov()->toArray();
} else {
$state['rounds'] = [];
$panoId = null;
$pov = null;
}
$session->set('state', $state);
@ -117,7 +125,8 @@ class GameFlowController
'distance' => $distance,
'score' => $score
],
'panoId' => $panoId
'panoId' => $panoId,
'pov' => $pov
];
return new JsonContent($data);
}
@ -128,7 +137,8 @@ class GameFlowController
'placesWithoutPano' => $placesWithoutPano,
'placeId' => $place->getId(),
'position' => $place->getPosition(),
'panoId' => $place->getPanoIdCached()
'panoId' => $place->getPanoIdCached(),
'pov' => $place->getPov()
];
}

View File

@ -16,6 +16,7 @@ use MapGuesser\Response\HtmlContent;
use MapGuesser\Response\JsonContent;
use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Util\Geo\Position;
use MapGuesser\Util\Panorama\Pov;
class MapAdminController implements ISecured
{
@ -94,6 +95,11 @@ class MapAdminController implements ISecured
$place->setMap($map);
$place->setLat((float) $placeRaw['lat']);
$place->setLng((float) $placeRaw['lng']);
$place->setPov(new Pov(
(float) $placeRaw['pov']['heading'],
(float) $placeRaw['pov']['pitch'],
(float) $placeRaw['pov']['zoom']
));
if ($placeRaw['panoId'] === -1) {
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
@ -114,6 +120,11 @@ class MapAdminController implements ISecured
$place = $this->placeRepository->getById((int) $placeRaw['id']);
$place->setLat((float) $placeRaw['lat']);
$place->setLng((float) $placeRaw['lng']);
$place->setPov(new Pov(
(float) $placeRaw['pov']['heading'],
(float) $placeRaw['pov']['pitch'],
(float) $placeRaw['pov']['zoom']
));
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
$this->pdm->saveToDb($place);
@ -150,7 +161,8 @@ class MapAdminController implements ISecured
return new JsonContent($data);
}
public function deleteMap() {
public function deleteMap()
{
$mapId = (int) $this->request->query('mapId');
$map = $this->mapRepository->getById($mapId);
@ -206,7 +218,7 @@ class MapAdminController implements ISecured
{
//TODO: from repository or relations
$select = new Select(\Container::$dbConnection, 'places');
$select->columns(['id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp']);
$select->columns(['id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp', 'pov_heading', 'pov_pitch', 'pov_zoom']);
$select->where('map_id', '=', $map->getId());
$result = $select->execute();
@ -214,8 +226,6 @@ class MapAdminController implements ISecured
$places = [];
while ($place = $result->fetch(IResultSet::FETCH_ASSOC)) {
//$panoId = ???
//$pov = ???
$noPano = $place['pano_id_cached_timestamp'] && $place['pano_id_cached'] === null;
$places[$place['id']] = [
@ -223,7 +233,11 @@ class MapAdminController implements ISecured
'lat' => $place['lat'],
'lng' => $place['lng'],
'panoId' => null,
'pov' => ['heading' => 0.0, 'pitch' => 0.0, 'zoom' => 0.0],
'pov' => [
'heading' => (float) $place['pov_heading'],
'pitch' => (float) $place['pov_pitch'],
'zoom' => (float) $place['pov_zoom']
],
'noPano' => $noPano
];
}

View File

@ -5,12 +5,13 @@ use DateTime;
use MapGuesser\Http\Request;
use MapGuesser\PersistentData\PersistentDataManager;
use MapGuesser\Util\Geo\Position;
use MapGuesser\Util\Panorama\Pov;
class Place extends Model
{
protected static string $table = 'places';
protected static array $fields = ['map_id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp'];
protected static array $fields = ['map_id', 'lat', 'lng', 'pano_id_cached', 'pano_id_cached_timestamp', 'pov_heading', 'pov_pitch', 'pov_zoom'];
protected static array $relations = ['map' => Map::class];
@ -24,9 +25,12 @@ class Place extends Model
private ?DateTime $panoIdCachedTimestamp = null;
private Pov $pov;
public function __construct()
{
$this->position = new Position(0.0, 0.0);
$this->pov = new Pov(0.0, 0.0, 0.0);
}
public function setMap(Map $map): void
@ -54,6 +58,26 @@ class Place extends Model
$this->position->setLng($lng);
}
public function setPov(Pov $pov): void
{
$this->pov = $pov;
}
public function setPovHeading(float $heading): void
{
$this->pov->setHeading($heading);
}
public function setPovPitch(float $pitch): void
{
$this->pov->setPitch($pitch);
}
public function setPovZoom(float $zoom): void
{
$this->pov->setZoom($zoom);
}
public function setPanoIdCached(?string $panoIdCached): void
{
$this->panoIdCached = $panoIdCached;
@ -96,6 +120,26 @@ class Place extends Model
return $this->position->getLng();
}
public function getPov(): Pov
{
return $this->pov;
}
public function getPovHeading(): float
{
return $this->pov->getHeading();
}
public function getPovPitch(): float
{
return $this->pov->getPitch();
}
public function getPovZoom(): float
{
return $this->pov->getZoom();
}
public function getFreshPanoId(bool $canBeIndoor = false): ?string
{
if (

56
src/Util/Panorama/Pov.php Normal file
View File

@ -0,0 +1,56 @@
<?php namespace MapGuesser\Util\Panorama;
class Pov
{
private float $heading;
private float $pitch;
private float $zoom;
public function __construct(float $heading, float $pitch, float $zoom)
{
$this->heading = $heading;
$this->pitch = $pitch;
$this->zoom = $zoom;
}
public function setHeading(float $heading): void
{
$this->heading = $heading;
}
public function setPitch(float $pitch): void
{
$this->pitch = $pitch;
}
public function setZoom(float $zoom): void
{
$this->zoom = $zoom;
}
public function getHeading(): float
{
return $this->heading;
}
public function getPitch(): float
{
return $this->pitch;
}
public function getZoom(): float
{
return $this->zoom;
}
public function toArray(): array
{
return [
'heading' => $this->heading,
'pitch' => $this->pitch,
'zoom' => $this->zoom
];
}
}