This commit is contained in:
2026-05-12 10:16:16 +07:00
parent bae0569701
commit c2efc4414f
37 changed files with 2222 additions and 18 deletions
+3
View File
@@ -0,0 +1,3 @@
<?php
header('Content-Type: application/json');
echo json_encode(['success'=>true,'msg'=>'API placeholder untuk layer groups']);
@@ -0,0 +1,36 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'ID fitur tidak valid']);
$conn->close();
exit;
}
$stmt = $conn->prepare("DELETE FROM spatial_features WHERE id = ?");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Fitur berhasil dihapus']);
} else {
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
}
$conn->close();
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../db_config.php';
$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()) {
$row['geometry_data'] = json_decode($row['geometry_data']);
$row['nilai_ukur'] = (float)$row['nilai_ukur'];
$features[] = $row;
}
}
echo json_encode($features);
$conn->close();
?>
+36
View File
@@ -0,0 +1,36 @@
<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Layer Groups & Choropleth</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>html,body,#map{height:100%;margin:0}</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
const map = L.map('map').setView([-0.03,109.34],11);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
// Layer group for SPBU points
const spbuLayer = L.layerGroup();
const spbuMarkers = [L.marker([-0.03,109.34]).bindPopup('SPBU A'), L.marker([-0.04,109.36]).bindPopup('SPBU B')];
spbuMarkers.forEach(m=>spbuLayer.addLayer(m));
// Choropleth layer (load from ../data/pontianak-kecamatan.geojson if available)
let choropleth = L.layerGroup();
fetch('../data/pontianak-kecamatan.geojson').then(r=>r.json()).then(j=>{
function getColor(d){return d>10000?'#800026':d>5000?'#BD0026':d>2000?'#E31A1C':d>1000?'#FC4E2A':'#FD8D3C';}
choropleth = L.geoJSON(j,{style: f=>({fillColor:getColor(f.properties.luas||0),weight:1,fillOpacity:0.7,color:'#333'})}).addTo(map);
controlLayers.addOverlay(choropleth,'Choropleth');
}).catch(()=>{ /* ignore missing file */ });
const base = {};
const overlays = {'SPBU Points': spbuLayer};
const controlLayers = L.control.layers(base, overlays, {collapsed:false}).addTo(map);
spbuLayer.addTo(map);
</script>
</body>
</html>
+50
View File
@@ -0,0 +1,50 @@
<?php
header('Content-Type: application/json');
ini_set('display_errors', '0');
ini_set('html_errors', '0');
include __DIR__ . '/../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nama = trim($_POST['nama'] ?? '');
$kategori = trim($_POST['kategori'] ?? '');
if ($kategori === 'Parsil Tanah') {
$kategori = 'Tanah';
}
$status = trim($_POST['status'] ?? '');
$type = trim($_POST['type'] ?? '');
$geometry = $_POST['geometry'] ?? '';
$nilai = (float)($_POST['nilai'] ?? 0);
if ($nama === '' || $kategori === '' || $status === '' || $type === '' || $geometry === '') {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Data fitur tidak lengkap']);
$conn->close();
exit;
}
$stmt = $conn->prepare("INSERT INTO spatial_features (nama_objek, kategori, status_objek, type, geometry_data, nilai_ukur) VALUES (?, ?, ?, ?, ?, ?)");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param("sssssd", $nama, $kategori, $status, $type, $geometry, $nilai);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Data berhasil disimpan']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>
@@ -0,0 +1,45 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (int)($_POST['id'] ?? 0);
$nama = trim($_POST['nama'] ?? '');
$kategori = trim($_POST['kategori'] ?? '');
if ($kategori === 'Parsil Tanah') {
$kategori = 'Tanah';
}
$status = trim($_POST['status'] ?? '');
$type = trim($_POST['type'] ?? '');
$geometry = $_POST['geometry'] ?? '';
$nilai = (float)($_POST['nilai'] ?? 0);
if ($id <= 0 || $nama === '' || $kategori === '' || $status === '' || $type === '' || $geometry === '') {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Data fitur tidak lengkap']);
$conn->close();
exit;
}
$stmt = $conn->prepare("UPDATE spatial_features SET nama_objek = ?, kategori = ?, status_objek = ?, type = ?, geometry_data = ?, nilai_ukur = ? WHERE id = ?");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param("sssssdi", $nama, $kategori, $status, $type, $geometry, $nilai, $id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Fitur berhasil diperbarui']);
} else {
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
}
$conn->close();
?>