Add cursor-centered mouse wheel zoom to station map
This commit is contained in:
1 parent
388bf3755a
commit
4f0ea5f008
2 files changed
+6
-4
No files matched your search
@@ -85,6 +85,6 @@ I log VARA possono arricchire le sessioni con byte effettivi e picchi TX/RX. Ins
|
||||
|
||||
La mappa è locale, senza servizi di tile, API key o invio dei log a terzi. Usa i poligoni pubblici [Natural Earth](https://www.naturalearthdata.com/about/terms-of-use/), inclusi nel progetto. Posizione locale da LOCATOR BPQ; per le stazioni remote selezionare un nominativo e salvare il locator Maidenhead comunicato dalla stazione (4, 6 o 8 caratteri). I locator vengono salvati nel file locale station-locations.json, escluso da Git. I punti rappresentano il centro del locator. Stazioni con lo stesso centro del locator condividono il punto, senza spostamenti artificiali. Il riquadro dettagli permette di selezionarle; non viene disegnata una traccia di distanza zero.
|
||||
|
||||
Punti e tracce sono cliccabili, con nominativo, ultimo collegamento nel periodo, servizio, orario e accesso al dettaglio di ogni sessione. Pulsanti zoom e Inquadra rete; trascinamento della mappa e filtro per servizio/periodo. Mostra collegamenti permette di attivare o nascondere le tracce. Le tracce uniscono stazioni e non descrivono il percorso fisico radio o gli hop NET/ROM. Le stazioni senza locator rimangono nell'elenco, senza coordinate inventate.
|
||||
Punti e tracce sono cliccabili, con nominativo, ultimo collegamento nel periodo, servizio, orario e accesso al dettaglio di ogni sessione. Zoom con rotellina del mouse centrato sul cursore, pulsanti zoom e Inquadra rete; trascinamento della mappa e filtro per servizio/periodo. Mostra collegamenti permette di attivare o nascondere le tracce. Le tracce uniscono stazioni e non descrivono il percorso fisico radio o gli hop NET/ROM. Le stazioni senza locator rimangono nell'elenco, senza coordinate inventate.
|
||||
|
||||
Il diario espone eventi strutturati, non i log grezzi: password, challenge CMS, contenuto delle email e conversazioni chat non sono restituiti dall'API.
|
||||
+5
-3
@@ -20,19 +20,21 @@ function mapStations(){const calls=new Set(mapSessions().map(s=>base(s.call)));r
|
||||
const xy=p=>[(p.lon+180)*1000/360,(90-p.lat)*500/180];
|
||||
function landPath(){if(!land)return '';const polygon=rings=>rings.map(r=>r.map((p,i)=>(i?'L':'M')+xy({lon:p[0],lat:p[1]}).map(n=>n.toFixed(3)).join(' ')).join(' ')+'Z').join(' ');return land.features.map(f=>f.geometry.type==='Polygon'?polygon(f.geometry.coordinates):f.geometry.type==='MultiPolygon'?f.geometry.coordinates.map(polygon).join(' '):'').join(' ');}
|
||||
let cachedLand='';
|
||||
function renderMap(){if(!data)return;const stations=mapStations(),known=stations.filter(s=>s.position),own=data.own.position,svg=$('#station-map'),scale=view[2]/1000;$('#map-summary').textContent=known.length+' sulla mappa · '+(stations.length-known.length)+' senza locator';$('#map-station-count').textContent=stations.length+' stazioni';if(!cachedLand&&land)cachedLand=landPath();let content=`<defs><radialGradient id="map-sea"><stop stop-color="#17354d"/><stop offset="1" stop-color="#0b1624"/></radialGradient></defs><rect x="0" y="0" width="1000" height="500" fill="url(#map-sea)"/><path class="map-land" d="${cachedLand}"/>`;
|
||||
function renderMap(keepInfo=false){if(!data)return;const stations=mapStations(),known=stations.filter(s=>s.position),own=data.own.position,svg=$('#station-map'),scale=view[2]/1000;$('#map-summary').textContent=known.length+' sulla mappa · '+(stations.length-known.length)+' senza locator';$('#map-station-count').textContent=stations.length+' stazioni';if(!cachedLand&&land)cachedLand=landPath();let content=`<defs><radialGradient id="map-sea"><stop stop-color="#17354d"/><stop offset="1" stop-color="#0b1624"/></radialGradient></defs><rect x="0" y="0" width="1000" height="500" fill="url(#map-sea)"/><path class="map-land" d="${cachedLand}"/>`;
|
||||
for(let x=0;x<=1000;x+=1000/12)content+=`<path class="map-gridline" d="M${x} 0V500"/>`;for(let y=0;y<=500;y+=500/6)content+=`<path class="map-gridline" d="M0 ${y}H1000"/>`;
|
||||
const local=own?xy(own):null;for(const s of known){const [x,y]=xy(s.position);const sessions=mapSessions().filter(r=>base(r.call)===s.call),radio=sessions.some(r=>r.transport==='Radio'),color=radio?'#96d6c0':'#91bdea';if(local&&Math.hypot(x-local[0],y-local[1])>1e-8&&$('#map-tracks').checked){const mx=(x+local[0])/2,my=(y+local[1])/2-Math.min(55,Math.hypot(x-local[0],y-local[1])*.18);content+=`<path class="map-track ${mapCall===s.call?'selected':''}" data-map-call="${esc(s.call)}" d="M${local[0]} ${local[1]} Q${mx} ${my} ${x} ${y}" stroke="${color}"><title>${esc(data.own.call+' ↔ '+s.call+' · '+sessions.length+' sessioni')}</title></path>`;}
|
||||
content+=`<g class="map-point ${mapCall===s.call?'selected':''}" data-map-call="${esc(s.call)}" role="button" tabindex="0" aria-label="Dettagli stazione ${esc(s.call)}"><rect x="${x-scale*12}" y="${y-scale*24}" width="${scale*115}" height="${scale*40}" fill="transparent" pointer-events="all"/><circle cx="${x}" cy="${y}" r="${scale*11}" fill="${color}" opacity=".14"/><circle cx="${x}" cy="${y}" r="${scale*4.8}" fill="${color}"/><text x="${x+scale*9}" y="${y-scale*8}" font-size="${scale*12}" fill="${color}">${esc(s.call)}</text><title>${esc(s.call+' · '+s.position.locator+' · ultimo collegamento '+time(sessions[0]?.startedAt))}</title></g>`;}
|
||||
if(local)content+=`<g class="map-local"><path d="M${local[0]} ${local[1]-scale*7}l${scale*7} ${scale*7}l${-scale*7} ${scale*7}l${-scale*7} ${-scale*7}Z" fill="#f0d498"/><text x="${local[0]-scale*10}" y="${local[1]+scale*19}" font-size="${scale*12}" text-anchor="end" fill="#f0d498">${esc(data.own.call)}</text></g>`;
|
||||
svg.innerHTML=content;svg.setAttribute('viewBox',view.join(' '));$$('#station-map [data-map-call]').forEach(el=>{el.onclick=e=>{if(moved)return;e.stopPropagation();mapCall=el.dataset.mapCall;renderMap();};el.onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();mapCall=el.dataset.mapCall;renderMap();}};});
|
||||
$('#map-station-list').innerHTML=stations.map(s=>`<button class="map-station ${mapCall===s.call?'selected':''}" data-peer="${esc(s.call)}"><b>${esc(s.call)}</b><span>${s.position?esc(s.position.locator):'+ Aggiungi locator'}</span><small>${esc(s.services.join(' · '))}</small></button>`).join('')||'<p class="empty">Nessun collegamento stabilito nel periodo selezionato.</p>';$$('[data-peer]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.peer;renderMap();});mapInfo(stations.find(s=>s.call===mapCall));}
|
||||
$('#map-station-list').innerHTML=stations.map(s=>`<button class="map-station ${mapCall===s.call?'selected':''}" data-peer="${esc(s.call)}"><b>${esc(s.call)}</b><span>${s.position?esc(s.position.locator):'+ Aggiungi locator'}</span><small>${esc(s.services.join(' · '))}</small></button>`).join('')||'<p class="empty">Nessun collegamento stabilito nel periodo selezionato.</p>';$$('[data-peer]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.peer;renderMap();});if(!keepInfo)mapInfo(stations.find(s=>s.call===mapCall));}
|
||||
function mapInfo(s){if(!s){$('#map-info').innerHTML=`<div class="map-info-empty"><span>◎</span><h2>Scegli una stazione.</h2><p>Clicca un punto, una traccia o un nominativo nell’elenco.</p>${!data.own.position?'<p>Il LOCATOR della stazione locale non è presente in BPQ: le tracce non possono essere disegnate.</p>':''}</div>`;return;}
|
||||
const sessions=mapSessions().filter(r=>base(r.call)===s.call),latest=sessions[0];const samePosition=p=>s.position&&p&&Math.abs(p.lat-s.position.lat)<1e-8&&Math.abs(p.lon-s.position.lon)<1e-8;const colocated=mapStations().filter(other=>samePosition(other.position));const sharedLocal=samePosition(data.own.position);const shared=sharedLocal||colocated.length>1?'<div class="map-shared"><b>Stazioni nello stesso punto</b>'+(sharedLocal?'<p>'+esc(data.own.call)+' · stazione locale</p>':'')+colocated.map(other=>'<button class="secondary" data-colocated="'+esc(other.call)+'">'+esc(other.call)+'</button>').join('')+'<small>Il locator individua un’area: le posizioni effettive possono essere diverse.</small></div>':'';$('#map-info').innerHTML=`<header><span class="eyebrow">STAZIONE COLLEGATA</span><h2>${esc(s.call)}</h2><p>${s.position?esc(s.position.locator)+' · '+(s.distance==null?'Distanza non disponibile':s.distance===0?'Stesso locator del nodo':s.distance+' km dal nodo'):'Posizione non disponibile'}</p></header>${shared}<div class="map-last"><span>Ultimo collegamento nel periodo</span><b>${esc(time(latest?.startedAt))}</b><small>${esc(latest?.service||'')} · ${esc(transport(latest?.transport))} · ${esc(direction(latest?.direction))}</small></div><form id="locator-form"><label>Locator Maidenhead<input id="station-locator" name="locator" required maxlength="8" placeholder="Es. JN45NN" value="${esc(s.position?.locator||'')}"></label><button class="secondary" type="submit">Salva posizione</button><small>${esc(s.position?.source||'Inserisci il locator comunicato dalla stazione.')}</small></form><h3>${sessions.length} collegamenti nel periodo</h3><div class="map-recent">${sessions.slice(0,8).map(r=>`<button data-map-session="${esc(r.id)}"><b>${esc(r.service)} <span>${esc(duration(r.duration))}</span></b><small>${esc(time(r.startedAt))}</small><small>TX ${esc(bytes(r.txBytes))} / RX ${esc(bytes(r.rxBytes))}</small></button>`).join('')}</div>`;$$('[data-colocated]').forEach(b=>b.onclick=()=>{mapCall=b.dataset.colocated;renderMap();});$('#locator-form').onsubmit=async e=>{e.preventDefault();try{data=await api('/stations/location',{method:'POST',body:JSON.stringify({call:s.call,locator:$('#station-locator').value})});render();fit();toast('Locator salvato per '+s.call);}catch(err){toast(err.message)}};$$('[data-map-session]').forEach(b=>b.onclick=()=>{navigate('journal');detail(b.dataset.mapSession);});}
|
||||
function fit(){const points=mapStations().filter(s=>s.position).map(s=>xy(s.position));if(data?.own.position)points.push(xy(data.own.position));if(!points.length){view=[0,0,1000,500];renderMap();return;}const xs=points.map(p=>p[0]),ys=points.map(p=>p[1]);const w=Math.min(1000,Math.max(100,(Math.max(...xs)-Math.min(...xs))*1.7,(Math.max(...ys)-Math.min(...ys))*3.4)),cx=(Math.min(...xs)+Math.max(...xs))/2,cy=(Math.min(...ys)+Math.max(...ys))/2;view=[Math.max(0,Math.min(1000-w,cx-w/2)),Math.max(0,Math.min(500-w/2,cy-w/4)),w,w/2];renderMap();}
|
||||
function zoom(factor){const w=Math.max(5,Math.min(1000,view[2]*factor)),cx=view[0]+view[2]/2,cy=view[1]+view[3]/2;view=[Math.max(0,Math.min(1000-w,cx-w/2)),Math.max(0,Math.min(500-w/2,cy-w/4)),w,w/2];renderMap();}
|
||||
function zoom(factor,anchor){const w=Math.max(5,Math.min(1000,view[2]*factor));if(w===view[2])return;const point=anchor||{x:view[0]+view[2]/2,y:view[1]+view[3]/2},u=(point.x-view[0])/view[2],v=(point.y-view[1])/view[3];view=[Math.max(0,Math.min(1000-w,point.x-u*w)),Math.max(0,Math.min(500-w/2,point.y-v*w/2)),w,w/2];renderMap(true);}
|
||||
$('#map-plus').onclick=()=>zoom(.65);$('#map-minus').onclick=()=>zoom(1.5);$('#map-fit').onclick=fit;$('#map-tracks').onchange=renderMap;for(const id of ['map-period','map-service'])$('#'+id).onchange=()=>{mapCall=null;renderMap();fit();};
|
||||
const svg=$('#station-map');svg.addEventListener('pointerdown',e=>{drag={x:e.clientX,y:e.clientY,view:[...view]};moved=false});svg.addEventListener('pointermove',e=>{if(!drag)return;const box=svg.getBoundingClientRect(),dx=(e.clientX-drag.x)*drag.view[2]/box.width,dy=(e.clientY-drag.y)*drag.view[3]/box.height;if(Math.abs(e.clientX-drag.x)+Math.abs(e.clientY-drag.y)>4){moved=true;if(!svg.hasPointerCapture(e.pointerId))svg.setPointerCapture(e.pointerId);}view=[drag.view[0]-dx,drag.view[1]-dy,...drag.view.slice(2)];svg.setAttribute('viewBox',view.join(' '));});svg.addEventListener('pointerup',()=>{drag=null;setTimeout(()=>moved=false,0)});svg.addEventListener('pointercancel',()=>{drag=null});
|
||||
let wheelDelta=0,wheelPoint=null,wheelFrame=0;
|
||||
svg.addEventListener('wheel',e=>{if(!data||!e.deltaY||drag)return;e.preventDefault();const unit=e.deltaMode===1?16:e.deltaMode===2?svg.clientHeight:1;wheelDelta+=e.deltaY*unit;wheelPoint={x:e.clientX,y:e.clientY};if(wheelFrame)return;wheelFrame=requestAnimationFrame(()=>{wheelFrame=0;const matrix=svg.getScreenCTM();if(matrix&&wheelPoint){const p=svg.createSVGPoint();p.x=wheelPoint.x;p.y=wheelPoint.y;zoom(Math.exp(Math.max(-240,Math.min(240,wheelDelta))*.002),p.matrixTransform(matrix.inverse()));}wheelDelta=0;wheelPoint=null;});},{passive:false});
|
||||
for(const id of ['journal-search','journal-period','journal-service','journal-direction','journal-result'])$('#'+id).oninput=render;
|
||||
$('#journal-refresh').onclick=()=>load(true);$('#map-refresh').onclick=()=>load(true);
|
||||
$('#journal-export').onclick=()=>{const quote=v=>'"'+String(v??'').replaceAll('"','""')+'"';const rows=[['Stazione','Servizio','Trasporto','Direzione','Inizio UTC','Connessione UTC','Fine UTC','Durata s','Frequenza MHz','TX byte','RX byte','Messaggi TX','Messaggi RX','Esito'],...filtered().map(s=>[s.call,s.service,s.transport,s.direction,s.startedAt,s.connectedAt,s.endedAt,s.duration,s.frequency,s.txBytes,s.rxBytes,s.sentMessages,s.receivedMessages,s.status])];const url=URL.createObjectURL(new Blob(['\ufeff'+rows.map(row=>row.map(quote).join(';')).join('\r\n')],{type:'text/csv;charset=utf-8'})),a=document.createElement('a');a.href=url;a.download='BPQ-diario-'+new Date().toISOString().slice(0,10)+'.csv';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);};
|
||||
|
||||
Reference in new issue
Block a user