feat(web-ui): 添加 Windows 系统依赖并更新样式

- 在 Cargo.toml 中为 Windows 平台添加 windows-sys 依赖,版本为 0.52,包含 Win32_Foundation 和 Win32_System_Registry 特性。
- 更新相关 CSS 文件以改善界面样式,确保在不同主题下的视觉一致性。
- 在 JavaScript 文件中实现围栏标记的绘制和管理功能,增强地图交互体验。
This commit is contained in:
2026-10-31 20:01:50 +08:00
parent 5522843823
commit 3ea9cf32ee
27 changed files with 1301 additions and 103 deletions
+21 -7
View File
@@ -4,16 +4,18 @@ import vm from 'node:vm';
import assert from 'node:assert/strict';
const source=(await readFile(new URL('../crates/web-ui/public/map-adapter.js',import.meta.url),'utf8')).replace(/^import .*;$/gm,'');
let markers=0,drawCount=0,trail=[];
const gl={ARRAY_BUFFER:1,bindBuffer(){},bufferSubData(_t,_o,data){assert.ok([...data].every(Number.isFinite));}};
const map={getSource(){return{setData(data){trail=data.features;}};},triggerRepaint(){},getCanvas(){return{clientWidth:1000,clientHeight:700};},project(p){assert.ok(p.every(Number.isFinite));return{x:1,y:2};},getCenter(){return{toArray(){return[120,30];}};},getZoom(){return 15;},getPitch(){return 0;},getBearing(){return 0;},easeTo(){},isStyleLoaded(){return true;}};
class Marker{constructor(){markers++;this.element={dataset:{}};}setLngLat(p){assert.ok(p.every(Number.isFinite));return this;}addTo(){return this;}getElement(){return this.element;}remove(){markers--;}}
const gl={ARRAY_BUFFER:1,bindBuffer(){},bufferSubData(_t,_o,data){assert.ok([...data].every(Number.isFinite));},getExtension(){return null;}};
let flights=[];
const map={getSource(){return{setData(data){trail=data.features;}};},triggerRepaint(){},getCanvas(){return{clientWidth:1000,clientHeight:700};},project(p){assert.ok(p.every(Number.isFinite));return{x:1,y:2};},getCenter(){return{toArray(){return[120,30];}};},getZoom(){return 15;},getPitch(){return 0;},getBearing(){return 0;},easeTo(){},flyTo(options){flights.push(options.center);},isStyleLoaded(){return true;}};
class Marker{constructor(opts){markers++;this.element=opts?.element||{dataset:{},querySelector(){return{dataset:{}};}};}setLngLat(p){assert.ok(p.every(Number.isFinite));return this;}addTo(){return this;}getElement(){return this.element;}remove(){markers--;}}
function domNode(){const node={dataset:{},className:'',textContent:'',innerHTML:'',children:[],append(...items){this.children.push(...items);},querySelector(sel){const name=sel.slice(1);const walk=item=>item.className===name?item:(item.children||[]).map(walk).find(Boolean);return walk(node)||null;}};return node;}
let now=1000;
const context=vm.createContext({window:{},document:{createElement(){return{};},getElementById(){return null;}},performance:{now:()=>now},requestAnimationFrame(){},maplibre:{setWorkerUrl(){},Marker,MercatorCoordinate:{fromLngLat(p){assert.ok(p.every(Number.isFinite));return{x:p[0],y:p[1]};}}},console,Float32Array,Map,Number,Array,Math,mockMap:map,mockGl:gl});
const context=vm.createContext({window:{},document:{createElement:domNode,getElementById(){return null;}},performance:{now:()=>now},requestAnimationFrame(){},maplibre:{setWorkerUrl(){},Marker,MercatorCoordinate:{fromLngLat(p){assert.ok(p.every(Number.isFinite));return{x:p[0],y:p[1]};}}},console,Float32Array,Map,Number,Array,Math,mockMap:map,mockGl:gl});
vm.runInContext(source,context);
vm.runInContext('map=mockMap;layer={gl:mockGl,instances:{},origin:{x:0,y:0}};centered=true;',context);
const update=(positions,generation)=>{context.input=new Float64Array(positions);context.generation=generation;vm.runInContext('window.ridMap.update(input,["TEST"],[generation]);flush();',context);drawCount=vm.runInContext('layer.count',context);};
update([NaN,NaN,NaN,90],0);assert.equal(drawCount,0);assert.equal(vm.runInContext('window.ridMap.select("TEST").length',context),0);
update([120,30,NaN,NaN],1);assert.equal(drawCount,1);vm.runInContext('window.ridMap.select("TEST");flush();',context);assert.equal(markers,1);
update([NaN,NaN,NaN,90],0);assert.equal(drawCount,0);assert.equal(vm.runInContext('window.ridMap.select("TEST").length',context),0);assert.equal(flights.length,0);
update([120,30,NaN,NaN],1);assert.equal(drawCount,1);vm.runInContext('window.ridMap.select("TEST");flush();',context);assert.equal(markers,1);assert.deepEqual([...flights.at(-1)],[120,30]);
now+=200;update([120.01,30.01,NaN,90],1);assert.equal(trail.length,1);
now+=200;update([NaN,NaN,NaN,90],2);assert.equal(drawCount,0);assert.equal(markers,0);assert.equal(trail.length,0);
now+=200;update([121,31,NaN,90],3);assert.equal(markers,1);assert.equal(trail.length,0);
@@ -24,4 +26,16 @@ assert.equal(vm.runInContext('layer.count',context),0,'source filter hides map i
vm.runInContext('window.ridMap.setSources(["TEST"]);',context);
assert.equal(vm.runInContext('layer.count',context),1,'source filter restores matching targets');assert.equal(markers,1);
vm.runInContext('window.ridMap.setSources(null);',context);
console.log(JSON.stringify({status:'PASS',scenarios:['unknown position excluded from GPU and selection','unknown altitude/heading do not block valid position','loss removes marker and trail','recovery starts new trail','coalesced loss breaks trail','source filter hides and restores targets']}));
const beforeRaw=flights.length;
vm.runInContext('window.ridMap.focusRaw([118.5768,31.9547]);',context);
assert.deepEqual([...flights.at(-1)],[118.5768,31.9547]);
vm.runInContext('window.ridMap.focusRaw([200,0]);',context);
assert.equal(flights.length,beforeRaw+1);
vm.runInContext('window.ridMap.setFences([{id:"F1",name:"园区",enabled:true,geometry:{type:"circle",center:[120.15,30.28],radius_m:400}}]);',context);
assert.equal(vm.runInContext('window.ridMap.metrics().fences',context),1);
assert.equal(trail[0].geometry.type,'Polygon');
assert.ok(trail[0].geometry.coordinates[0].length>8);
assert.equal(markers,2);
vm.runInContext('window.ridMap.setFences([{id:"BAD",geometry:{type:"circle",center:[999,0],radius_m:10}}]);',context);
assert.equal(trail.length,0);
console.log(JSON.stringify({status:'PASS',scenarios:['unknown position excluded from GPU and selection','unknown altitude/heading do not block valid position','loss removes marker and trail','recovery starts new trail','coalesced loss breaks trail','source filter hides and restores targets','saved geofence renders on the realtime map']}));