- 在 web-ui 中新增历史轨迹查询与回放功能,允许用户查看历史数据。 - 更新 map-loader.js 和 history-map-adapter.js,支持历史轨迹的地图渲染与交互。 - 修改 CSS 文件以改善历史轨迹界面的样式,确保在不同主题下的视觉一致性。 - 在 receivers.js 中更新接收机配置,支持 UID 身份隔离与状态显示优化。 - 在 map_settings.rs 中设置默认经纬度,提升地图初始化体验。
45 lines
2.4 KiB
JavaScript
45 lines
2.4 KiB
JavaScript
// Deterministic map-adapter checks without an HTTP server or physical receiver.
|
|
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFile} from 'node:fs/promises';
|
|
import vm from 'node:vm';
|
|
|
|
const source=(await readFile(new URL('../crates/web-ui/public/history-map-adapter.js',import.meta.url),'utf8'))
|
|
.replace(/^import .*;$/gm,'').replaceAll('export function ','function ');
|
|
|
|
test('historical segments stay separate and playback moves only the marker',()=>{
|
|
let map,marker,fitCount=0,removed=false;
|
|
const sources=new Map();
|
|
class FakeMap{
|
|
constructor(){map=this;this.handlers={};}
|
|
on(name,fn){this.handlers[name]=fn;}
|
|
addControl(){}
|
|
addSource(id,value){sources.set(id,{data:value.data,setData(data){this.data=data;}});}
|
|
addLayer(){}
|
|
getSource(id){return sources.get(id);}
|
|
fitBounds(){fitCount++;}
|
|
resize(){}
|
|
remove(){removed=true;}
|
|
}
|
|
class Marker{setLngLat(point){this.position=[...point];marker=this;return this;}addTo(){return this;}remove(){}}
|
|
class Bounds{constructor(){this.points=[];}extend(point){this.points.push(point);}isEmpty(){return this.points.length===0;}}
|
|
const context=vm.createContext({window:{dispatchEvent(){}},document:{getElementById(){return {};}},
|
|
ResizeObserver:class{observe(){}disconnect(){}},Event:class{},Number,Array,Math,
|
|
ml:{setWorkerUrl(){},Map:FakeMap,Marker,LngLatBounds:Bounds,NavigationControl:class{},AttributionControl:class{}},
|
|
attachTileBuffer:()=>({destroy(){}})});
|
|
vm.runInContext(source,context);
|
|
vm.runInContext('open({longitude:118.77,latitude:32.04,zoom:15,basemap:"road"})',context);
|
|
vm.runInContext('setPoints([{longitude:118,latitude:32,segmentStart:true},{longitude:119,latitude:32,segmentStart:false},{longitude:120,latitude:32,segmentStart:true},{longitude:121,latitude:32,segmentStart:false}])',context);
|
|
map.handlers['style.load']();
|
|
const features=sources.get('history-track').data.features;
|
|
assert.equal(features.length,2);
|
|
assert.deepEqual([...features[0].geometry.coordinates].map(p=>[...p]),[[118,32],[119,32]]);
|
|
assert.deepEqual([...features[1].geometry.coordinates].map(p=>[...p]),[[120,32],[121,32]]);
|
|
assert.equal(fitCount,1);
|
|
vm.runInContext('setIndex(2)',context);
|
|
assert.deepEqual(marker.position,[120,32]);
|
|
assert.equal(fitCount,1,'playback should not recenter the map repeatedly');
|
|
vm.runInContext('close()',context);
|
|
assert.ok(removed);
|
|
});
|