```
feat(web-ui): 新增首页启动器与地图遮挡感知交互 - 添加首页卡片式应用启动器界面,包含实时视图、登记、 设置三个入口及对应 SVG 图标资源 - 地图组件新增 ResizeObserver 自动适配容器尺寸变化 - 地图组件引入遮挡区域(occlusion)管理,聚焦时自动 计算可见填充偏移,避免目标被面板遮挡 - 将地图加载事件从 load 改为 style.load,提升初始化 可靠性 - 扩展 metrics 接口,返回选中目标像素坐标、遮挡状态、 画布尺寸等运行时诊断信息 - 补充 web-sys features(HtmlImageElement, Storage, PointerEvent, DomRect 等)以支持新 UI 交互 - index.html 新增 workspace/home/registry 样式及资源引用 - .gitignore 忽略 previews 目录与本地编译产物 ```
This commit is contained in:
@@ -4,7 +4,8 @@ maplibre.setWorkerUrl('/vendor/maplibre-gl-worker.mjs');
|
||||
let map, layer, latest, ids = [], selected = '', pending = false;
|
||||
let frameTimes = [], lastFrame = 0;
|
||||
let marker=null, history=[], lastTrail=0;
|
||||
let centered=false, workerWasmBytes=0;
|
||||
let centered=false, workerWasmBytes=0, resizeObserver;
|
||||
let occlusion={top:0,right:0,bottom:0,left:0};
|
||||
function shader(gl, type, source) {
|
||||
const s=gl.createShader(type);gl.shaderSource(s,source);gl.compileShader(s);
|
||||
if (!gl.getShaderParameter(s,gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));return s;
|
||||
@@ -20,6 +21,7 @@ function create(container) {
|
||||
{id:'tdt-base',type:'raster',source:'tdt-base'},
|
||||
{id:'tdt-labels',type:'raster',source:'tdt-labels'}
|
||||
]}});
|
||||
resizeObserver?.disconnect(); resizeObserver=new ResizeObserver(()=>map?.resize());resizeObserver.observe(document.getElementById(container));
|
||||
map.addControl(new maplibre.AttributionControl({compact:true}),'bottom-right');
|
||||
layer={id:'rid-targets',type:'custom',renderingMode:'2d',
|
||||
onAdd(map,gl){
|
||||
@@ -51,7 +53,7 @@ function create(container) {
|
||||
},
|
||||
onRemove(map,gl){gl.deleteBuffer(this.shape);gl.deleteBuffer(this.instances);gl.deleteVertexArray(this.vao);gl.deleteProgram(this.program);gl.deleteShader(this.vs);gl.deleteShader(this.fs);}
|
||||
};
|
||||
map.on('load',()=>{
|
||||
map.on('style.load',()=>{
|
||||
// Mission Control tactical radar grid & range rings
|
||||
const features=[];
|
||||
for(let lon=118;lon<=122;lon+=.05)features.push({type:'Feature',geometry:{type:'LineString',coordinates:[[lon,28],[lon,32]]},properties:{}});
|
||||
@@ -95,9 +97,32 @@ function flush(){
|
||||
map.getSource('selected-trail')?.setData({type:'FeatureCollection',features:history.length<2?[]:[{type:'Feature',properties:{},geometry:{type:'LineString',coordinates:history.map(p=>p.coordinate)}}]});}
|
||||
}else{marker?.remove();marker=null;history=[];map.getSource('selected-trail')?.setData({type:'FeatureCollection',features:[]});}
|
||||
}
|
||||
function update(positions,newIds){latest=positions;if(newIds)ids=Array.from(newIds);if(!centered&&latest.length>=4){centered=true;map.jumpTo({center:[latest[0],latest[1]]});}if(!pending){pending=true;requestAnimationFrame(flush);}}
|
||||
function update(positions,newIds){latest=positions;if(newIds)ids=Array.from(newIds);if(!centered&&latest.length>=4){centered=true;focusCoordinate([latest[0],latest[1]], false);}if(!pending){pending=true;requestAnimationFrame(flush);}}
|
||||
function select(id){if(selected!==id){selected=id;history=[];flush();}const i=ids.indexOf(id);return i>=0&&latest?Array.from(latest.slice(i*4,i*4+4)):[];}
|
||||
function metrics(){const sorted=[...frameTimes].sort((a,b)=>a-b);const gl=layer?.gl;const ext=gl?.getExtension('WEBGL_debug_renderer_info');return {samples:sorted.length,drawSubmissionIntervalP95Ms:sorted[Math.floor(sorted.length*.95)]||0,targets:ids.length,renderer:ext?gl.getParameter(ext.UNMASKED_RENDERER_WEBGL):'unavailable',selectedTrailPoints:history.length,workerWasmBytes};}
|
||||
function connection(connected){const canvas=document.querySelector('.rt-map');if(canvas)canvas.dataset.stale=connected?'false':'true';}
|
||||
function metrics(){const sorted=[...frameTimes].sort((a,b)=>a-b);const gl=layer?.gl;const ext=gl?.getExtension('WEBGL_debug_renderer_info');const projected=map&&latest&&ids.includes(selected)?map.project([latest[ids.indexOf(selected)*4],latest[ids.indexOf(selected)*4+1]]):null;return {selectedPixel:projected?{x:projected.x,y:projected.y}:null,occlusion:{...occlusion},mapReady:!!layer?.gl,styleReady:map?.isStyleLoaded()||false,mapCanvasWidth:map?.getCanvas().clientWidth||0,mapCanvasHeight:map?.getCanvas().clientHeight||0,samples:sorted.length,drawSubmissionIntervalP95Ms:sorted[Math.floor(sorted.length*.95)]||0,targets:ids.length,renderer:ext?gl.getParameter(ext.UNMASKED_RENDERER_WEBGL):'unavailable',selectedTrailPoints:history.length,workerWasmBytes};}
|
||||
function connection(connected){const canvas=document.getElementById('rt-map');if(canvas)canvas.dataset.stale=connected?'false':'true';}
|
||||
function refresh(){for(const [id,layer]of [['tdt-base','img_w'],['tdt-labels','cia_w']])map?.getSource(id)?.setTiles([`/api/maps/tile/${layer}/{z}/{x}/{y}`]);}
|
||||
window.ridMap={workerMemory(bytes){if(Number.isFinite(bytes))workerWasmBytes=bytes;},create,update,select,metrics,connection,refresh,zoomIn(){if(map)map.zoomIn();},zoomOut(){if(map)map.zoomOut();},centerSelected(){if(!map||!latest||!selected)return;const index=ids.indexOf(selected);if(index>=0){map.flyTo({center:[latest[index*4],latest[index*4+1]],zoom:Math.max(map.getZoom(),13),essential:true});}},resetBearing(){if(map)map.resetNorthPitch({duration:400});},toggle3d(){if(!map)return;const p=map.getPitch();map.easeTo({pitch:p>10?0:55,duration:500});},destroy(){marker?.remove();marker=null;history=[];map?.remove();map=null;layer=null;latest=null;ids=[];centered=false;}};
|
||||
function setOcclusion(value){
|
||||
occlusion=Object.fromEntries(['top','right','bottom','left'].map(k=>[k,Number.isFinite(value?.[k])?Math.max(0,value[k]):0]));
|
||||
}
|
||||
function visiblePadding(){
|
||||
if(!map)return {top:0,right:0,bottom:0,left:0};
|
||||
const w=map.getCanvas().clientWidth,h=map.getCanvas().clientHeight;
|
||||
const p={...occlusion};
|
||||
// Hidden mobile overlays may have just closed; measure visible panels at focus time.
|
||||
const root=document.getElementById('rt-layout')?.getBoundingClientRect();
|
||||
if(root){const scale=Math.max(.01,root.width/w);for(const [id,side] of [['rt-directory','left'],['rt-details','right']]){const el=document.getElementById(id);const r=el?.getBoundingClientRect();p[side]=r?.height?side==='left'?(r.right-root.left)/scale+12:(root.right-r.left)/scale+12:0;}
|
||||
const dock=document.getElementById('rt-dock')?.getBoundingClientRect();p.bottom=dock?.height?(root.bottom-dock.top)/scale+40:116;
|
||||
}
|
||||
if(p.left+p.right>w-80){p.left=0;p.right=0;}
|
||||
if(p.top+p.bottom>h-80){p.top=0;p.bottom=0;}
|
||||
return p;
|
||||
}
|
||||
function focusCoordinate(center,animate=true){
|
||||
if(!map)return;
|
||||
const p=visiblePadding();
|
||||
const options={center,offset:[(p.left-p.right)/2,(p.top-p.bottom)/2]};
|
||||
if(animate)map.flyTo({...options,zoom:Math.max(map.getZoom(),13),duration:400});else map.easeTo({...options,duration:0});
|
||||
}
|
||||
function centerSelected(){if(!map||!latest||!selected)return;const i=ids.indexOf(selected);if(i>=0)focusCoordinate([latest[i*4],latest[i*4+1]]);}
|
||||
window.ridMap={workerMemory(bytes){if(Number.isFinite(bytes))workerWasmBytes=bytes;},create,update,select,metrics,connection,refresh,setOcclusion,focusVisible(){requestAnimationFrame(()=>requestAnimationFrame(centerSelected));},zoomIn(){if(map)map.zoomIn();},zoomOut(){if(map)map.zoomOut();},centerSelected,resetBearing(){if(map)map.resetNorthPitch({duration:400});},toggle3d(){if(!map)return;const p=map.getPitch();map.easeTo({pitch:p>10?0:55,duration:500});},destroy(){resizeObserver?.disconnect();resizeObserver=null;marker?.remove();marker=null;history=[];map?.remove();map=null;layer=null;latest=null;ids=[];centered=false;occlusion={top:0,right:0,bottom:0,left:0};}};
|
||||
|
||||
Reference in New Issue
Block a user