`; } // 一覧:モード保存つき function indexView(list){ const switcher = `
`; const linkTo = (p, mode)=> `?pref=${p.id}&mode=${mode}`; function renderRegion(mode){ const groups = {}; for (const p of list){ const g = regionOf(p.id); (groups[g]||(groups[g]=[])).push(p); } const html = REGION_ORDER.map(g=>{ const arr = (groups[g]||[]).slice().sort((a,b)=> (jisIndex[a.id]??999) - (jisIndex[b.id]??999)); if (!arr.length) return ''; return `
${g}
${arr.map(p=>` `).join('')}
`; }).join(''); return html; } function renderNorth(mode){ const sorted = list.slice().sort((a,b)=> (jisIndex[a.id]??999) - (jisIndex[b.id]??999)); return `
${sorted.map(p=>` `).join('')}
`; } setTimeout(()=>{ const container = document.getElementById('grid'); const br = document.getElementById('btn-region'); const bn = document.getElementById('btn-north'); if (!container || !br || !bn) return; const setMode = (mode)=>{ localStorage.setItem('jpmap:mode', mode); br.classList.toggle('active', mode==='region'); bn.classList.toggle('active', mode==='north'); container.innerHTML = (mode==='north') ? renderNorth(mode) : renderRegion(mode); }; setMode(initialMode); br.addEventListener('click', ()=> setMode('region')); bn.addEventListener('click', ()=> setMode('north')); },0); const searchBox = ` `; return `${searchBox}${switcher}`; } // ルーティング描画 if (prefId){ const p = PREFS.find(x=> x.id === prefId); if (p) document.title = `${p.name}の紹介`; app.innerHTML = p ? viewCard(p) : `

該当する県が見つかりません(${prefId})。

`; } else { document.title = '都道府県一覧|紹介'; app.innerHTML = indexView(PREFS); // 検索(現在モードをURLに付与) const kw = document.getElementById('kw'); const grid = document.getElementById('grid'); kw?.addEventListener('input', () => { const k = kw.value.trim(); const f = PREFS.filter(p => { const hay = [p.name, p.capital, ...(p.famous||[]), ...(p.spots||[])].join(' '); return hay.includes(k); }); const mode = localStorage.getItem('jpmap:mode') || 'region'; const show = (k ? f : PREFS); grid.innerHTML = show.map(p=>` `).join(''); }); } })();