GeoJSON zrušen, geo ukládáme do DB.
parent
d21657c594
commit
e20e0d45b1
|
|
@ -6,7 +6,7 @@ namespace App\Model;
|
||||||
|
|
||||||
use Nette;
|
use Nette;
|
||||||
use Nette\Database\Explorer;
|
use Nette\Database\Explorer;
|
||||||
use Nette\Database\Row;
|
use Nette\Database\Row;
|
||||||
use Nette\Security\User;
|
use Nette\Security\User;
|
||||||
use Nette\Utils\DateTime;
|
use Nette\Utils\DateTime;
|
||||||
|
|
||||||
|
|
@ -15,6 +15,9 @@ use Nette\Utils\DateTime;
|
||||||
*/
|
*/
|
||||||
final class ObvodFacade
|
final class ObvodFacade
|
||||||
{
|
{
|
||||||
|
/** Sloupce bez GEO, aby seznam obvodů nenačítal hranice. */
|
||||||
|
private const SLOUPCE = 'ID, NAZEV, CISLO, SKUPINA, AKTIVNI';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private Explorer $database,
|
private Explorer $database,
|
||||||
private User $user,
|
private User $user,
|
||||||
|
|
@ -28,9 +31,9 @@ final class ObvodFacade
|
||||||
*/
|
*/
|
||||||
public function getObvod(int $id): Row|null
|
public function getObvod(int $id): Row|null
|
||||||
{
|
{
|
||||||
$sql = "SELECT *
|
$sql = 'SELECT ' . self::SLOUPCE . '
|
||||||
FROM OBVOD
|
FROM OBVOD
|
||||||
WHERE OBVOD.ID = ?";
|
WHERE OBVOD.ID = ?';
|
||||||
return $this->database->fetch($sql, $id);
|
return $this->database->fetch($sql, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,11 +46,11 @@ final class ObvodFacade
|
||||||
public function getObvody(?string $skupina = null): array
|
public function getObvody(?string $skupina = null): array
|
||||||
{
|
{
|
||||||
if ($skupina === null || $skupina === '') {
|
if ($skupina === null || $skupina === '') {
|
||||||
return $this->database->fetchAll('SELECT * FROM OBVOD ORDER BY CISLO');
|
return $this->database->fetchAll('SELECT ' . self::SLOUPCE . ' FROM OBVOD ORDER BY CISLO');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->database->fetchAll(
|
return $this->database->fetchAll(
|
||||||
'SELECT * FROM OBVOD WHERE SKUPINA = ? ORDER BY CISLO',
|
'SELECT ' . self::SLOUPCE . ' FROM OBVOD WHERE SKUPINA = ? ORDER BY CISLO',
|
||||||
$skupina,
|
$skupina,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -102,4 +105,29 @@ final class ObvodFacade
|
||||||
return $skupiny[0] ?? '';
|
return $skupiny[0] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hranice obvodů jako GeoJSON FeatureCollection.
|
||||||
|
* GEO v databázi je GeoJSON geometrie (Polygon nebo MultiPolygon).
|
||||||
|
*/
|
||||||
|
public function getGeoJson(): string
|
||||||
|
{
|
||||||
|
$radky = $this->database->fetchAll(
|
||||||
|
"SELECT CISLO, GEO
|
||||||
|
FROM OBVOD
|
||||||
|
WHERE GEO IS NOT NULL AND LTRIM(RTRIM(GEO)) <> ''
|
||||||
|
ORDER BY CISLO",
|
||||||
|
);
|
||||||
|
|
||||||
|
$features = [];
|
||||||
|
foreach ($radky as $radek) {
|
||||||
|
$features[] = '{"type":"Feature","properties":{"number":'
|
||||||
|
. (int) $radek->CISLO
|
||||||
|
. '},"geometry":'
|
||||||
|
. $radek->GEO
|
||||||
|
. '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '{"type":"FeatureCollection","features":[' . implode(',', $features) . ']}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,14 +5,13 @@ declare(strict_types=1);
|
||||||
namespace App\Presentation\Home;
|
namespace App\Presentation\Home;
|
||||||
|
|
||||||
use App\Core\Konstanty;
|
use App\Core\Konstanty;
|
||||||
|
use App\Model\ObvodFacade;
|
||||||
use Nette;
|
use Nette;
|
||||||
use Nette\Utils\Json;
|
|
||||||
use Nette\Utils\FileSystem;
|
|
||||||
|
|
||||||
final class HomePresenter extends Nette\Application\UI\Presenter
|
final class HomePresenter extends Nette\Application\UI\Presenter
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private ObvodFacade $obvody,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,28 +23,11 @@ final class HomePresenter extends Nette\Application\UI\Presenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderDefault(int $obvod = null): void
|
public function renderDefault(): void
|
||||||
{
|
{
|
||||||
try {
|
$this->template->obvody = array_map(
|
||||||
// načti seznam obvodů:
|
static fn($obvod): int => (int) $obvod->CISLO,
|
||||||
$content = FileSystem::read('../www/data/geo-obvody.geojson');
|
$this->obvody->getObvody(),
|
||||||
// dekóduj geo-json:
|
);
|
||||||
$geoObvody = Json::decode($content, true);
|
|
||||||
} catch (Nette\Utils\JsonException $e) {
|
|
||||||
// Ošetření výjimky
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($geoObvody))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$obvody = array();
|
|
||||||
foreach ($geoObvody["features"] as $o) {
|
|
||||||
$obvody[] = $o["properties"]["number"];
|
|
||||||
}
|
|
||||||
asort($obvody);
|
|
||||||
$this->template->obvody = $obvody;
|
|
||||||
|
|
||||||
bdump($geoObvody["features"]);
|
|
||||||
bdump($obvody);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ declare(strict_types=1);
|
||||||
namespace App\Presentation\Mapa;
|
namespace App\Presentation\Mapa;
|
||||||
|
|
||||||
use App\Core\Konstanty;
|
use App\Core\Konstanty;
|
||||||
|
use App\Model\ObvodFacade;
|
||||||
use App\Model\ZaznamFacade;
|
use App\Model\ZaznamFacade;
|
||||||
use Nette;
|
use Nette;
|
||||||
|
use Nette\Application\Responses\TextResponse;
|
||||||
use Nette\Utils\Json;
|
use Nette\Utils\Json;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,6 +22,7 @@ final class MapaPresenter extends Nette\Application\UI\Presenter
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ZaznamFacade $zaznam,
|
private ZaznamFacade $zaznam,
|
||||||
|
private ObvodFacade $obvod,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,6 +34,12 @@ final class MapaPresenter extends Nette\Application\UI\Presenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionGeojson(): void
|
||||||
|
{
|
||||||
|
$this->getHttpResponse()->setContentType('application/json', 'utf-8');
|
||||||
|
$this->sendResponse(new TextResponse($this->obvod->getGeoJson()));
|
||||||
|
}
|
||||||
|
|
||||||
public function actionDefault(?int $obvod = null, ?string $filtr = null): void
|
public function actionDefault(?int $obvod = null, ?string $filtr = null): void
|
||||||
{
|
{
|
||||||
if (!$this->getUser()->isLoggedIn() && $filtr !== null && $filtr !== 'obvody') {
|
if (!$this->getUser()->isLoggedIn() && $filtr !== null && $filtr !== 'obvody') {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{block content}
|
{block content}
|
||||||
<div id="map"
|
<div id="map"
|
||||||
data-geojson="{$basePath}/data/geo-obvody.geojson"
|
data-geojson="{link geojson}"
|
||||||
data-max="{$maxMesicu}"
|
data-max="{$maxMesicu}"
|
||||||
data-prideleni="{$maxPrideleni}"
|
data-prideleni="{$maxPrideleni}"
|
||||||
data-filtr="{$filtr}"
|
data-filtr="{$filtr}"
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<h2>Náhled</h2>
|
<h2>Náhled</h2>
|
||||||
<div id="obvod-nahled"
|
<div id="obvod-nahled"
|
||||||
data-obvod="{$obvod->CISLO}"
|
data-obvod="{$obvod->CISLO}"
|
||||||
data-geojson="{$basePath}/data/geo-obvody.geojson"></div>
|
data-geojson="{link :Mapa:geojson}"></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="panel detail-zaznamy">
|
<section class="panel detail-zaznamy">
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{block title}Stáří obvodů{/block}
|
{block title}Stáří obvodů{/block}
|
||||||
|
|
||||||
{block content}
|
{block content}
|
||||||
<div id="map" data-geojson="{$basePath}/data/geo-obvody.geojson" data-max="{$maxMesicu}"></div>
|
<div id="map" data-geojson="{link :Mapa:geojson}" data-max="{$maxMesicu}"></div>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.css" />
|
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.css" />
|
||||||
<script src="https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js"></script>
|
<script src="https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js"></script>
|
||||||
<script type="application/json" id="stari-data">{$stariJson|noescape}</script>
|
<script type="application/json" id="stari-data">{$stariJson|noescape}</script>
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue