Initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
// Pastikan file db_config.php sudah benar konfigurasinya
|
||||
include 'db_config.php';
|
||||
|
||||
/**
|
||||
* Mengambil semua fitur spasial dari tabel spatial_features.
|
||||
* Data diurutkan berdasarkan waktu pembuatan terbaru.
|
||||
*/
|
||||
$sql = "SELECT id, nama_objek, kategori, status_objek, type, geometry_data, nilai_ukur, created_at
|
||||
FROM spatial_features
|
||||
ORDER BY created_at DESC";
|
||||
|
||||
$result = $conn->query($sql);
|
||||
$features = [];
|
||||
|
||||
if (!$result) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Query gagal: ' . $conn->error]);
|
||||
$conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($result && $result->num_rows > 0) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
// Mendecode data JSON koordinat agar bisa langsung digunakan oleh Leaflet di frontend
|
||||
$row['geometry_data'] = json_decode($row['geometry_data']);
|
||||
|
||||
// Memastikan nilai_ukur dikirim sebagai angka (float/double)
|
||||
$row['nilai_ukur'] = (float)$row['nilai_ukur'];
|
||||
|
||||
$features[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// Mengirimkan data dalam format JSON
|
||||
echo json_encode($features);
|
||||
|
||||
// Menutup koneksi database
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user