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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="vi">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
| 6 |
+
<title>Bản đồ tra cứu hành chính TP.HCM - Long Ngo, 2025</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
| 9 |
+
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/topojson-client@3"></script>
|
| 11 |
+
<style>
|
| 12 |
+
html, body { height: 100%; margin: 0; padding: 0; font-family: 'Helvetica Neue', Arial, sans-serif; background: #15161c;}
|
| 13 |
+
#map { height: 100vh; width: 100vw; background: #15161c; }
|
| 14 |
+
.non-serif { font-family: 'Helvetica Neue', Arial, sans-serif !important; }
|
| 15 |
+
.shadow-sm { box-shadow: 0 2px 8px #0001; }
|
| 16 |
+
.popup-header { background: #24272f; color: #f9c846; padding: 1rem 1.3rem 0.7rem 1.3rem; border-bottom: 1px solid #393a44; font-size: 1.13rem; font-weight: 600; }
|
| 17 |
+
.popup-body { padding: 0.9rem 1.3rem; font-size: 1rem; color: #f2f2f5;}
|
| 18 |
+
.popup-metrics { display: flex; gap: 1.3rem; margin-bottom: 0.7rem; }
|
| 19 |
+
.popup-metric { background: #23243a; border-radius: 8px; padding: 0.5rem 1rem; text-align: center; min-width: 90px; color:#f9c846;}
|
| 20 |
+
.popup-label { font-size: 0.85rem; color: #bbb; }
|
| 21 |
+
.popup-value { font-size: 1.15rem; font-weight: 700; color: #fff; }
|
| 22 |
+
.popup-footer { background: #23243a; color: #bbb; padding: 0.8rem 1.3rem; border-top: 1px solid #393a44; }
|
| 23 |
+
.search-bar { position: absolute; top: 1.2rem; left: 50%; transform: translateX(-50%); width: 98vw; max-width: 450px; z-index: 999; }
|
| 24 |
+
.search-input { width: 100%; border-radius: 0.85rem; border: 1px solid #2d3141; padding: 0.75rem 1.1rem; font-size: 1.1rem; outline: none; box-shadow: 0 4px 16px #0002; background: #23243a; color:#f4e6b7;}
|
| 25 |
+
.search-results { background: #23243a; border-radius: 0.85rem; box-shadow: 0 6px 32px #0006; margin-top: 0.3rem; border: 1px solid #393a44; max-height: 44vh; overflow-y: auto;}
|
| 26 |
+
.search-item { width: 100%; text-align: left; border: none; background: none; padding: 0.8rem 1.1rem; font-size: 1.03rem; color: #ffecc3; cursor: pointer;}
|
| 27 |
+
.search-item:hover,.search-item:focus { background: #393a44; color: #fff;}
|
| 28 |
+
@media (max-width: 600px) {
|
| 29 |
+
.search-bar { top: 0.6rem; max-width: 98vw; }
|
| 30 |
+
.search-input { font-size: 0.99rem; padding: 0.6rem 0.8rem; }
|
| 31 |
+
.popup-header, .popup-footer, .popup-body { padding: 0.7rem 0.7rem;}
|
| 32 |
+
.popup-metrics { gap: 0.5rem;}
|
| 33 |
+
.popup-metric { min-width: 65px; }
|
| 34 |
+
}
|
| 35 |
+
</style>
|
| 36 |
+
</head>
|
| 37 |
+
<body class="non-serif">
|
| 38 |
+
|
| 39 |
+
<div class="search-bar">
|
| 40 |
+
<input id="searchInput" class="search-input" type="text" autocomplete="off" placeholder="Tìm xã/phường, huyện/quận...">
|
| 41 |
+
<div id="searchResults" class="search-results" style="display:none"></div>
|
| 42 |
+
</div>
|
| 43 |
+
<div id="map"></div>
|
| 44 |
+
<footer style="position:fixed;right:8px;bottom:8px;z-index:10001;font-size:13px;color:#b1b3bb;">Nguồn: Long Ngo, 2025</footer>
|
| 45 |
+
|
| 46 |
+
<script>
|
| 47 |
+
// CHỈ hiện ranh giới các xã/phường TP.HCM, nổi bật so với nền xung quanh!
|
| 48 |
+
const WARDS_TOPOJSON_URL = 'https://raw.githubusercontent.com/lqtue/phuongnao/main/Data/Wards.json';
|
| 49 |
+
const WARD_DATA_TSV_URL = 'https://raw.githubusercontent.com/lqtue/phuongnao/main/Data/Data.tsv';
|
| 50 |
+
|
| 51 |
+
let map, wardsLayer, highlightLayer;
|
| 52 |
+
let features = [];
|
| 53 |
+
let searchArr = [];
|
| 54 |
+
let searchResults = [];
|
| 55 |
+
let currentFocus = -1;
|
| 56 |
+
|
| 57 |
+
function normalize(str) {
|
| 58 |
+
return (str||'').toLowerCase()
|
| 59 |
+
.normalize("NFD").replace(/[\u0300-\u036f]/g,"")
|
| 60 |
+
.replace(/đ/g,"d").replace(/[^a-z0-9 ]/g,"").replace(/\s+/g," ").trim();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function getHCMBounds(features) {
|
| 64 |
+
// Tìm ranh giới bao quanh tất cả các xã/phường TP.HCM (cho fitBounds)
|
| 65 |
+
const coords = [];
|
| 66 |
+
features.forEach(f=>{
|
| 67 |
+
let geom = f.geometry.coordinates;
|
| 68 |
+
if (f.geometry.type==='Polygon') coords.push(...geom[0]);
|
| 69 |
+
if (f.geometry.type==='MultiPolygon') geom.forEach(g=>coords.push(...g[0]));
|
| 70 |
+
});
|
| 71 |
+
const latlngs = coords.map(([lng,lat])=>[lat,lng]);
|
| 72 |
+
return L.latLngBounds(latlngs);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function wardColor(name) {
|
| 76 |
+
// Cho mỗi xã/phường 1 màu khác biệt
|
| 77 |
+
let hash = 0; for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
|
| 78 |
+
let h = Math.abs(hash % 360); return `hsl(${h},68%,48%)`;
|
| 79 |
+
}
|
| 80 |
+
function metric(n, unit='') {
|
| 81 |
+
return !n||n==='NaN'?'-':parseFloat(n).toLocaleString('vi-VN')+(unit?(' '+unit):'');
|
| 82 |
+
}
|
| 83 |
+
function createPopup(props){
|
| 84 |
+
return `
|
| 85 |
+
<div class="popup-header">${props['Loại']||''} ${props['Tên']||''}</div>
|
| 86 |
+
<div class="popup-body">
|
| 87 |
+
<div class="popup-metrics">
|
| 88 |
+
<div class="popup-metric"><div class="popup-label">Dân số</div><div class="popup-value">${metric(props['Dân số (người)'])}</div></div>
|
| 89 |
+
<div class="popup-metric"><div class="popup-label">Diện tích</div><div class="popup-value">${metric(props['Diện tích (km2)'],'km²')}</div></div>
|
| 90 |
+
<div class="popup-metric"><div class="popup-label">Mật độ</div><div class="popup-value">${metric(props['Mật độ (người/km2)'])}</div></div>
|
| 91 |
+
</div>
|
| 92 |
+
${props['Sáp nhập toàn bộ từ']||props['Sáp nhập một phần từ']?
|
| 93 |
+
`<div class="popup-label" style="margin-top:6px;">Sáp nhập:
|
| 94 |
+
${props['Sáp nhập toàn bộ từ']?'Toàn bộ '+props['Sáp nhập toàn bộ từ']:''}
|
| 95 |
+
${props['Sáp nhập toàn bộ từ']&&props['Sáp nhập một phần từ']?'; ':''}
|
| 96 |
+
${props['Sáp nhập một phần từ']?'Một phần '+props['Sáp nhập một phần từ']:''}
|
| 97 |
+
</div>`:''
|
| 98 |
+
}
|
| 99 |
+
</div>
|
| 100 |
+
<div class="popup-footer">${props['Full Address 1']||' '}</div>
|
| 101 |
+
`;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
async function main(){
|
| 105 |
+
// Load dữ liệu
|
| 106 |
+
const [topo, tsv] = await Promise.all([
|
| 107 |
+
fetch(WARDS_TOPOJSON_URL).then(r=>r.json()),
|
| 108 |
+
fetch(WARD_DATA_TSV_URL).then(r=>r.text())
|
| 109 |
+
]);
|
| 110 |
+
// Chỉ lấy các xã/phường của TP.HCM (hầu hết file này đã tách riêng TP.HCM)
|
| 111 |
+
const geojson = topojson.feature(topo, Object.keys(topo.objects)[0]);
|
| 112 |
+
features = geojson.features;
|
| 113 |
+
// Parse TSV
|
| 114 |
+
const [header,...rows] = tsv.trim().split(/\r?\n/);
|
| 115 |
+
const keys = header.split('\t');
|
| 116 |
+
const arr = rows.map(line=>{
|
| 117 |
+
const cells = line.split('\t');
|
| 118 |
+
let obj={};
|
| 119 |
+
keys.forEach((k,i)=>obj[k]=cells[i]);
|
| 120 |
+
return obj;
|
| 121 |
+
});
|
| 122 |
+
// Map data by STT
|
| 123 |
+
let mapData = {};
|
| 124 |
+
arr.forEach(row=>{ mapData[row.STT]=row; });
|
| 125 |
+
features.forEach(f=>{
|
| 126 |
+
Object.assign(f.properties, mapData[f.properties.STT]);
|
| 127 |
+
});
|
| 128 |
+
// Chuẩn bị cho tìm kiếm
|
| 129 |
+
searchArr = features.map(f=>{
|
| 130 |
+
return {
|
| 131 |
+
name: (f.properties['Tên']||'').trim(),
|
| 132 |
+
id: f.properties['STT'],
|
| 133 |
+
type: f.properties['Loại']||'',
|
| 134 |
+
norm: normalize(f.properties['Tên']),
|
| 135 |
+
pop: f.properties['Dân số (người)']||'',
|
| 136 |
+
area: f.properties['Diện tích (km2)']||'',
|
| 137 |
+
density: f.properties['Mật độ (người/km2)']||'',
|
| 138 |
+
f
|
| 139 |
+
};
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
// Hiện nền tối, làm mờ vùng ngoài TP.HCM, nổi bật vùng TP.HCM:
|
| 143 |
+
map = L.map('map', {
|
| 144 |
+
center: [10.8,106.7], zoom: 10.3, attributionControl: false,
|
| 145 |
+
zoomControl: true, minZoom: 9, maxZoom: 17
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
// Nền tối CartoDB (dễ phân biệt vùng)
|
| 149 |
+
let tiles = L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
|
| 150 |
+
attribution: '© CartoDB',
|
| 151 |
+
subdomains: 'abcd', maxZoom: 20
|
| 152 |
+
}).addTo(map);
|
| 153 |
+
|
| 154 |
+
// Lớp ranh giới các xã/phường, mỗi xã/phường 1 màu khác
|
| 155 |
+
wardsLayer = L.geoJSON(geojson, {
|
| 156 |
+
style: f => ({
|
| 157 |
+
color: '#fff', weight: 1.2, fillOpacity: 0.71,
|
| 158 |
+
fillColor: wardColor(f.properties['Tên'])
|
| 159 |
+
}),
|
| 160 |
+
onEachFeature: (feature, layer) => {
|
| 161 |
+
layer.on({
|
| 162 |
+
mouseover: function(e) { e.target.setStyle({fillOpacity:0.95, weight:2.2}); },
|
| 163 |
+
mouseout: function(e) { wardsLayer.resetStyle(e.target); },
|
| 164 |
+
click: function(e){
|
| 165 |
+
map.closePopup();
|
| 166 |
+
if (highlightLayer) { map.removeLayer(highlightLayer);}
|
| 167 |
+
highlightLayer = L.geoJSON(feature, {
|
| 168 |
+
style:{ color:'#f9c846', weight:3, fillColor:'#f8d364', fillOpacity:0.44 }
|
| 169 |
+
}).addTo(map);
|
| 170 |
+
map.openPopup(createPopup(feature.properties), e.latlng, { className: 'shadow-sm non-serif', maxWidth:390 });
|
| 171 |
+
}
|
| 172 |
+
});
|
| 173 |
+
layer.bindTooltip((feature.properties['Loại']||'')+' '+feature.properties['Tên'],{sticky:true, direction:'top'});
|
| 174 |
+
}
|
| 175 |
+
}).addTo(map);
|
| 176 |
+
|
| 177 |
+
// Fit bản đồ vừa vùng TP.HCM (tự động, không bị lệch vùng)
|
| 178 |
+
map.fitBounds(getHCMBounds(features),{padding:[16,16]});
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// Search & UI
|
| 182 |
+
document.addEventListener('DOMContentLoaded', ()=>{
|
| 183 |
+
main();
|
| 184 |
+
const searchInput = document.getElementById('searchInput');
|
| 185 |
+
const resultsDiv = document.getElementById('searchResults');
|
| 186 |
+
searchInput.addEventListener('input', ()=>{
|
| 187 |
+
const q = normalize(searchInput.value);
|
| 188 |
+
if (q.length<2) { resultsDiv.style.display='none'; return;}
|
| 189 |
+
searchResults = searchArr.filter(e=>e.norm.includes(q)).slice(0,12);
|
| 190 |
+
resultsDiv.innerHTML = searchResults.map((e,i)=>
|
| 191 |
+
`<button class="search-item" tabindex="0" data-idx="${i}">${e.type} ${e.name}</button>`
|
| 192 |
+
).join('');
|
| 193 |
+
resultsDiv.style.display = searchResults.length ? 'block':'none';
|
| 194 |
+
currentFocus = -1;
|
| 195 |
+
});
|
| 196 |
+
resultsDiv.addEventListener('click', function(e){
|
| 197 |
+
let btn = e.target.closest('.search-item');
|
| 198 |
+
if (!btn) return;
|
| 199 |
+
let idx = +btn.getAttribute('data-idx');
|
| 200 |
+
let feature = searchResults[idx].f;
|
| 201 |
+
map.closePopup();
|
| 202 |
+
if (highlightLayer) { map.removeLayer(highlightLayer);}
|
| 203 |
+
highlightLayer = L.geoJSON(feature, {
|
| 204 |
+
style:{ color:'#f9c846', weight:3, fillColor:'#f8d364', fillOpacity:0.44 }
|
| 205 |
+
}).addTo(map);
|
| 206 |
+
map.fitBounds(highlightLayer.getBounds(),{maxZoom:15});
|
| 207 |
+
map.openPopup(createPopup(feature.properties), highlightLayer.getBounds().getCenter(), { className: 'shadow-sm non-serif', maxWidth:390 });
|
| 208 |
+
resultsDiv.style.display='none';
|
| 209 |
+
searchInput.value = searchResults[idx].name;
|
| 210 |
+
});
|
| 211 |
+
document.addEventListener('click', function(e){
|
| 212 |
+
if (!e.target.closest('.search-bar')) resultsDiv.style.display='none';
|
| 213 |
+
});
|
| 214 |
+
searchInput.addEventListener('keydown', function(e){
|
| 215 |
+
let items = resultsDiv.querySelectorAll('.search-item');
|
| 216 |
+
if (['ArrowDown','ArrowUp','Enter'].includes(e.key)){
|
| 217 |
+
if (e.key==='ArrowDown') { currentFocus = (currentFocus+1)%items.length; }
|
| 218 |
+
if (e.key==='ArrowUp') { currentFocus = (currentFocus-1+items.length)%items.length; }
|
| 219 |
+
if (e.key==='Enter' && items[currentFocus]) { items[currentFocus].click(); return;}
|
| 220 |
+
items.forEach((el,i)=>el.classList.toggle('bg-[#393a44]',i===currentFocus));
|
| 221 |
+
if (items[currentFocus]) items[currentFocus].focus();
|
| 222 |
+
}
|
| 223 |
+
});
|
| 224 |
+
});
|
| 225 |
+
</script>
|
| 226 |
+
</body>
|
| 227 |
</html>
|