Upload deploy/globe/app.js with huggingface_hub
Browse files30 unmodified lines31323334353637262 unmodified lines30030130230330430549 unmodified lines35535635735835936078 unmodified lines439440441442443444172 unmodified lines61761861962062162213 unmodified lines63663763863964064164271 unmodified lines714715716717718719720721722723724725726727105 unmodified lines8338348358368378384 unmodified lines8438448458468478488498508518528538548558568571 unmodified line859860861862863864157 unmodified lines10221023102410251026102710281 unmodified line1030103110321033103410354 unmodified lines1040104110421043104410451046104716 unmodified lines106410651066106710681069107010711072107310741 unmodified line1076107710781079108010811 unmodified line10831084108510861087108830 unmodified lines];const state = { summary: null, events: [], news: [], cdhe: null, hours: 24, markers: [], cLabels: [],disasters: [], fires: { type: 'FeatureCollection', features: [] },pulses: [], countries: null, feed: 'news', region: '全球' };const domain = (u) => { try { return new URL(u).hostname.replace(/^www\./, ''); } catch (e) { return ''; } };const fmt = (n) => (n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e4 ? (n / 1e3).toFixed(1) + 'k' : String(n));262 unmodified linesaddDisasters();addFires();addSats();addLabels();}49 unmodified lines} });}const SAT = { items: [], timer: null };const SATC = { stations: '#eaf4ff', 'gps-ops': '#ffd166', weather: '#6fd3ff' };78 unmodified linesfunction applyBasemode(m) {const night = m === 'night', relief = m === 'relief';if (map.getLayer('base-night')) map.setLayoutProperty('base-night', 'visibility', night ? 'visible' : 'none');if (map.getLayer('base-relief')) map.setLayoutProperty('base-relief', 'visibility', relief ? 'visible' : 'none');if (map.getLayer('ocean')) map.setLayoutProperty('ocean', 'visibility', m === 'plain' ? 'visible' : 'none');if (map.getLayer('c-fill')) {172 unmodified linesif (map.getLayer(id)) map.setLayoutProperty(id, 'visibility',document.getElementById('l-fires').checked ? 'visible' : 'none');});const sf = satFilter();['sat-glow', 'sat-dot'].forEach((id) => { if (map.getLayer(id)) map.setFilter(id, sf); });updateLabelOpacity();13 unmodified lines}));document.querySelectorAll('#basemode .chip').forEach((c) =>c.addEventListener('click', () => applyBasemode(c.dataset.m)));document.querySelectorAll('#basetog .chip, #distog .chip').forEach((c) =>c.addEventListener('click', () => {const box = document.getElementById(c.dataset.for);if (!box) return;71 unmodified lines}function renderRank() {const list = state.summary.top_countries.slice(0, 14);const max = list[0].epi;$('rank').innerHTML = list.map((c, i) => `<div class="rk" data-f="${c.f}" title="飞到 ${c.cc}"><span class="i">${String(i + 1).padStart(2, '0')}</span><span class="nm">${c.cc}</span><span class="tr"><span class="fl" style="width:${(c.epi / max) * 100}%"></span></span><span class="v">${Math.round(c.epi).toLocaleString()}</span></div>`).join('');document.querySelectorAll('.rk').forEach((el) => {el.addEventListener('click', () => {105 unmodified lines<div class="m2">${p.m} 提及 · 语气 ${p.t != null ? Number(p.t).toFixed(1) : '—'} · ${d || 'GDELT'}</div></div>`;}).join('')) || '<div style="color:#3d4c60;padding:16px 2px;font-size:11px">该时间窗内无可展示事件</div>';document.querySelectorAll('#feed .ev').forEach((el) => {el.addEventListener('click', () => {4 unmodified lines});}function renderNews() {const list = (state.news || []).slice(0, 80);const day = 86400;$('feed').innerHTML = list.map((n) => {const c = NCAT[n.cat] || NCAT['其他'];const ago = Math.max(0, Math.round((Date.now() / 1000 - n.ts) / 60));const when = ago < 60 ? ago + ' 分钟前' : Math.round(ago / 60) + ' 小时前';return `<div class="ev" data-u="${encodeURIComponent(n.u)}" style="--c:${c}"><div class="m1"><span class="c">${n.cat}</span><span>${n.src}</span><span class="t">${when}</span></div><div class="tt">${n.t}</div></div>`;}).join('') || '<div style="color:#3d4c60;padding:16px 2px;font-size:11px">暂无要闻</div>';1 unmodified linedocument.querySelectorAll('#feed .ev').forEach((el) => {el.addEventListener('click', () => window.open(decodeURIComponent(el.dataset.u), '_blank', 'noopener'));});}function bindFeedTabs() {157 unmodified lines/* ---------------- 启动 ---------------- */async function loadAll() {const t = Date.now();const [sum, ev, cd, hl, satd, dis, fir] = await Promise.all([fetch(DATA + 'summary.json?t=' + t).then((r) => r.json()),fetch(DATA + 'events.json?t=' + t).then((r) => r.json()),fetch(DATA + 'cdhe.json?t=' + t).then((r) => r.json()),1 unmodified linefetch(DATA + 'satellites.json?t=' + t).then((r) => r.json()).catch(() => ({ satellites: [] })),fetch(DATA + 'disasters.json?t=' + t).then((r) => r.json()).catch(() => ({ events: [] })),fetch(DATA + 'fires.json?t=' + t).then((r) => r.json()).catch(() => ({ points: [] })),]);state.summary = sum; state.events = ev.points; state.cdhe = cd;state.news = hl.items || [];4 unmodified linesconst disEl = document.getElementById('n-dis');if (disEl) disEl.textContent = state.disasters.length + ' / ' + state.fires.features.length;if (satd && satd.satellites) initSats(satd);const satEl = document.getElementById('n-sat');if (satEl) satEl.textContent = SAT.items.length + ' 颗';window.__state = state;if (!state.countries) {const gj = await fetch(DATA + 'countries.geojson').then((r) => r.json());16 unmodified linesaddLayers();applyBasemode(document.querySelector('#basemode .chip.on').dataset.m || 'relief');startSats();bindToggles();addCountryLabels();bindMap();bindHover();bindFeedTabs();refreshFilters();refreshPulses();applyPadding();1 unmodified line};if (map.isStyleLoaded()) init(); else map.once('load', init);setInterval(async () => {try {await loadAll();1 unmodified lineif (map.getSource('cdhe')) map.getSource('cdhe').setData(cdheFeatures());if (map.getSource('disasters')) map.getSource('disasters').setData(disasterFC());if (map.getSource('fires')) map.getSource('fires').setData(state.fires);renderTop(); renderRank(); renderSpark(); refreshFilters();} catch (e) { console.warn('刷新失败', e); }}, 300000);30 unmodified lines31323334353637262 unmodified lines30030130230330430530649 unmodified lines35635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942078 unmodified lines499500501502503504505172 unmodified lines67867968068168268368468568668768868913 unmodified lines70370470570670770870971 unmodified lines781782783784785786787788789790791792793794795796797798799800801802105 unmodified lines9089099109119129139144 unmodified lines9199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549551 unmodified line957958959960961962963964965966967968969970971972973974157 unmodified lines11321133113411351136113711381 unmodified line11401141114211431144114511464 unmodified lines11511152115311541155115611571158115916 unmodified lines1176117711781179118011811182118311841185118611871188118911901191119211931 unmodified line1195119611971198119912001201120212031204120512061207120812091210121112121 unmodified line121412151216121712181219122030 unmodified lines];const state = { summary: null, events: [], news: [], cdhe: null, hours: 24, markers: [], cLabels: [],disasters: [], fires: { type: 'FeatureCollection', features: [] }, flights: [], rank: 'epi', feedTop: null,pulses: [], countries: null, feed: 'news', region: '全球' };const domain = (u) => { try { return new URL(u).hostname.replace(/^www\./, ''); } catch (e) { return ''; } };const fmt = (n) => (n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e4 ? (n / 1e3).toFixed(1) + 'k' : String(n));262 unmodified linesaddDisasters();addFires();addFlights();addSats();addLabels();}49 unmodified lines} });}const FL = { rows: [], t0: 0, timer: null };function initFlights(data) {FL.rows = data.flights || [];FL.t0 = data.generated || Date.now() / 1000;}/* 两次拉取之间用速度与航向做推算,让目标真的在动而不是每 20 分钟跳一次 */function flightFC() {const now = Date.now() / 1000;const dt = Math.min(Math.max(now - FL.t0, 0), 1800);const feats = new Array(FL.rows.length);for (let i = 0; i < FL.rows.length; i++) {const r = FL.rows[i];const rad = (r[4] * Math.PI) / 180;const lat = r[1] + (r[3] * Math.cos(rad) * dt) / 111320;const cosLat = Math.cos((lat * Math.PI) / 180) || 0.01;let lon = r[0] + (r[3] * Math.sin(rad) * dt) / (111320 * cosLat);if (lon > 180) lon -= 360;if (lon < -180) lon += 360;feats[i] = { type: 'Feature', geometry: { type: 'Point', coordinates: [lon, lat] },properties: { c: r[5], o: r[6], a: r[2], v: r[3], q: r[7] } };}return { type: 'FeatureCollection', features: feats };}function addFlights() {map.addSource('flights', { type: 'geojson', data: flightFC() });map.addLayer({ id: 'fl-air', type: 'circle', source: 'flights',filter: ['!', ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]]],paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'], 1, 1.1, 3, 1.7, 5, 2.5, 7, 3.8],'circle-color': '#a9d8f5','circle-opacity': 0.62,} });map.addLayer({ id: 'fl-em', type: 'circle', source: 'flights',filter: ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]],paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'], 1, 3, 5, 6],'circle-color': '#ff5040', 'circle-opacity': 0.9,'circle-stroke-width': 1, 'circle-stroke-color': 'rgba(255,179,168,.8)',} });}function startFlights() {const tick = () => {const src = map.getSource('flights');if (!src) return;if (!document.getElementById('l-flights').checked) return;const fc = flightFC();src.setData(fc);window.__flt = { n: (window.__flt ? window.__flt.n : 0) + 1,p: fc.features.length ? fc.features[0].geometry.coordinates : null };};tick();if (FL.timer) clearInterval(FL.timer);FL.timer = setInterval(tick, 2500);}const SAT = { items: [], timer: null };const SATC = { stations: '#eaf4ff', 'gps-ops': '#ffd166', weather: '#6fd3ff' };78 unmodified linesfunction applyBasemode(m) {const night = m === 'night', relief = m === 'relief';if (map.getLayer('base-night')) map.setLayoutProperty('base-night', 'visibility', night ? 'visible' : 'none');// 真彩底图有轨道缝隙,垫一层晕渲,缝里露地表而不是黑洞if (map.getLayer('base-relief')) map.setLayoutProperty('base-relief', 'visibility', relief ? 'visible' : 'none');if (map.getLayer('ocean')) map.setLayoutProperty('ocean', 'visibility', m === 'plain' ? 'visible' : 'none');if (map.getLayer('c-fill')) {172 unmodified linesif (map.getLayer(id)) map.setLayoutProperty(id, 'visibility',document.getElementById('l-fires').checked ? 'visible' : 'none');});['fl-air', 'fl-em'].forEach((id) => {if (map.getLayer(id)) {map.setLayoutProperty(id, 'visibility',document.getElementById('l-flights').checked ? 'visible' : 'none');}});const sf = satFilter();['sat-glow', 'sat-dot'].forEach((id) => { if (map.getLayer(id)) map.setFilter(id, sf); });updateLabelOpacity();13 unmodified lines}));document.querySelectorAll('#basemode .chip').forEach((c) =>c.addEventListener('click', () => applyBasemode(c.dataset.m)));document.querySelectorAll('#basetog .chip, #distog .chip, #movetog .chip').forEach((c) =>c.addEventListener('click', () => {const box = document.getElementById(c.dataset.for);if (!box) return;71 unmodified lines}function renderRank() {const key = state.rank || 'epi';const list = (state.summary.all_countries || []).slice().sort((a, b) => (b[key] || 0) - (a[key] || 0)).slice(0, 14);const max = Math.max(1, list[0] ? list[0][key] : 1);const note = document.getElementById('rnote');if (note) {note.textContent = key === 'cepi'? '冲突 = 武装袭击 + 大规模暴力 + 军事部署(24h)': 'EPI = Σ 类别权重 × 事件数(24h)';}$('rank').innerHTML = list.map((c, i) => `<div class="rk" data-f="${c.f}" title="飞到 ${c.cc}"><span class="i">${String(i + 1).padStart(2, '0')}</span><span class="nm">${c.cc}</span><span class="tr"><span class="fl" style="width:${((c[key] || 0) / max) * 100}%"></span></span><span class="v">${Math.round(c[key] || 0).toLocaleString()}</span></div>`).join('');document.querySelectorAll('.rk').forEach((el) => {el.addEventListener('click', () => {105 unmodified lines<div class="m2">${p.m} 提及 · 语气 ${p.t != null ? Number(p.t).toFixed(1) : '—'} · ${d || 'GDELT'}</div></div>`;}).join('')) || '<div style="color:#3d4c60;padding:16px 2px;font-size:11px">该时间窗内无可展示事件</div>';feedStamp();document.querySelectorAll('#feed .ev').forEach((el) => {el.addEventListener('click', () => {4 unmodified lines});}function agoText(ts) {const m = Math.max(0, Math.round((Date.now() / 1000 - ts) / 60));if (m < 1) return '刚刚';return m < 60 ? m + ' 分钟前' : Math.round(m / 60) + ' 小时前';}function feedStamp() {const el = document.getElementById('feed-upd');if (!el) return;const d = new Date();el.textContent = String(d.getHours()).padStart(2, '0') + ':' +String(d.getMinutes()).padStart(2, '0') + ' 更新';}function markNew(topKey) {const first = document.querySelector('#feed .ev');if (!first) return;if (state.feedTop && topKey && topKey !== state.feedTop) {first.classList.add('new');setTimeout(() => first.classList.remove('new'), 1200);}if (topKey) state.feedTop = topKey;}function renderNews() {const list = (state.news || []).slice(0, 80);$('feed').innerHTML = list.map((n) => {const c = NCAT[n.cat] || NCAT['其他'];return `<div class="ev" data-u="${encodeURIComponent(n.u)}" style="--c:${c}"><div class="m1"><span class="c">${n.cat}</span><span>${n.src}</span><span class="t" data-rel="1" data-ts="${n.ts}">${agoText(n.ts)}</span></div><div class="tt">${n.t}</div></div>`;}).join('') || '<div style="color:#3d4c60;padding:16px 2px;font-size:11px">暂无要闻</div>';1 unmodified linedocument.querySelectorAll('#feed .ev').forEach((el) => {el.addEventListener('click', () => window.open(decodeURIComponent(el.dataset.u), '_blank', 'noopener'));});feedStamp();markNew('n:' + (list[0] ? list[0].t : ''));}function bindRankTabs() {document.querySelectorAll('#rankTabs b').forEach((b) => {b.addEventListener('click', () => {state.rank = b.dataset.v;document.querySelectorAll('#rankTabs b').forEach((x) => x.classList.toggle('on', x === b));renderRank();});});}function bindFeedTabs() {157 unmodified lines/* ---------------- 启动 ---------------- */async function loadAll() {const t = Date.now();const [sum, ev, cd, hl, satd, dis, fir, flt] = await Promise.all([fetch(DATA + 'summary.json?t=' + t).then((r) => r.json()),fetch(DATA + 'events.json?t=' + t).then((r) => r.json()),fetch(DATA + 'cdhe.json?t=' + t).then((r) => r.json()),1 unmodified linefetch(DATA + 'satellites.json?t=' + t).then((r) => r.json()).catch(() => ({ satellites: [] })),fetch(DATA + 'disasters.json?t=' + t).then((r) => r.json()).catch(() => ({ events: [] })),fetch(DATA + 'fires.json?t=' + t).then((r) => r.json()).catch(() => ({ points: [] })),fetch(DATA + 'flights.json?t=' + t).then((r) => r.json()).catch(() => ({ flights: [] })),]);state.summary = sum; state.events = ev.points; state.cdhe = cd;state.news = hl.items || [];4 unmodified linesconst disEl = document.getElementById('n-dis');if (disEl) disEl.textContent = state.disasters.length + ' / ' + state.fires.features.length;if (satd && satd.satellites) initSats(satd);if (flt && flt.flights) initFlights(flt);const satEl = document.getElementById('n-sat');if (satEl) satEl.textContent = SAT.items.length + ' / ' + (FL.rows.length / 1000).toFixed(1) + 'k';window.__state = state;if (!state.countries) {const gj = await fetch(DATA + 'countries.geojson').then((r) => r.json());16 unmodified linesaddLayers();applyBasemode(document.querySelector('#basemode .chip.on').dataset.m || 'relief');startSats();startFlights();bindToggles();addCountryLabels();bindMap();bindHover();bindFeedTabs();bindRankTabs();setInterval(() => {document.querySelectorAll('#feed .t[data-rel]').forEach((el) => {el.textContent = agoText(Number(el.dataset.ts));});}, 20000);refreshFilters();refreshPulses();applyPadding();1 unmodified line};if (map.isStyleLoaded()) init(); else map.once('load', init);// 要闻单独快轮询:2 分钟一次,有新条目就滑入setInterval(async () => {try {const r = await fetch(DATA + 'headlines.json?t=' + Date.now());const j = await r.json();if (j && j.items && j.items.length) {state.news = j.items;if (state.feed === 'news') renderNews();}} catch (e) { /* 静默 */ }}, 120000);setInterval(async () => {try {await loadAll();1 unmodified lineif (map.getSource('cdhe')) map.getSource('cdhe').setData(cdheFeatures());if (map.getSource('disasters')) map.getSource('disasters').setData(disasterFC());if (map.getSource('fires')) map.getSource('fires').setData(state.fires);if (map.getSource('flights')) map.getSource('flights').setData(flightFC());renderTop(); renderRank(); renderSpark(); refreshFilters();} catch (e) { console.warn('刷新失败', e); }}, 300000);
deploy/globe/app.js+144-12