แผนที่จาก GPKG + บทความ 6 ชิ้น + ลดความหนา footer

== แผนที่ / GIS ==
- qgis-to-web.py: อ่าน GPKG ได้ (--from gpkg) + เพิ่ม dream-Watcharapol
- เพิ่ม dream-*.geojson 6 ไฟล์ (เส้นทางที่เสนอ: บ้านภาชี · ชานเมืองอยุธยา · HSR · เมืองทองธานี · ปากเกร็ด · วัชรพล)
- map.js: ATMap.proposal() วาดเส้นจริงจาก geojson (ไม่ใช่เส้นตรง) · smoothFactor 0.5
  · coordOf() รับ coords=[lat,lng] · fitAll รับได้ทั้งจุดเดี่ยวและเส้น · setStyle บน featureGroup

== บทความ (blog) ==
- text3: ถ้าผมได้ออกแบบสายเดินรถเอง (จาก mydream.html) TH+EN
- text4: วิธีเดินทางไปสถานีรถไฟ และสนามบิน (จาก train-airplane.html) TH+EN
- text5/text6: โครงเปล่ารอเติมเนื้อหา (แสวงหา-โพธิ์ทอง · อำเภอเข้าเมือง)
- แผนที่ความฝัน: map.groups 3 กลุ่ม · คลิกเส้น/หมุด/แถวได้ · ป้ายที่มา
- ย่อหน้า: ระยะห่าง 20px + ย่อหน้าหน้าบรรทัด 1.5em

== ตารางเดินรถ ==
- เปลี่ยนชื่อคีย์ dir_* -> direction_* ทุกไฟล์ (backward-compat ในโค้ด)
- 1011: จุดย่อย 2 ทิศ + offsets [0,25,55]
- 954/2194: จุดย่อย station 8 + offsets
- refreshHighlights: วนข้ามวันเมื่อเลยเที่ยวสุดท้าย + ไฮเทลต์ชิปทุกจุด
- 8 other_stop.md: อัปเดตตรงข้อมูลจริง 8 รายการ

== i18n ==
- แยกไฟล์ต่อภาษา ui/locales/{th,en}.json + i18n.js = loader (ลด 28KB -> 6.5KB)
- resource/tools/check-i18n.py ตรวจคีย์ขาด/ซ้ำ
- ข้อความผู้สนับสนุนหน้าแรก + คำแปล EN

== UI ==
- ฝังฟอนต์ K2D (ui/vendor/fonts/) ออฟไลน์ 100%
- cache busting ?v=<SW VERSION> ทุกรูป (ui/imageurl.js)
- footer: ลดความหนา 468 -> 349px + line-height 1.5 กันสระ/วรรณยุกต์ซ้อน
- QR modal + ปุ่มคัดลอกลิงก์ · หน้าอัปเดตล่าสุดใน #/check
- credits: ขอขอบคุณภาพรถ 3 สาย

== เครื่องมือ ==
- bump-version.py · stamp-schedules.py · derive-times.py (จุดอ้างอิง ± นาที)
This commit is contained in:
Bkk1234 committed 2026-10-05 03:55:09 +07:00
1 parent 1cfaeb1526
commit 656f65b41c
109 files changed
+3335 -1225

No files matched your search

