Upload deploy/globe/app.js with huggingface_hub
Browse files355 unmodified lines3563573583593603613623633643653663673688 unmodified lines37737837938038138238332 unmodified lines4164174184194204214224234244254264274286 unmodified lines4354364374384394404414 unmodified lines4464474484494504513 unmodified lines45545645745845946046121 unmodified lines4834844854864874884894904912 unmodified lines49449549649749849950050150250350450550650750850951021 unmodified lines532533534535536537538178 unmodified lines7177187197207217222 unmodified lines725726727728729730731406 unmodified lines11381139114011411142114349 unmodified lines119311941195119611971198119955 unmodified lines125512561257125812591260355 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;8 unmodified linesif (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], t: r[4], s: i % 3 === 0 ? 1 : 0 } };}return { type: 'FeatureCollection', features: feats };}32 unmodified linesfilter: ['!', ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]]],layout: {'icon-image': 'plane-icon','icon-size': ['interpolate', ['linear'], ['zoom'], 1, 0.34, 3, 0.52, 5, 0.74, 7, 0.95],'icon-rotate': ['get', 't'],'icon-rotation-alignment': 'map','icon-allow-overlap': true,'icon-ignore-placement': true,},paint: { 'icon-opacity': ['interpolate', ['linear'], ['zoom'], 1, 0.42, 3, 0.58, 5, 0.7] } });map.addLayer({ id: 'fl-em', type: 'circle', source: 'flights',filter: ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]],paint: {6 unmodified linesfunction setFlightFilter() {if (!map.getLayer('fl-air')) return;const base = ['!', ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]]];map.setFilter('fl-air', map.getZoom() < 2.6 ? ['all', base, ['==', ['get', 's'], 1]] : base);}function startFlights() {4 unmodified linesif (!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 };};3 unmodified lines}const SAT = { items: [], timer: null };const SATC = { stations: '#eaf4ff', 'gps-ops': '#ffd166', weather: '#6fd3ff' };function initSats(data) {SAT.items = (data.satellites || []).map((s) => {21 unmodified linesfunction satFilter() {if (!document.getElementById('l-sat').checked) return ['==', ['get', 'g'], '__off'];const on = ['stations'];if (document.getElementById('l-sat-gps').checked) on.push('gps-ops');if (document.getElementById('l-sat-wx').checked) on.push('weather');return ['in', ['get', 'g'], ['literal', on]];}2 unmodified linesfunction addSats() {map.addSource('sats', { type: 'geojson', data: { type: 'FeatureCollection', features: [] } });map.addLayer({ id: 'sat-glow', type: 'circle', source: 'sats',paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'],1, ['*', 4, ISSK], 4, ['*', 9, ISSK], 7, ['*', 15, ISSK]],'circle-color': ['match', ['get', 'g'], 'stations', SATC.stations, 'gps-ops', SATC['gps-ops'], 'weather', SATC.weather, '#9fb6cc'],'circle-opacity': 0.14, 'circle-blur': 1.1,} });map.addLayer({ id: 'sat-dot', type: 'circle', source: 'sats',paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'],1, ['*', 1.3, ISSK], 4, ['*', 2.4, ISSK], 7, ['*', 3.6, ISSK]],'circle-color': ['match', ['get', 'g'], 'stations', SATC.stations, 'gps-ops', SATC['gps-ops'], 'weather', SATC.weather, '#9fb6cc'],'circle-opacity': 0.95,'circle-stroke-width': 0.5, 'circle-stroke-color': 'rgba(255,255,255,.55)',} });21 unmodified lines};tick();if (SAT.timer) clearInterval(SAT.timer);SAT.timer = setInterval(tick, 1000);}function applyBasemode(m) {178 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',2 unmodified lines});setFlightFilter();const sf = satFilter();['sat-glow', 'sat-dot'].forEach((id) => { if (map.getLayer(id)) map.setFilter(id, sf); });updateLabelOpacity();renderFeed();}406 unmodified lines});map.on('mouseleave', 'fire-pt', () => dpop.remove());const spop = new maplibregl.Popup({ closeButton: false, closeOnClick: false, offset: 8, maxWidth: '220px' });map.on('mousemove', 'sat-dot', (e) => {const f = e.features && e.features[0];49 unmodified linesif (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());55 unmodified linesif (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);355 unmodified lines3563573583593603613623633643653663673683693703713723733743753763773783793803813823833848 unmodified lines39339439539639739839932 unmodified lines4324334344354364374384394404414424434444454464474484494504514524536 unmodified lines4604614624634644654664674684694704 unmodified lines4754764774784794804814823 unmodified lines48648748848949049149249321 unmodified lines5155165175185195205215225235242 unmodified lines52752852953053153253353453553653753853954054154254354454554654754854955055155255321 unmodified lines575576577578579580581178 unmodified lines7607617627637647657667677687697707712 unmodified lines774775776777778779780781782406 unmodified lines11891190119111921193119411951196119711981199120012011202120312041205120649 unmodified lines1256125712581259126012611262126355 unmodified lines1319132013211322132313241325355 unmodified lines} });}const FL = { rows: [], mil: [], t0: 0, timer: null };function initFlights(data) {FL.rows = data.flights || [];FL.mil = data.mil || [];FL.t0 = data.generated || Date.now() / 1000;}function milFC() {const now = Date.now() / 1000;const dt = Math.min(Math.max(now - FL.t0, 0), 1800);return { type: 'FeatureCollection', features: FL.mil.map((r) => {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;return { type: 'Feature', geometry: { type: 'Point', coordinates: [lon, lat] },properties: { c: r[5], t: r[6], a: r[2], h: r[7] } };}) };}/* 两次拉取之间用速度与航向做推算,让目标真的在动而不是每 20 分钟跳一次 */function flightFC() {const now = Date.now() / 1000;8 unmodified linesif (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], t: r[4], s: i % 3 === 0 ? 1 : 0, i } };}return { type: 'FeatureCollection', features: feats };}32 unmodified linesfilter: ['!', ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]]],layout: {'icon-image': 'plane-icon','icon-size': ['interpolate', ['linear'], ['zoom'], 1, 0.34, 3, 0.56, 5, 0.82, 7, 1.0],'icon-rotate': ['get', 't'],'icon-rotation-alignment': 'map','icon-allow-overlap': true,'icon-ignore-placement': true,},paint: { 'icon-opacity': ['interpolate', ['linear'], ['zoom'], 1, 0.38, 3, 0.5, 5, 0.62, 7, 0.72] } });map.addSource('mil', { type: 'geojson', data: milFC() });map.addLayer({ id: 'mil-pt', type: 'circle', source: 'mil',paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'], 1, 2.6, 4, 4, 7, 6],'circle-color': 'rgba(255,140,60,.14)','circle-stroke-width': 1.1,'circle-stroke-color': '#ff9c4a','circle-stroke-opacity': 0.9,} });map.addLayer({ id: 'fl-em', type: 'circle', source: 'flights',filter: ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]],paint: {6 unmodified linesfunction setFlightFilter() {if (!map.getLayer('fl-air')) return;const base = ['!', ['in', ['get', 'q'], ['literal', ['7700', '7600', '7500']]]];const z = map.getZoom();// 分级采样:全球看分布,区域看密度,近景看全部if (z < 2.8) map.setFilter('fl-air', ['all', base, ['==', ['get', 's'], 1]]);else if (z < 4.6) map.setFilter('fl-air', ['all', base, ['<', ['%', ['get', 'i'], 2], 1]]);else map.setFilter('fl-air', base);}function startFlights() {4 unmodified linesif (!document.getElementById('l-flights').checked) return;const fc = flightFC();src.setData(fc);const msrc = map.getSource('mil');if (msrc) msrc.setData(milFC());window.__flt = { n: (window.__flt ? window.__flt.n : 0) + 1,p: fc.features.length ? fc.features[0].geometry.coordinates : null };};3 unmodified lines}const SAT = { items: [], timer: null };const SATC = { stations: '#eaf4ff', 'gps-ops': '#ffd166', weather: '#6fd3ff',starlink: '#b9e6ff', visual: '#ffd9a8', science: '#a9ffd0' };function initSats(data) {SAT.items = (data.satellites || []).map((s) => {21 unmodified linesfunction satFilter() {if (!document.getElementById('l-sat').checked) return ['==', ['get', 'g'], '__off'];const on = ['stations', 'visual', 'science'];if (document.getElementById('l-sat-gps').checked) on.push('gps-ops');if (document.getElementById('l-sat-wx').checked) on.push('weather');if (document.getElementById('l-sat-sx').checked) on.push('starlink');return ['in', ['get', 'g'], ['literal', on]];}2 unmodified linesfunction addSats() {map.addSource('sats', { type: 'geojson', data: { type: 'FeatureCollection', features: [] } });map.addLayer({ id: 'sat-glow', type: 'circle', source: 'sats',filter: ['!=', ['get', 'g'], 'starlink'],paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'],1, ['*', 4, ISSK], 4, ['*', 9, ISSK], 7, ['*', 15, ISSK]],'circle-color': ['match', ['get', 'g'], 'stations', SATC.stations, 'gps-ops', SATC['gps-ops'], 'weather', SATC.weather, '#9fb6cc'],'circle-opacity': 0.14, 'circle-blur': 1.1,} });map.addLayer({ id: 'sat-starlink', type: 'circle', source: 'sats',filter: ['==', ['get', 'g'], 'starlink'],paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'], 1, 0.72, 4, 1.05, 7, 1.5],'circle-color': SATC.starlink,// 星链是星座结构,低缩放看带、放大后让位给态势'circle-opacity': ['interpolate', ['linear'], ['zoom'], 1, 0.20, 2.6, 0.18, 3.4, 0.08, 4.2, 0],} });map.addLayer({ id: 'sat-dot', type: 'circle', source: 'sats',filter: ['!=', ['get', 'g'], 'starlink'],paint: {'circle-radius': ['interpolate', ['linear'], ['zoom'],1, ['*', 1.3, ISSK], 4, ['*', 2.4, ISSK], 7, ['*', 3.6, ISSK]],'circle-color': ['match', ['get', 'g'], 'stations', SATC.stations, 'gps-ops', SATC['gps-ops'], 'weather', SATC.weather, 'visual', SATC.visual, 'science', SATC.science, '#9fb6cc'],'circle-opacity': 0.95,'circle-stroke-width': 0.5, 'circle-stroke-color': 'rgba(255,255,255,.55)',} });21 unmodified lines};tick();if (SAT.timer) clearInterval(SAT.timer);SAT.timer = setInterval(tick, 2000);}function applyBasemode(m) {178 unmodified linesif (map.getLayer(id)) map.setLayoutProperty(id, 'visibility',document.getElementById('l-fires').checked ? 'visible' : 'none');});['mil-pt'].forEach((id) => {if (map.getLayer(id)) {map.setLayoutProperty(id, 'visibility',document.getElementById('l-mil').checked ? 'visible' : 'none');}});['fl-air', 'fl-em'].forEach((id) => {if (map.getLayer(id)) {map.setLayoutProperty(id, 'visibility',2 unmodified lines});setFlightFilter();const sf = satFilter();if (map.getLayer('sat-glow')) map.setFilter('sat-glow', sf);if (map.getLayer('sat-dot')) map.setFilter('sat-dot', ['all', sf, ['!=', ['get', 'g'], 'starlink']]);if (map.getLayer('sat-starlink')) map.setFilter('sat-starlink', ['all', sf, ['==', ['get', 'g'], 'starlink']]);updateLabelOpacity();renderFeed();}406 unmodified lines});map.on('mouseleave', 'fire-pt', () => dpop.remove());const mpop = new maplibregl.Popup({ closeButton: false, closeOnClick: false, offset: 10, maxWidth: '230px' });map.on('mousemove', 'mil-pt', (e) => {const f = e.features && e.features[0];if (!f) return;const p = f.properties;mpop.setLngLat(e.lngLat).setHTML(`<div class="pop" style="--c:#ff9c4a"><div><b>${p.c || '军机'}</b> · ${p.t || '—'}</div><div class="k"><span>高度 <b>${Math.round(p.a / 30.48) * 100} ft</b></span><span>应答 <b>${p.h}</b></span></div></div>`).addTo(map);});map.on('mouseleave', 'mil-pt', () => mpop.remove());const spop = new maplibregl.Popup({ closeButton: false, closeOnClick: false, offset: 8, maxWidth: '220px' });map.on('mousemove', 'sat-dot', (e) => {const f = e.features && e.features[0];49 unmodified linesif (satd && satd.satellites) initSats(satd);if (flt && flt.flights) initFlights(flt);const satEl = document.getElementById('n-sat');if (satEl) satEl.textContent = (SAT.items.length / 1000).toFixed(1) + 'k 星 / ' +(FL.rows.length / 1000).toFixed(1) + 'k 机';window.__state = state;if (!state.countries) {const gj = await fetch(DATA + 'countries.geojson').then((r) => r.json());55 unmodified linesif (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());if (map.getSource('mil')) map.getSource('mil').setData(milFC());renderTop(); renderRank(); renderSpark(); refreshFilters();} catch (e) { console.warn('刷新失败', e); }}, 300000);
deploy/globe/app.js+76-11