Files
UAS_WEBGIS_IhyaUlumuddinHar…/project_final/api/fasilitas.php
T
2026-06-13 11:24:58 +07:00

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');