+143 -13
View File
@@ -146,12 +146,15 @@ window.ATMap = (function () {
/* แตกเป็น "จุดจริง" ทีละจุด — ชื่อ ↔ พิกัด จับคู่ตามลำดับ (จุดที่ไม่มีพิกัด = ไม่ปักหมุด) */
var subs = (window.OtherStop && OtherStop.stopsOf) ? OtherStop.stopsOf(o) : [];
if (!subs.length) subs = [{ name: o.station_name_th, hasCoord: false, lat: null, lng: null }];
subs.forEach(function (sub) {
subs.forEach(function (sub, si) {
stops.push({
name: sub.name,
pt: sub.hasCoord ? [sub.lng, sub.lat] : null,
code: null,
note: o.note || null
note: o.note || null,
subStop: true, /* ★ จุดย่อย: ลิงก์ไปหน้ารวมจุดขึ้นรถของสายนี้ */
subRoute: String(route.route_id),
subFirst: si === 0 /* จุดแรก = จุดอ้างอิง (อยู่บน timetable แล้ว) */
});
});
});
@@ -172,6 +175,7 @@ window.ATMap = (function () {
var km = fromEnd ? total - k.km : k.km;
s.off = k.d > OFF_ROUTE_M;
s.km = Math.max(0, km).toFixed(1);
if (s.subStop) s.sub = true; /* คงธงจุดย่อยไว้ให้ตัววาดหมุด */
});
return stops;
}
@@ -236,7 +240,11 @@ window.ATMap = (function () {
}
function fitAll(map, latlngs) {
var all = [];
latlngs.forEach(function (l) { all = all.concat(l); });
latlngs.forEach(function (l) {
/* รับได้ทั้ง "เส้น" ([ [lat,lng], ... ]) และ "จุดเดี่ยว" ([lat, lng]) */
if (l && typeof l[0] === 'number' && typeof l[1] === 'number') all.push([l[0], l[1]]);
else if (l && l.length) all = all.concat(l);
});
if (!all.length) return;
var rec = mapsFor(map);
if (all.length === 1) {
@@ -301,6 +309,23 @@ window.ATMap = (function () {
});
}
/* จุดย่อยของ "จุดขึ้นรถประจำทางอื่นๆ" (จาก 8 other_stop.json) — ปักหมุดสี่เหลี่ยมม่วง
คลิก = popup ชื่อ + กม. + ลิงก์ไปหน้ารวมจุดขึ้นรถของสายนั้น */
function drawSubStops(map, rows, routeId, group) {
(rows || []).forEach(function (r) {
if (!r.sub || !r.pt) return;
var html = '<div class="at-pop"><b>' + esc(r.name) + '</b>';
html += '<span>' + esc(t('map.subStop')) + (r.km != null && r.km !== '' ? ' · ' + esc(r.km) + ' กม.' : '') + '</span>';
if (r.href) html += '<a href="' + esc(r.href) + '">' + esc(t('map.viewBoardingPoints')) + '</a>';
html += '</div>';
L.marker([r.pt[1], r.pt[0]], { icon: pinIcon('sub'), zIndexOffset: 400 })
.bindTooltip(esc(r.name), { direction: 'top', offset: [0, -8] })
.bindPopup(html, { closeButton: false, offset: [0, -6] })
.addTo(group);
});
}
/* สถานีของเรา: ชื่อ + คลิกไปหน้ารายละเอียดป้าย (opts.stopHref) */
function drawStations(map, hits, opts, group) {
hits.forEach(function (h) {
@@ -317,10 +342,15 @@ window.ATMap = (function () {
});
}
function stationsNear(lines, maxM, o) {
/* สถานีที่จะปักหมุด (ไอคอนเหลือง)
- allowedIds = routes.json → station_ids ของสายนั้น (ปักเฉพาะที่ระบุไว้ — ให้ตรงกับตาราง)
- ไม่ส่ง allowedIds = พฤติกรรมเดิม (ปักทุกสถานีที่อยู่ใกล้เส้น) */
function stationsNear(lines, maxM, o, allowedIds) {
return stationList(o).then(function (list) {
var hits = [];
var allow = (allowedIds && allowedIds.length) ? allowedIds.map(String) : null;
list.forEach(function (s) {
if (allow && allow.indexOf(String(s.station_id)) === -1) return; /* ไม่อยู่ในสายนี้ → ไม่ปัก */
var pt = pointOf(s);
if (!pt) return;
var best = Infinity;
@@ -366,7 +396,7 @@ window.ATMap = (function () {
var li = document.createElement('li');
var row = document.createElement(x.href ? 'a' : 'div');
if (x.href) row.href = x.href;
row.className = 'at-km-row' + (x.href ? '' : ' is-plain');
row.className = 'at-km-row' + (x.href ? '' : ' is-plain') + (x.sub ? ' is-sub' : '');
if (x.note) row.title = x.note;
var val = x.off ? '<span class="is-off">' + esc(t('map.offRoute')) + '</span>'
: (x.km === null || x.km === '' ? '–' : x.km + ' ' + esc(t('map.km')));
@@ -406,21 +436,28 @@ window.ATMap = (function () {
.bindTooltip(esc(e[1]), { direction: 'top', offset: [0, -8] }).addTo(group);
});
Promise.all([stopsNear(lines, opts), stationsNear(lines, STATION_NEAR_M, opts),
stationList(opts), routeList(opts), otherStopList(opts)]).then(function (res) {
var shelters = res[0], sts = res[1], stations = res[2], routesDoc = res[3], others = res[4];
Promise.all([stopsNear(lines, opts), routeList(opts),
stationList(opts), otherStopList(opts)]).then(function (res) {
var shelters = res[0], routesDoc = res[1], stations = res[2], others = res[3];
var routeDoc = (routesDoc || []).filter(function (r) { return String(r.route_id) === String(routeId); })[0];
var allowed = routeDoc ? (routeDoc.station_ids || []) : null; /* ★ ปักเฉพาะสถานีที่สายระบุ */
drawShelters(map, shelters, group);
drawStations(map, sts, opts, group);
stationsNear(lines, STATION_NEAR_M, opts, allowed).then(function (sts) {
drawStations(map, sts, opts, group);
});
fitAll(map, latlngs);
/* จุดจอดตามเส้นทาง + กม. จากต้นทาง — ใช้ routes.json → station_ids เป็นหลัก
(station 8 → จับคู่ route_id ใน 8 other_stop.json) ถ้าหา route ไม่ได้จึงใช้ระยะใกล้เส้นแบบเดิม */
var main = longest(lines);
var route = (routesDoc || []).filter(function (r) { return String(r.route_id) === String(routeId); })[0];
var route = routeDoc;
var rows;
if (route && (route.station_ids || []).length) {
rows = routeStopRows(route, stations, others, main, (routesDoc || []).map(function (r) { return String(r.route_id); })).map(function (x) {
return { name: x.name, km: x.km, off: x.off, note: x.note, href: x.code ? href(opts, x.code) : null };
/* จุดย่อย → ลิงก์ไป #/stops/other_stop?route=<รหัสสาย> (หน้ารวมจุดขึ้นรถของสายนั้น) */
var linkHref = x.code ? href(opts, x.code)
: (x.subStop ? '#/stops/other_stop?route=' + encodeURIComponent(x.subRoute) : null);
return { name: x.name, km: x.km, off: x.off, note: x.note, href: linkHref, sub: !!x.subStop };
}).sort(function (a, b) { /* เรียงตาม กม. ตามเส้นทาง (อ่านเป็นเส้นทางเดินรถ) */
if (a.km === null || a.km === '') return 1;
if (b.km === null || b.km === '') return -1;
@@ -433,6 +470,8 @@ window.ATMap = (function () {
}).sort(function (a, b) { return parseFloat(a.km) - parseFloat(b.km); });
}
renderKmList('route-map-list', rows);
drawSubStops(map, routeStopRows(route, stations, others, main,
(routesDoc || []).map(function (r) { return String(r.route_id); })), route.route_id, group);
var parts = ['<b>' + esc(routeId) + '</b> · ' + esc(t('map.captionRoute', { km: lineLengthKm(lines).toFixed(1), n: shelters.length }))];
if (rows.length) parts.push(esc(t('map.stations')) + ' <b>' + rows.length + '</b>');
@@ -443,7 +482,8 @@ window.ATMap = (function () {
legend(el, [
{ color: LINE_MAIN, label: t('map.legendRoute') },
{ color: '#1f7a3d', square: true, label: t('map.legendStop') },
{ color: '#f2a900', square: true, label: t('map.legendTerminal') }
{ color: '#f2a900', square: true, label: t('map.legendTerminal') },
{ color: '#7a4cc0', square: true, label: t('map.legendSubStop') }
]);
});
}
@@ -626,8 +666,98 @@ window.ATMap = (function () {
map.fitBounds(L.latLngBounds(pts), { padding: [28, 28] });
}
/* ---------- แผนที่ "เส้นทางที่เสนอ" (ยังไม่มีจริง — วาดจากโครงข้อมูลที่ผู้ใช้กำหนด) ----------
spec = { origin:{lat,lng,label}, routes:[{ id, line_color, line_name,
dest:{name,lat,lng}, via:[{name,lat,lng}] }] }
เส้นที่ยังไม่ใส่พิกัดปลายทาง = ข้ามการวาด (ไปโผล่ในรายการฝั่งผู้เรียกแทน)
onPick(route) เรียกเมื่อคลิกเส้น/จุด — ผู้เรียกเป็นคนแสดงรายละเอียดเอง */
/* อ่านพิกัดจากได้ทั้ง 2 แบบ: coords = [lat, lng] (แบบใหม่) หรือ lat/lng แยก (แบบเดิม) */
function coordOf(o) {
o = o || {};
if (Array.isArray(o.coords) && o.coords.length >= 2) {
var a = num(o.coords[0]), b = num(o.coords[1]);
return (a == null || b == null) ? null : [a, b];
}
var la = num(o.lat), ln = num(o.lng);
return (la == null || ln == null) ? null : [la, ln];
}
function proposal(el, spec, onPick) {
var mk = makeMap(el), map = mk.map;
var group = L.featureGroup().addTo(map);
var pts = [];
var o = spec.origin || {};
var org = coordOf(o);
if (!org) { return { map: map, empty: true }; }
pts.push(org);
L.circleMarker(org, { radius: 8, color: '#fff', weight: 3, fillColor: '#1f2a44', fillOpacity: 1 })
.bindTooltip(esc(o.label || 'ต้นทาง'), { permanent: true, direction: 'top', offset: [0, -8], className: 'at-tip-org' })
.addTo(group);
var pending = []; /* เส้นที่พิกัดปลายทางมาจาก geojson (โหลด async) */
(spec.routes || []).forEach(function (r) {
var d = r.dest || {};
if (r.geo_id) { /* มีไฟล์เส้นทาง → โหลดเพื่อวาดเส้นจริง */
pending.push(loadGeo(r.geo_id, spec).then(function (geo) {
var ls = flatten(geo);
r.__shape = toLatLngs(ls); /* ★ เส้นจริงจาก geojson (วาดตามที่ลากใน QGIS) */
if (!coordOf(d)) { /* dest ยังไม่มีพิกัด → เดาจากจุดไกลสุดของเส้น */
var ps = [];
ls.forEach(function (l) { if (l && l.length) { ps.push(l[0]); ps.push(l[l.length - 1]); } });
if (!ps.length) return;
var ref = ps[0], far = ps[0], best = -1;
ps.forEach(function (pt) {
var dd = Math.pow(num(pt[0]) - num(ref[0]), 2) + Math.pow(num(pt[1]) - num(ref[1]), 2);
if (dd > best) { best = dd; far = pt; }
});
d.coords = [num(far[1]), num(far[0])]; /* geojson = [lng, lat] → [lat, lng] */
}
r.__geoOk = true;
}).catch(function () { /* อ่านไม่ได้ → ใช้ coords ที่มี (ถ้ามี) */ }));
}
});
var drawAll = function () {
(spec.routes || []).forEach(function (r) {
var d = r.dest || {};
var dl = coordOf(d);
if (!dl) return; /* ยังไม่มีพิกัด → ข้าม */
var col = r.line_color || '#7a4cc0';
/* เส้นจริงจาก geojson (ถ้ามี) → วาดตามเส้นที่ลากไว้ · ไม่มี → เส้นตรงต้นทาง→ปลายทาง + จุดแวะ */
var segs = (r.__shape && r.__shape.length) ? r.__shape : [[org].concat(
(r.via || []).map(coordOf).filter(Boolean), dl)];
/* smoothFactor 0.5 = ลดจุดน้อยลง (ค่าเริ่มต้น Leaflet = 1.0 ทำให้เส้นดูตรงตอนซูมออก) */
var line = L.featureGroup(segs.map(function (seg) {
return L.polyline(seg, { color: col, weight: 4, opacity: .85, dashArray: '10 8', smoothFactor: 0.5 });
})).addTo(group);
/* FeatureGroup ไม่มี setStyle → แนบ helper ให้ผู้เรียกใช้ได้เหมือน polyline เดี่ยว */
line.setStyle = function (st) { this.eachLayer(function (l) { l.setStyle(st); }); return this; };
var dot = L.circleMarker(dl, { radius: 7, color: '#fff', weight: 2, fillColor: col, fillOpacity: 1 })
.bindTooltip(esc(d.name || ''), { direction: 'top', offset: [0, -6] }).addTo(group);
pts.push(dl);
function pick(e) {
if (e && e.originalEvent) L.DomEvent.stopPropagation(e);
if (onPick) onPick(r, { line: line, dot: dot });
}
line.on('click', pick);
dot.on('click', pick);
r.__layer = { line: line, dot: dot }; /* ให้ผู้เรียกไฮไลต์ได้ */
});
};
/* มีเส้นที่ต้องอ่านพิกัดจาก geojson → รอให้ครบก่อนวาด · ไม่มี → วาดเลย */
(pending.length ? Promise.all(pending) : Promise.resolve()).then(function () {
drawAll();
fitAll(map, pts);
setTimeout(function () { map.invalidateSize(); }, 60);
});
return { map: map, group: group };
}
return {
route: route, forStop: forStop, nearMe: nearMe,
route: route, forStop: forStop, proposal: proposal, nearMe: nearMe,
NEAR_M: NEAR_M, LINE_MAIN: LINE_MAIN,
maps: MAPS /* ไว้ตรวจสอบ/ทดสอบจากคอนโซล */
};