feat(web-ui): 添加历史轨迹功能与地图适配

- 在 web-ui 中新增历史轨迹查询与回放功能,允许用户查看历史数据。
- 更新 map-loader.js 和 history-map-adapter.js,支持历史轨迹的地图渲染与交互。
- 修改 CSS 文件以改善历史轨迹界面的样式,确保在不同主题下的视觉一致性。
- 在 receivers.js 中更新接收机配置,支持 UID 身份隔离与状态显示优化。
- 在 map_settings.rs 中设置默认经纬度,提升地图初始化体验。
This commit is contained in:
2026-11-02 15:28:01 +08:00
parent 87d0ec8352
commit 7af8fb32cf
43 changed files with 3107 additions and 302 deletions
+72 -6
View File
@@ -7,6 +7,7 @@ type ObservationListener = Box<dyn Fn(&Observation, u64) + Send + Sync>;
struct Track {
target: Target,
sources: HashMap<String, SourceObservation>,
suppressed: bool,
}
pub struct Store {
@@ -95,6 +96,7 @@ impl Store {
sources: vec![],
},
sources: HashMap::new(),
suppressed: false,
},
);
}
@@ -123,6 +125,7 @@ impl Store {
.sources
.retain(|_, s| now_ms.saturating_sub(s.received_at_ms) < self.ttl_ms);
refresh(track);
track.suppressed = false;
if let Some(observer) = &self.observer {
observer(&track.target.observation, now_ms);
}
@@ -131,7 +134,51 @@ impl Store {
true
}
/// Return the selected observation after an accepted update.
pub fn selected_observation(&self, id: &str) -> Option<&Observation> {
self.tracks.get(id).map(|track| &track.target.observation)
}
pub fn expire(&mut self, now_ms: u64) {
let _ = self.expire_with_changes(now_ms);
}
/// Remove fully expired targets and hide stale selected positions until
/// their monitored source transition can be delivered.
pub fn expire_fully(&mut self, now_ms: u64) {
let mut expired = Vec::new();
let mut suppressed = Vec::new();
for (id, track) in &mut self.tracks {
if track
.sources
.values()
.all(|source| now_ms.saturating_sub(source.received_at_ms) >= self.ttl_ms)
{
expired.push(id.clone());
} else if !track.suppressed
&& track
.sources
.get(&track.target.observation.receiver_id)
.is_some_and(|source| {
now_ms.saturating_sub(source.received_at_ms) >= self.ttl_ms
})
{
track.suppressed = true;
suppressed.push(id.clone());
}
}
for id in expired {
self.tracks.remove(&id);
self.metrics.expired += 1;
self.changed(id);
}
for id in suppressed {
self.changed(id);
}
}
/// Expire sources and return the newly selected observations in change order.
pub fn expire_with_changes(&mut self, now_ms: u64) -> Vec<Observation> {
let mut changed = Vec::new();
let mut removed = Vec::new();
for (id, track) in &mut self.tracks {
@@ -141,12 +188,13 @@ impl Store {
.retain(|_, s| now_ms.saturating_sub(s.received_at_ms) < self.ttl_ms);
if track.sources.is_empty() {
removed.push(id.clone());
} else if track.sources.len() != count {
} else if track.sources.len() != count || track.suppressed {
refresh(track);
track.suppressed = false;
if let Some(observer) = &self.observer {
observer(&track.target.observation, now_ms);
}
changed.push(id.clone());
changed.push((id.clone(), track.target.observation.clone()));
}
}
for id in removed {
@@ -154,12 +202,25 @@ impl Store {
self.metrics.expired += 1;
self.changed(id);
}
for id in changed {
self.changed(id);
for (id, _) in &changed {
self.changed(id.clone());
}
changed
.into_iter()
.map(|(_, observation)| observation)
.collect()
}
pub fn frame(&self, since: Option<u64>, now_ms: u64) -> Frame {
let visible = |track: &Track| {
!track.suppressed
&& track
.sources
.get(&track.target.observation.receiver_id)
.is_some_and(|source| {
now_ms.saturating_sub(source.received_at_ms) < self.ttl_ms
})
};
let snapshot = since.is_none_or(|s| {
s > self.metrics.sequence
|| self
@@ -170,7 +231,12 @@ impl Store {
let mut targets = Vec::new();
let mut removed = Vec::new();
if snapshot {
targets.extend(self.tracks.values().map(|t| t.target.clone()));
targets.extend(
self.tracks
.values()
.filter(|track| visible(track))
.map(|t| t.target.clone()),
);
} else {
let mut ids = HashSet::new();
for (_, id) in self
@@ -180,7 +246,7 @@ impl Store {
.take_while(|(seq, _)| *seq > since.unwrap())
{
if ids.insert(id) {
if let Some(track) = self.tracks.get(id) {
if let Some(track) = self.tracks.get(id).filter(|track| visible(track)) {
targets.push(track.target.clone());
} else {
removed.push(id.clone());