mirror of
https://github.com/rekywhyd/gis_tugas.git
synced 2026-07-07 02:13:07 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$host = getenv('DB_HOST') ?: 'localhost';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: '';
|
||||
$db = getenv('DB_NAME') ?: 'gis_tugas';
|
||||
|
||||
$conn = mysqli_connect($host, $user, $pass, $db);
|
||||
|
||||
if (!$conn) {
|
||||
die("Koneksi gagal: " . mysqli_connect_error());
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,375 @@
|
||||
<?php include 'config.php'; ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>WebGIS Manajemen Jalan - Search & Filter</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css"/>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
||||
|
||||
:root {
|
||||
--primary-navy: #0F2027; /* Gelap & Elegan */
|
||||
--secondary-navy: #203A43;
|
||||
--accent-blue: #2C5364;
|
||||
--bg-color: #F8FAFC;
|
||||
--card-bg: #FFFFFF;
|
||||
--text-main: #1E293B;
|
||||
--text-muted: #64748B;
|
||||
--border-color: #E2E8F0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
margin: 0;
|
||||
background: var(--bg-color);
|
||||
color: var(--text-main);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, var(--primary-navy), var(--secondary-navy));
|
||||
color: white;
|
||||
padding: 20px 30px;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header h2 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 30px auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.panel, .table-container {
|
||||
background: var(--card-bg);
|
||||
padding: 25px 30px;
|
||||
border-radius: 16px;
|
||||
margin-bottom: 25px;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
|
||||
border: 1px solid var(--border-color);
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.panel:hover, .table-container:hover {
|
||||
box-shadow: 0 12px 20px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.panel h3, .table-container h3 {
|
||||
color: var(--primary-navy);
|
||||
font-weight: 700;
|
||||
margin-top: 0;
|
||||
font-size: 18px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-inline {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.input-group strong {
|
||||
font-size: 14px;
|
||||
color: var(--secondary-navy);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
input, select {
|
||||
padding: 12px 16px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
font-family: 'Inter', sans-serif;
|
||||
font-size: 14px;
|
||||
color: var(--text-main);
|
||||
background-color: var(--bg-color);
|
||||
transition: all 0.3s ease;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
input:focus, select:focus {
|
||||
border-color: var(--accent-blue);
|
||||
box-shadow: 0 0 0 3px rgba(44, 83, 100, 0.15);
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
small {
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
#map {
|
||||
height: 550px;
|
||||
width: 100%;
|
||||
border-radius: 16px;
|
||||
border: none;
|
||||
box-shadow: 0 10px 25px rgba(15, 32, 39, 0.1);
|
||||
z-index: 1;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
/* Tabel Styling */
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
margin-top: 15px;
|
||||
}
|
||||
th, td {
|
||||
padding: 16px 20px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
th {
|
||||
background: linear-gradient(135deg, var(--primary-navy), var(--secondary-navy));
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.8px;
|
||||
}
|
||||
th:first-child { border-top-left-radius: 10px; }
|
||||
th:last-child { border-top-right-radius: 10px; }
|
||||
|
||||
tbody tr {
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
tbody tr:hover {
|
||||
background-color: #F1F5F9;
|
||||
}
|
||||
|
||||
.badge {
|
||||
padding: 6px 14px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
display: inline-block;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Leaflet Overrides */
|
||||
.leaflet-control-layers, .leaflet-bar {
|
||||
border: none !important;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
|
||||
border-radius: 12px !important;
|
||||
}
|
||||
.leaflet-control-layers { padding: 8px !important; font-family: 'Inter', sans-serif; }
|
||||
.leaflet-bar { overflow: hidden; }
|
||||
.leaflet-bar a {
|
||||
border-bottom: 1px solid #eee !important;
|
||||
color: var(--primary-navy) !important;
|
||||
width: 32px !important;
|
||||
height: 32px !important;
|
||||
line-height: 32px !important;
|
||||
}
|
||||
.leaflet-bar a:hover {
|
||||
background-color: #f8f9fa !important;
|
||||
color: var(--accent-blue) !important;
|
||||
}
|
||||
.leaflet-popup-content-wrapper {
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
.leaflet-popup-content { font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.5; }
|
||||
.leaflet-popup-content b { color: var(--primary-navy); font-size: 15px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>🛣️ Manajemen Data Jalan (Polyline)</h2>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="panel">
|
||||
<h3>Input Data Baru</h3>
|
||||
<div class="form-inline">
|
||||
<div class="input-group">
|
||||
<strong>Nama Jalan:</strong>
|
||||
<input type="text" id="nama_jalan" placeholder="Nama Jalan Baru...">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<strong>Status Jalan:</strong>
|
||||
<select id="status_jalan">
|
||||
<option value="Nasional">Nasional (Merah)</option>
|
||||
<option value="Provinsi">Provinsi (Biru)</option>
|
||||
<option value="Kabupaten">Kabupaten (Hijau)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<small>Isi nama dan status, lalu gambar garis di peta untuk menyimpan data.</small>
|
||||
</div>
|
||||
|
||||
<div class="panel search-box">
|
||||
<h3>Pencarian & Filter</h3>
|
||||
<div class="form-inline">
|
||||
<div class="input-group">
|
||||
<strong>Cari Nama:</strong>
|
||||
<input type="text" id="search_input" placeholder="Ketik nama jalan..." onkeyup="filterData()">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<strong>Filter Status:</strong>
|
||||
<select id="filter_status" onchange="filterData()">
|
||||
<option value="Semua">Semua Status</option>
|
||||
<option value="Nasional">Nasional</option>
|
||||
<option value="Provinsi">Provinsi</option>
|
||||
<option value="Kabupaten">Kabupaten</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="map"></div>
|
||||
|
||||
<div class="table-container">
|
||||
<h3>Daftar Jalan</h3>
|
||||
<table id="tabel_jalan">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nama Jalan</th>
|
||||
<th>Status</th>
|
||||
<th>Panjang</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
|
||||
|
||||
<script>
|
||||
// 1. Inisialisasi Map
|
||||
var map = L.map('map').setView([-0.02, 109.34], 13);
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
|
||||
|
||||
const gayaJalan = {
|
||||
"Nasional": { color: 'red', weight: 6 },
|
||||
"Provinsi": { color: 'blue', weight: 4 },
|
||||
"Kabupaten": { color: 'green', weight: 3 }
|
||||
};
|
||||
|
||||
// Arry untuk menampung semua data dari database agar bisa difilter di sisi client
|
||||
let dataJalanGlobal = [];
|
||||
let layerGroup = L.layerGroup().addTo(map);
|
||||
|
||||
// 2. Fungsi Load Data dari PHP ke JS
|
||||
function loadData() {
|
||||
<?php
|
||||
$res = mysqli_query($conn, "SELECT * FROM data_jalan ORDER BY id DESC");
|
||||
$data = [];
|
||||
while($row = mysqli_fetch_assoc($res)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
echo "dataJalanGlobal = " . json_encode($data) . ";";
|
||||
?>
|
||||
renderData(dataJalanGlobal);
|
||||
}
|
||||
|
||||
// 3. Fungsi Menampilkan Data ke Peta dan Tabel
|
||||
function renderData(data) {
|
||||
layerGroup.clearLayers(); // Bersihkan peta
|
||||
const tbody = document.querySelector("#tabel_jalan tbody");
|
||||
tbody.innerHTML = ""; // Bersihkan tabel
|
||||
|
||||
data.forEach(item => {
|
||||
// Tambahkan ke Peta
|
||||
const coords = JSON.parse(item.geojson_data);
|
||||
const poly = L.polyline(coords, gayaJalan[item.status_jalan])
|
||||
.bindPopup(`<b>${item.nama_jalan}</b><br>Status: ${item.status_jalan}<br>Panjang: ${item.panjang_jalan} m`);
|
||||
layerGroup.addLayer(poly);
|
||||
|
||||
// Tambahkan ke Tabel
|
||||
const color = gayaJalan[item.status_jalan].color;
|
||||
const row = `<tr>
|
||||
<td>${item.nama_jalan}</td>
|
||||
<td><span class="badge" style="background:${color}">${item.status_jalan}</span></td>
|
||||
<td>${parseFloat(item.panjang_jalan).toLocaleString()} m</td>
|
||||
</tr>`;
|
||||
tbody.innerHTML += row;
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Fungsi Search dan Filter
|
||||
function filterData() {
|
||||
const keyword = document.getElementById('search_input').value.toLowerCase();
|
||||
const statusFilt = document.getElementById('filter_status').value;
|
||||
|
||||
const hasilFilter = dataJalanGlobal.filter(item => {
|
||||
const matchNama = item.nama_jalan.toLowerCase().includes(keyword);
|
||||
const matchStatus = (statusFilt === "Semua") || (item.status_jalan === statusFilt);
|
||||
return matchNama && matchStatus;
|
||||
});
|
||||
|
||||
renderData(hasilFilter);
|
||||
}
|
||||
|
||||
// 5. Fitur Menggambar (Leaflet Draw)
|
||||
var drawnItems = new L.FeatureGroup();
|
||||
map.addLayer(drawnItems);
|
||||
var drawControl = new L.Control.Draw({
|
||||
draw: { polygon: false, circle: false, marker: false, circlemarker: false, rectangle: false,
|
||||
polyline: { shapeOptions: { color: '#333' } }
|
||||
}
|
||||
});
|
||||
map.addControl(drawControl);
|
||||
|
||||
map.on(L.Draw.Event.CREATED, function (e) {
|
||||
var layer = e.layer;
|
||||
var latlngs = layer.getLatLngs();
|
||||
var totalPanjang = 0;
|
||||
for (let i = 0; i < latlngs.length - 1; i++) {
|
||||
totalPanjang += latlngs[i].distanceTo(latlngs[i + 1]);
|
||||
}
|
||||
|
||||
var nama = document.getElementById('nama_jalan').value;
|
||||
var status = document.getElementById('status_jalan').value;
|
||||
|
||||
if(!nama) { alert("Isi Nama Jalan dulu!"); return; }
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('nama', nama);
|
||||
formData.append('status', status);
|
||||
formData.append('coords', JSON.stringify(latlngs));
|
||||
formData.append('panjang', totalPanjang.toFixed(2));
|
||||
|
||||
fetch('save.php', { method: 'POST', body: formData })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if(data.status === 'success') {
|
||||
alert("Data Berhasil Disimpan!");
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Jalankan saat pertama kali buka
|
||||
loadData();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
include 'config.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$nama = mysqli_real_escape_string($conn, $_POST['nama']);
|
||||
$status = $_POST['status'];
|
||||
$coords = $_POST['coords'];
|
||||
$panjang = $_POST['panjang'];
|
||||
|
||||
$query = "INSERT INTO data_jalan (nama_jalan, status_jalan, geojson_data, panjang_jalan)
|
||||
VALUES ('$nama', '$status', '$coords', '$panjang')";
|
||||
|
||||
if (mysqli_query($conn, $query)) {
|
||||
echo json_encode(['status' => 'success']);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => mysqli_error($conn)]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user