diff --git a/tugas02/README.md b/tugas02/README.md new file mode 100644 index 0000000..1427ddd --- /dev/null +++ b/tugas02/README.md @@ -0,0 +1,25 @@ +# Project 2 - WebGIS Manajemen Jalan dan Tanah + +Project ini khusus untuk mengelola data spasial berbentuk: + +- Polyline untuk jalan. +- Polygon untuk tanah/kavling. + +## Database + +Import file `database.sql` ke phpMyAdmin. Database yang dibuat adalah: + +`webgis_jalan_tanah_p2` + +Tabel utama: + +`data_spasial` + +## Cara Menjalankan + +1. Letakkan folder ini di `htdocs`. +2. Jalankan Apache dan MySQL. +3. Import `database.sql`. +4. Buka `http://localhost/webgis_pisah/project_02_webgis_jalan_tanah/`. +5. Gunakan tool polyline untuk menambah jalan. +6. Gunakan tool polygon untuk menambah tanah/kavling. diff --git a/tugas02/api.php b/tugas02/api.php new file mode 100644 index 0000000..170c117 --- /dev/null +++ b/tugas02/api.php @@ -0,0 +1,65 @@ +query($sql); + $data = []; + + while ($row = $result->fetch_assoc()) { + $data[] = $row; + } + + echo json_encode($data); +} +elseif ($action === 'simpan') { + $nama = trim($_POST['nama'] ?? ''); + $jenis_objek = $_POST['jenis_objek'] ?? ''; + $status = $_POST['status'] ?? ''; + $ukuran = floatval($_POST['ukuran'] ?? 0); + $geojson = $_POST['geojson'] ?? ''; + + if ($nama === '' || $jenis_objek === '' || $geojson === '') { + echo json_encode(["status" => "error", "message" => "Nama, jenis objek, dan geometri wajib diisi."]); + exit; + } + + $stmt = $conn->prepare("INSERT INTO tugas02_data_spasial (nama, jenis_objek, status, ukuran, geojson) VALUES (?, ?, ?, ?, ?)"); + $stmt->bind_param("sssds", $nama, $jenis_objek, $status, $ukuran, $geojson); + + if ($stmt->execute()) { + echo json_encode(["status" => "success"]); + } else { + echo json_encode(["status" => "error", "message" => $stmt->error]); + } + + $stmt->close(); +} +elseif ($action === 'hapus') { + $id = intval($_POST['id'] ?? 0); + + if ($id <= 0) { + echo json_encode(["status" => "error", "message" => "ID tidak valid."]); + exit; + } + + $stmt = $conn->prepare("DELETE FROM tugas02_data_spasial WHERE id = ?"); + $stmt->bind_param("i", $id); + + if ($stmt->execute()) { + echo json_encode(["status" => "success"]); + } else { + echo json_encode(["status" => "error", "message" => $stmt->error]); + } + + $stmt->close(); +} +else { + echo json_encode(["status" => "error", "message" => "Action tidak dikenali."]); +} + +$conn->close(); +?> diff --git a/tugas02/connect.php b/tugas02/connect.php new file mode 100644 index 0000000..f58dec2 --- /dev/null +++ b/tugas02/connect.php @@ -0,0 +1,19 @@ +connect_error) { + http_response_code(500); + die(json_encode([ + "status" => "error", + "message" => "Koneksi database gagal: " . $conn->connect_error + ])); +} + +$conn->set_charset('utf8mb4'); +?> diff --git a/tugas02/index.html b/tugas02/index.html new file mode 100644 index 0000000..e0717c9 --- /dev/null +++ b/tugas02/index.html @@ -0,0 +1,268 @@ + + + + + + Project 2 - WebGIS Jalan dan Tanah + + + + + +
+

Project 2 - Jalan dan Tanah

+

Gunakan polyline untuk jalan dan polygon untuk tanah/kavling.

+
+
+ + + + + +