feat: overhaul UI with new paper-themed layout and Libre Franklin typography
This commit is contained in:
@@ -4,12 +4,12 @@ Aplikasi WebGIS sederhana untuk menampilkan peta choropleth jumlah penduduk per
|
||||
|
||||
## Fitur
|
||||
|
||||
- Peta dasar citra satelit dari Esri.
|
||||
- Layer batas kecamatan Kota Pontianak.
|
||||
- Peta dasar terang dari CARTO (gaya atlas/kartografi).
|
||||
- Layer batas kecamatan Kota Pontianak dengan label tempat di atas layer choropleth.
|
||||
- Pewarnaan choropleth berdasarkan jumlah penduduk.
|
||||
- Popup dan panel info saat area kecamatan diarahkan cursor.
|
||||
- Zoom otomatis ke batas kecamatan saat area diklik.
|
||||
- Legenda rentang jumlah penduduk.
|
||||
- Sidebar berisi total penduduk, daftar kecamatan dengan bar pembanding, dan legenda.
|
||||
- Hover pada daftar kecamatan menyorot wilayahnya di peta (dan sebaliknya).
|
||||
- Zoom otomatis ke batas kecamatan saat area atau baris daftar diklik.
|
||||
|
||||
## Struktur File
|
||||
|
||||
@@ -25,7 +25,6 @@ Aplikasi WebGIS sederhana untuk menampilkan peta choropleth jumlah penduduk per
|
||||
- HTML, CSS, dan JavaScript
|
||||
- Leaflet
|
||||
- Proj4js
|
||||
- Turf.js
|
||||
- GeoJSON
|
||||
|
||||
## Cara Menjalankan
|
||||
@@ -35,7 +34,7 @@ Jalankan project melalui web server lokal agar pemanggilan file GeoJSON dapat be
|
||||
Jika menggunakan Laragon, letakkan folder project di direktori `www`, lalu buka:
|
||||
|
||||
```text
|
||||
http://localhost/GIS_Brutal/
|
||||
http://localhost/WebGIS_Choropleth/
|
||||
```
|
||||
|
||||
Atau gunakan server lokal lain dari direktori project:
|
||||
@@ -56,4 +55,4 @@ File `Admin_Kecamatan.json` berisi batas administrasi kecamatan Kota Pontianak.
|
||||
|
||||
## Catatan
|
||||
|
||||
Aplikasi membutuhkan koneksi internet untuk memuat library CDN dan tile peta Esri.
|
||||
Aplikasi membutuhkan koneksi internet untuk memuat library CDN dan tile peta CARTO.
|
||||
|
||||
+342
-223
@@ -3,220 +3,308 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>WebGIS Choropleth Kecamatan Pontianak</title>
|
||||
<title>Sebaran Penduduk Kota Pontianak — Peta Tematik per Kecamatan</title>
|
||||
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Libre+Franklin:wght@400;500;600&display=swap" rel="stylesheet" />
|
||||
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--bg-1: #091821;
|
||||
--bg-2: #103447;
|
||||
--panel: rgba(9, 24, 33, 0.78);
|
||||
--text-main: #e8f5f9;
|
||||
--text-sub: #acd1db;
|
||||
--accent: #ffd166;
|
||||
--border: rgba(255, 255, 255, 0.15);
|
||||
--shadow: 0 12px 45px rgba(0, 0, 0, 0.35);
|
||||
--paper: #f7f3ea;
|
||||
--paper-deep: #efe9db;
|
||||
--ink: #292420;
|
||||
--ink-soft: #6f675b;
|
||||
--rule: #d9d1bf;
|
||||
--accent: #a8501a;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
font-family: "Space Grotesk", sans-serif;
|
||||
color: var(--text-main);
|
||||
background:
|
||||
radial-gradient(circle at 12% 20%, rgba(255, 209, 102, 0.14), transparent 40%),
|
||||
radial-gradient(circle at 87% 12%, rgba(77, 174, 255, 0.2), transparent 45%),
|
||||
linear-gradient(130deg, var(--bg-1), var(--bg-2));
|
||||
overflow: hidden;
|
||||
font-family: "Libre Franklin", sans-serif;
|
||||
color: var(--ink);
|
||||
background: var(--paper);
|
||||
}
|
||||
|
||||
.app {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 340px 1fr;
|
||||
height: 100%;
|
||||
padding: 16px;
|
||||
animation: enter 0.7s ease;
|
||||
}
|
||||
|
||||
@keyframes enter {
|
||||
from {
|
||||
transform: translateY(8px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
/* ---------- Sidebar ---------- */
|
||||
|
||||
.panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid var(--rule);
|
||||
background: var(--paper);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#map {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 18px;
|
||||
border: 1px solid var(--border);
|
||||
box-shadow: var(--shadow);
|
||||
overflow: hidden;
|
||||
.panel-inner {
|
||||
padding: 28px 26px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.hud {
|
||||
position: absolute;
|
||||
left: 30px;
|
||||
top: 30px;
|
||||
z-index: 1000;
|
||||
width: min(420px, calc(100% - 60px));
|
||||
padding: 16px 18px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
backdrop-filter: blur(7px);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.hud h1 {
|
||||
margin: 0 0 6px;
|
||||
font-size: 1.24rem;
|
||||
line-height: 1.3;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
|
||||
.hud p {
|
||||
margin: 0;
|
||||
font-size: 0.92rem;
|
||||
color: var(--text-sub);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-flex;
|
||||
margin-top: 10px;
|
||||
padding: 5px 9px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(255, 209, 102, 0.4);
|
||||
.overline {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
color: var(--accent);
|
||||
font-size: 0.78rem;
|
||||
font-family: "IBM Plex Mono", monospace;
|
||||
letter-spacing: 0.2px;
|
||||
background: rgba(255, 209, 102, 0.08);
|
||||
margin: 0 0 14px;
|
||||
}
|
||||
|
||||
.leaflet-container {
|
||||
background: #0b202d;
|
||||
h1 {
|
||||
font-family: "Fraunces", serif;
|
||||
font-weight: 700;
|
||||
font-size: 1.85rem;
|
||||
line-height: 1.15;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.lede {
|
||||
font-size: 0.84rem;
|
||||
line-height: 1.55;
|
||||
color: var(--ink-soft);
|
||||
margin: 0 0 22px;
|
||||
}
|
||||
|
||||
.total {
|
||||
border-top: 1px solid var(--ink);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
padding: 14px 0;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.total-num {
|
||||
font-family: "Fraunces", serif;
|
||||
font-weight: 600;
|
||||
font-size: 2rem;
|
||||
line-height: 1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.total-label {
|
||||
font-size: 0.72rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-soft);
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.16em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-soft);
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.rows {
|
||||
margin: 0 0 24px;
|
||||
border-top: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
grid-template-areas: "name val" "bar bar";
|
||||
width: 100%;
|
||||
padding: 9px 2px 10px;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--rule);
|
||||
background: none;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.legend,
|
||||
.info-box {
|
||||
padding: 10px 12px;
|
||||
background: rgba(7, 20, 28, 0.92);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
color: var(--text-main);
|
||||
line-height: 1.35;
|
||||
box-shadow: var(--shadow);
|
||||
.row:hover,
|
||||
.row.is-active {
|
||||
background: var(--paper-deep);
|
||||
}
|
||||
|
||||
.legend h4 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 0.88rem;
|
||||
color: #dff4ff;
|
||||
.row-name {
|
||||
grid-area: name;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.row-val {
|
||||
grid-area: val;
|
||||
font-size: 0.82rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.row-bar {
|
||||
grid-area: bar;
|
||||
height: 5px;
|
||||
margin-top: 7px;
|
||||
background: var(--paper-deep);
|
||||
}
|
||||
|
||||
.row-bar i {
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.legend-rows { margin-bottom: 24px; }
|
||||
|
||||
.legend-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 4px 0;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-sub);
|
||||
font-family: "IBM Plex Mono", monospace;
|
||||
gap: 10px;
|
||||
padding: 3px 0;
|
||||
font-size: 0.78rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.swatch {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.26);
|
||||
flex: 0 0 16px;
|
||||
width: 22px;
|
||||
height: 13px;
|
||||
border: 1px solid rgba(41, 36, 32, 0.25);
|
||||
flex: 0 0 22px;
|
||||
}
|
||||
|
||||
.panel-foot {
|
||||
margin-top: auto;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid var(--rule);
|
||||
font-size: 0.7rem;
|
||||
line-height: 1.6;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
.panel-foot .status { font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ---------- Map ---------- */
|
||||
|
||||
.map-wrap { position: relative; }
|
||||
|
||||
#map {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #eef0ea;
|
||||
}
|
||||
|
||||
.leaflet-container { font: inherit; }
|
||||
|
||||
.info-box {
|
||||
width: 230px;
|
||||
padding: 10px 14px;
|
||||
background: #fffdf8;
|
||||
border: 1px solid var(--rule);
|
||||
border-left: 3px solid var(--accent);
|
||||
box-shadow: 0 1px 3px rgba(41, 36, 32, 0.12);
|
||||
color: var(--ink);
|
||||
line-height: 1.45;
|
||||
font-size: 0.8rem;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.info-box b {
|
||||
color: #fff;
|
||||
font-family: "Fraunces", serif;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
position: absolute;
|
||||
right: 26px;
|
||||
bottom: 20px;
|
||||
z-index: 1000;
|
||||
padding: 8px 10px;
|
||||
border-radius: 9px;
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(9, 24, 33, 0.86);
|
||||
color: var(--text-sub);
|
||||
font-family: "IBM Plex Mono", monospace;
|
||||
font-size: 0.76rem;
|
||||
.leaflet-bar a,
|
||||
.leaflet-bar a:hover {
|
||||
background: #fffdf8;
|
||||
color: var(--ink);
|
||||
border-bottom-color: var(--rule);
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.app {
|
||||
padding: 10px;
|
||||
.leaflet-touch .leaflet-bar { border: 1px solid var(--rule); }
|
||||
|
||||
.leaflet-popup-content-wrapper {
|
||||
background: #fffdf8;
|
||||
color: var(--ink);
|
||||
border: 1px solid var(--rule);
|
||||
border-radius: 0;
|
||||
box-shadow: 0 1px 3px rgba(41, 36, 32, 0.15);
|
||||
}
|
||||
|
||||
.leaflet-popup-tip { background: #fffdf8; }
|
||||
|
||||
.leaflet-container .leaflet-control-attribution {
|
||||
background: rgba(247, 243, 234, 0.85);
|
||||
color: var(--ink-soft);
|
||||
font-size: 0.62rem;
|
||||
}
|
||||
|
||||
/* ---------- Mobile ---------- */
|
||||
|
||||
@media (max-width: 820px) {
|
||||
.layout {
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-rows: auto 1fr;
|
||||
}
|
||||
|
||||
.hud {
|
||||
left: 16px;
|
||||
top: 16px;
|
||||
width: calc(100% - 32px);
|
||||
.panel {
|
||||
max-height: 46vh;
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.hud h1 {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
right: 16px;
|
||||
bottom: 12px;
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
.panel-inner { padding: 20px 18px 14px; }
|
||||
h1 { font-size: 1.4rem; }
|
||||
.total-num { font-size: 1.5rem; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
<div id="map"></div>
|
||||
<div class="layout">
|
||||
<aside class="panel">
|
||||
<div class="panel-inner">
|
||||
<p class="overline">Peta Tematik · Kalimantan Barat</p>
|
||||
<h1>Sebaran Penduduk Kota Pontianak</h1>
|
||||
<p class="lede">
|
||||
Choropleth jumlah penduduk pada enam kecamatan di Kota Pontianak.
|
||||
Semakin pekat warnanya, semakin besar jumlah penduduknya. Klik
|
||||
kecamatan pada daftar atau peta untuk memperbesar wilayahnya.
|
||||
</p>
|
||||
|
||||
<section class="hud">
|
||||
<h1>WebGIS Choropleth Kecamatan Kota Pontianak</h1>
|
||||
<p>
|
||||
Intensitas warna menunjukkan jumlah penduduk setiap kecamatan di Kota Pontianak.
|
||||
</p>
|
||||
<span class="chip">Leaflet + Proj4 + Turf</span>
|
||||
</section>
|
||||
<div class="total">
|
||||
<div class="total-num" id="total-pop">—</div>
|
||||
<div class="total-label">Total penduduk · 6 kecamatan</div>
|
||||
</div>
|
||||
|
||||
<div class="status">Memuat data spasial...</div>
|
||||
<p class="section-title">Kecamatan</p>
|
||||
<div class="rows" id="rows"></div>
|
||||
|
||||
<p class="section-title">Jumlah penduduk (jiwa)</p>
|
||||
<div class="legend-rows" id="legend"></div>
|
||||
|
||||
<div class="panel-foot">
|
||||
Sumber batas administrasi: Admin_Kecamatan.json (EPSG:32749, dikonversi ke WGS 84).<br />
|
||||
<span class="status" id="status">Memuat data spasial…</span>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="map-wrap">
|
||||
<div id="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.9.2/proj4.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js"></script>
|
||||
|
||||
<script>
|
||||
const statusEl = document.querySelector('.status');
|
||||
const statusEl = document.getElementById('status');
|
||||
|
||||
const map = L.map('map', {
|
||||
zoomControl: true,
|
||||
@@ -225,31 +313,23 @@
|
||||
preferCanvas: true
|
||||
});
|
||||
|
||||
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
|
||||
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}{r}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="https://carto.com/attributions">CARTO</a>',
|
||||
subdomains: 'abcd'
|
||||
}).addTo(map);
|
||||
|
||||
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}', {
|
||||
attribution: 'Labels © Esri'
|
||||
map.createPane('labels');
|
||||
map.getPane('labels').style.zIndex = 650;
|
||||
map.getPane('labels').style.pointerEvents = 'none';
|
||||
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}{r}.png', {
|
||||
pane: 'labels',
|
||||
subdomains: 'abcd'
|
||||
}).addTo(map);
|
||||
|
||||
proj4.defs('EPSG:32749', '+proj=utm +zone=49 +south +datum=WGS84 +units=m +no_defs +type=crs');
|
||||
|
||||
const palette = ['#fff8dc', '#fee7ad', '#f9c76f', '#f39f4d', '#d97706', '#a84906'];
|
||||
|
||||
function round2(value) {
|
||||
return Math.round((value + Number.EPSILON) * 100) / 100;
|
||||
}
|
||||
|
||||
function getQuantileBreaks(values, steps) {
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
const breaks = [];
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const idx = Math.floor((i / steps) * (sorted.length - 1));
|
||||
breaks.push(sorted[idx]);
|
||||
}
|
||||
return breaks;
|
||||
}
|
||||
const palette = ['#fdf3d8', '#f7dfa2', '#eec06c', '#dd9440', '#bc651f', '#8c400d'];
|
||||
|
||||
function convertCoords(coords) {
|
||||
if (!Array.isArray(coords[0])) {
|
||||
@@ -301,63 +381,96 @@
|
||||
|
||||
info.update = function (props) {
|
||||
this._div.innerHTML = props
|
||||
? `<b>${props.Ket}</b><br>Jumlah Penduduk: ${props.pop.toLocaleString('id-ID')} jiwa`
|
||||
: 'Arahkan cursor ke kecamatan';
|
||||
? `<b>${props.Ket}</b><br>${props.pop.toLocaleString('id-ID')} jiwa`
|
||||
: 'Arahkan kursor ke kecamatan';
|
||||
};
|
||||
|
||||
info.addTo(map);
|
||||
|
||||
function createLegend(breaks) {
|
||||
const legend = L.control({ position: 'bottomright' });
|
||||
function renderLegend(breaks) {
|
||||
const wrap = document.getElementById('legend');
|
||||
|
||||
legend.onAdd = function () {
|
||||
const div = L.DomUtil.create('div', 'legend');
|
||||
div.innerHTML = '<h4>Jumlah Penduduk (jiwa)</h4>';
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const from = breaks[i];
|
||||
const to = breaks[i + 1];
|
||||
const label = to
|
||||
? `${from.toLocaleString('id-ID')} - ${to.toLocaleString('id-ID')}`
|
||||
: `> ${from.toLocaleString('id-ID')}`;
|
||||
const row = document.createElement('div');
|
||||
row.className = 'legend-row';
|
||||
row.innerHTML = `<span class="swatch" style="background:${palette[i]}"></span><span>${label}</span>`;
|
||||
div.appendChild(row);
|
||||
}
|
||||
|
||||
return div;
|
||||
};
|
||||
|
||||
legend.addTo(map);
|
||||
for (let i = 0; i < palette.length; i++) {
|
||||
const from = breaks[i];
|
||||
const to = breaks[i + 1];
|
||||
const label = to
|
||||
? `${from.toLocaleString('id-ID')} – ${to.toLocaleString('id-ID')}`
|
||||
: `> ${from.toLocaleString('id-ID')}`;
|
||||
const row = document.createElement('div');
|
||||
row.className = 'legend-row';
|
||||
row.innerHTML = `<span class="swatch" style="background:${palette[i]}"></span><span>${label}</span>`;
|
||||
wrap.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
function onEachFeatureFactory(layerRef) {
|
||||
return function onEachFeature(layer) {
|
||||
const feature = layer.feature;
|
||||
function renderRows(features, breaks, layerByName, layerRef) {
|
||||
const wrap = document.getElementById('rows');
|
||||
const maxPop = Math.max(...features.map((f) => f.properties.pop));
|
||||
const sorted = [...features].sort((a, b) => b.properties.pop - a.properties.pop);
|
||||
|
||||
sorted.forEach((feature) => {
|
||||
const { Ket, pop } = feature.properties;
|
||||
const row = document.createElement('button');
|
||||
row.type = 'button';
|
||||
row.className = 'row';
|
||||
row.dataset.name = Ket;
|
||||
row.innerHTML = `
|
||||
<span class="row-name">${Ket}</span>
|
||||
<span class="row-val">${pop.toLocaleString('id-ID')}</span>
|
||||
<span class="row-bar"><i style="width:${(pop / maxPop) * 100}%;background:${colorFromBreaks(pop, breaks)}"></i></span>
|
||||
`;
|
||||
|
||||
row.addEventListener('mouseenter', () => {
|
||||
const layer = layerByName.get(Ket);
|
||||
if (layer) highlight(layer);
|
||||
});
|
||||
row.addEventListener('mouseleave', () => {
|
||||
const layer = layerByName.get(Ket);
|
||||
if (layer) {
|
||||
layerRef.resetStyle(layer);
|
||||
info.update();
|
||||
setActiveRow(null);
|
||||
}
|
||||
});
|
||||
row.addEventListener('click', () => {
|
||||
const layer = layerByName.get(Ket);
|
||||
if (layer) map.fitBounds(layer.getBounds(), { padding: [24, 24] });
|
||||
});
|
||||
|
||||
wrap.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
function setActiveRow(name) {
|
||||
document.querySelectorAll('.row').forEach((row) => {
|
||||
row.classList.toggle('is-active', row.dataset.name === name);
|
||||
});
|
||||
}
|
||||
|
||||
function highlight(layer) {
|
||||
layer.setStyle({ weight: 2.4, color: '#292420', fillOpacity: 0.95 });
|
||||
layer.bringToFront();
|
||||
info.update(layer.feature.properties);
|
||||
setActiveRow(layer.feature.properties.Ket);
|
||||
}
|
||||
|
||||
function bindFeatureEvents(layerRef) {
|
||||
return function (layer) {
|
||||
layer.on({
|
||||
mouseover: (e) => {
|
||||
const target = e.target;
|
||||
target.setStyle({
|
||||
weight: 3,
|
||||
color: '#ffffff',
|
||||
fillOpacity: 0.94
|
||||
});
|
||||
target.bringToFront();
|
||||
info.update(target.feature.properties);
|
||||
},
|
||||
mouseover: (e) => highlight(e.target),
|
||||
mouseout: (e) => {
|
||||
layerRef.resetStyle(e.target);
|
||||
info.update();
|
||||
setActiveRow(null);
|
||||
},
|
||||
click: (e) => {
|
||||
map.fitBounds(e.target.getBounds(), { padding: [16, 16] });
|
||||
map.fitBounds(e.target.getBounds(), { padding: [24, 24] });
|
||||
}
|
||||
});
|
||||
|
||||
const p = feature.properties;
|
||||
const p = layer.feature.properties;
|
||||
layer.bindPopup(
|
||||
`<b>${p.Ket}</b><br/>Jumlah Penduduk: <b>${p.pop.toLocaleString('id-ID')} jiwa</b>`
|
||||
`<b>${p.Ket}</b><br/>Jumlah penduduk: <b>${p.pop.toLocaleString('id-ID')} jiwa</b>`
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -366,7 +479,7 @@
|
||||
const candidates = [
|
||||
'./Admin_Kecamatan.json',
|
||||
'Admin_Kecamatan.json',
|
||||
'/GIS_Brutal/Admin_Kecamatan.json',
|
||||
'/WebGIS_Choropleth/Admin_Kecamatan.json',
|
||||
'/Admin_Kecamatan.json'
|
||||
];
|
||||
|
||||
@@ -406,35 +519,41 @@
|
||||
const rawGeoJson = await fetchGeoJsonWithFallback();
|
||||
const geojson = convertFeatureCollectionToWGS84(rawGeoJson);
|
||||
|
||||
const values = geojson.features.map((f) => {
|
||||
const name = f.properties.Ket;
|
||||
const pop = populationData[name] || 0;
|
||||
let totalPop = 0;
|
||||
geojson.features.forEach((f) => {
|
||||
const pop = populationData[f.properties.Ket] || 0;
|
||||
f.properties.pop = pop;
|
||||
return pop;
|
||||
totalPop += pop;
|
||||
});
|
||||
|
||||
const breaks = [0, 50000, 95000, 115000, 135000, 150000];
|
||||
|
||||
const layerRef = L.geoJSON(geojson, {
|
||||
style: (feature) => ({
|
||||
color: '#0e2733',
|
||||
weight: 1.4,
|
||||
color: '#8a8270',
|
||||
weight: 1,
|
||||
fillColor: colorFromBreaks(feature.properties.pop, breaks),
|
||||
fillOpacity: 0.86
|
||||
fillOpacity: 0.82
|
||||
})
|
||||
});
|
||||
|
||||
layerRef.eachLayer(onEachFeatureFactory(layerRef));
|
||||
const layerByName = new Map();
|
||||
layerRef.eachLayer((layer) => {
|
||||
layerByName.set(layer.feature.properties.Ket, layer);
|
||||
});
|
||||
layerRef.eachLayer(bindFeatureEvents(layerRef));
|
||||
layerRef.addTo(map);
|
||||
|
||||
map.fitBounds(layerRef.getBounds(), { padding: [18, 18] });
|
||||
createLegend(breaks);
|
||||
map.fitBounds(layerRef.getBounds(), { padding: [24, 24] });
|
||||
|
||||
statusEl.textContent = 'Data termuat: 6 kecamatan';
|
||||
document.getElementById('total-pop').textContent = totalPop.toLocaleString('id-ID');
|
||||
renderRows(geojson.features, breaks, layerByName, layerRef);
|
||||
renderLegend(breaks);
|
||||
|
||||
statusEl.textContent = `Data termuat: ${geojson.features.length} kecamatan.`;
|
||||
} catch (error) {
|
||||
statusEl.textContent = 'Terjadi error saat memuat data';
|
||||
statusEl.textContent = 'Terjadi error saat memuat data spasial.';
|
||||
console.error(error);
|
||||
alert(`Data gagal dimuat: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user