feat(protocol): Observation坐标字段可选化及协议v2扩展 - 将Observation中longitude/latitude/altitude_m/heading_deg改为Option类型, 支持无位置信息的观测数据 - 新增DeviceTelemetry结构体承载设备遥测扩展字段(serial, mac, model, rssi, speed, vertical_speed, pressure_altitude, geometric_altitude, height_agl, pilot_position等) - 新增LegacyObservation兼容结构体及From转换,保持旧接收器协议输入兼容 - PROTOCOL_VERSION从1升至2 - 新增coordinates()辅助方法统一提取有效坐标 - validate()适配Option类型,允许坐标字段同时缺失 - Store新增position_generation机制追踪位置可用性变化,确保合并帧间的 位置丢失仍能正确断开轨迹 - geofence-map-adapter过滤无效坐标避免渲染异常 - 新增appearance.css外观主题系统,支持blue/graphite/white三套配色 ```
23 lines
2.7 KiB
JavaScript
23 lines
2.7 KiB
JavaScript
// Unit-level map adapter contract with a deterministic WebGL/MapLibre test double.
|
|
import {readFile} from 'node:fs/promises';
|
|
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--;}}
|
|
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});
|
|
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);
|
|
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);
|
|
now+=200;update([121.01,31.01,NaN,90],3);assert.equal(trail.length,1);
|
|
now+=200;update([122,32,NaN,90],5);assert.equal(trail.length,0,'coalesced loss/recovery must start a fresh trail');
|
|
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']}));
|