22 lines
826 B
PHP
22 lines
826 B
PHP
<?php
|
|
/**
|
|
* api/fasilitas.php — GeoJSON fasilitas publik (untuk peta & proximity).
|
|
* GET → FeatureCollection titik fasilitas (sekolah/puskesmas/pasar/dll).
|
|
*/
|
|
require_once __DIR__ . '/../config/db.php';
|
|
require_once __DIR__ . '/helpers.php';
|
|
|
|
$pdo = Database::getConnection();
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') sendError('Method not allowed', 405);
|
|
|
|
$stmt = $pdo->query("SELECT id, nama, jenis, ST_AsGeoJSON(geom) AS geojson FROM fasilitas_publik ORDER BY jenis, nama");
|
|
$features = [];
|
|
while ($r = $stmt->fetch()) {
|
|
$features[] = [
|
|
'type' => 'Feature',
|
|
'geometry' => json_decode($r['geojson']),
|
|
'properties' => ['id' => (int)$r['id'], 'nama' => $r['nama'], 'jenis' => $r['jenis']],
|
|
];
|
|
}
|
|
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Fasilitas Publik');
|