This commit is contained in:
rahmagustin 2026-01-20 11:11:09 +07:00
parent 2be275b1fb
commit 32d581d5a4
4 changed files with 101 additions and 41 deletions

View File

@ -127,7 +127,7 @@ public function update(Request $request, $id)
// VALIDASI // VALIDASI
$request->validate([ $request->validate([
'kategori_tps_id' => 'required|exists:kategori_tps,id', 'kategori_tps_id' => 'required|exists:kategori_tps,id_kategori_tps',
'nama_tps' => 'required|string|max:255', 'nama_tps' => 'required|string|max:255',
'alamat_tps' => 'required|string|max:255', 'alamat_tps' => 'required|string|max:255',
'status_tps' => 'required', 'status_tps' => 'required',

View File

@ -4,6 +4,7 @@
use App\Models\Sampah; use App\Models\Sampah;
use App\Models\KategoriTps; use App\Models\KategoriTps;
use App\Models\LokasiTps;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class IndexController extends Controller class IndexController extends Controller
@ -12,7 +13,8 @@ public function index()
{ {
$sampah = Sampah::orderBy('tahun', 'desc')->first(); $sampah = Sampah::orderBy('tahun', 'desc')->first();
$kategoriTps = KategoriTps::orderBy('id_kategori_tps')->get(); $kategoriTps = KategoriTps::orderBy('id_kategori_tps')->get();
$lokasiTps = LokasiTps::all();
return view('user.index', compact('sampah', 'kategoriTps')); return view('user.index', compact('sampah', 'kategoriTps', 'lokasiTps'));
} }
} }

View File

@ -58,8 +58,8 @@ class="forms-sample">
<select name="kategori_tps_id" class="form-control" required> <select name="kategori_tps_id" class="form-control" required>
<option value="">-- Pilih Kategori --</option> <option value="">-- Pilih Kategori --</option>
@foreach ($kategori as $item) @foreach ($kategori as $item)
<option value="{{ $item->id }}" <option value="{{ $item->id_kategori_tps }}"
{{ old('kategori_tps_id', $tps->kategori_tps_id) == $item->id ? 'selected' : '' }}> {{ old('kategori_tps_id', $tps->kategori_tps_id) == $item->id_kategori_tps ? 'selected' : '' }}>
{{ $item->nama_kategori }} {{ $item->nama_kategori }}
</option> </option>
@endforeach @endforeach

View File

@ -203,64 +203,70 @@
<!-- /Services Section --> <!-- /Services Section -->
<!-- Call To Action Section --> <!-- Call To Action Section -->
{{-- Leaflet CSS & JS --}}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" /> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style> <style>
/* Hilangkan padding section */
#call-to-action.call-to-action { #call-to-action.call-to-action {
padding: 0 !important; padding: 0 !important;
margin: 0 !important; margin: 0 !important;
} }
/* Container dibuat flex agar map bisa center */
#call-to-action .container { #call-to-action .container {
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: 20px 0; padding: 20px 0;
} }
/* Wrapper card map modern */
.map-wrapper { .map-wrapper {
width: 100%; width: 100%;
max-width: 1100px; max-width: 1100px;
/* agar map di tengah */ border-radius: 12px;
border-radius: 10px;
overflow: hidden; overflow: hidden;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
} }
/* Map full card */
#mapTPS { #mapTPS {
width: 100%; width: 100%;
height: 450px; height: 450px;
} }
/* Zoom Button Modern */
.leaflet-control-zoom {
border-radius: 10px !important;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2) !important;
overflow: hidden !important;
}
/* Popup Modern */
.leaflet-popup-content-wrapper { .leaflet-popup-content-wrapper {
border-radius: 14px !important; border-radius: 14px !important;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15); }
/* Legend */
.legend {
background: white;
padding: 10px;
border-radius: 8px;
line-height: 18px;
color: #333;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.9;
} }
</style> </style>
<section id="call-to-action" class="call-to-action section"> <section id="call-to-action" class="call-to-action section">
<div class="container" data-aos="fade-up"> <div class="container" data-aos="fade-up">
<div class="map-wrapper"> <div class="map-wrapper">
<div id="mapTPS"></div> <div id="mapTPS"></div>
</div> </div>
</div> </div>
</section> </section>
<script> <script>
// =============================
// INIT MAP
// =============================
var map = L.map('mapTPS').setView([-7.6078, 111.903], 12); var map = L.map('mapTPS').setView([-7.6078, 111.903], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@ -268,30 +274,82 @@
maxZoom: 19 maxZoom: 19
}).addTo(map); }).addTo(map);
var tpsData = [{ // =============================
name: "TPS 1 Berbek", // ICON MARKER PER KATEGORI
lat: -7.5978, // =============================
lng: 111.917 function markerIcon(color) {
}, return new L.Icon({
{ iconUrl: `https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-${color}.png`,
name: "TPS 2 Loceret", shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png',
lat: -7.6280, iconSize: [25, 41],
lng: 111.910 iconAnchor: [12, 41],
}, popupAnchor: [1, -34],
{ shadowSize: [41, 41]
name: "TPS 3 Nganjuk Kota", });
lat: -7.6140, }
lng: 111.900
}
];
tpsData.forEach(tps => { var iconTPS = markerIcon('green'); // TPS
L.marker([tps.lat, tps.lng]) var iconTPS3R = markerIcon('blue'); // TPS 3R
.addTo(map) var iconTPA = markerIcon('red'); // TPA
.bindPopup(`<b style='font-size:16px;'>${tps.name}</b>`); var iconDefault = markerIcon('grey');
// =============================
// DATA TPS DARI DATABASE
// =============================
var tpsData = @json($lokasiTps);
tpsData.forEach(function(tps) {
if (tps.latitude && tps.longitude) {
let iconKategori = iconDefault;
// SESUAIKAN ID KATEGORI
if (tps.kategori_tps_id == 1) {
iconKategori = iconTPS;
} else if (tps.kategori_tps_id == 2) {
iconKategori = iconTPS3R;
} else if (tps.kategori_tps_id == 3) {
iconKategori = iconTPA;
}
L.marker([tps.latitude, tps.longitude], {
icon: iconKategori
})
.addTo(map)
.bindPopup(`
<div style="min-width:200px">
<strong>${tps.nama_tps}</strong><br>
${tps.alamat_tps ?? ''}<br>
<small>Status: ${tps.status_tps ?? '-'}</small>
</div>
`);
}
}); });
// =============================
// LEGEND PETA
// =============================
var legend = L.control({
position: "bottomright"
});
legend.onAdd = function() {
var div = L.DomUtil.create("div", "legend");
div.innerHTML = `
<strong>Kategori TPS</strong><br>
<i style="background:green"></i> TPS<br>
<i style="background:blue"></i> TPS 3R<br>
<i style="background:red"></i> TPA
`;
return div;
};
legend.addTo(map);
</script> </script>
<!-- Contact Section --> <!-- Contact Section -->
<section id="contact" class="contact section"> <section id="contact" class="contact section">