Add mock GPS simulator and configurable location sources

This commit is contained in:
2026-03-24 14:24:53 +08:00
parent 0295893b56
commit 2cf0bb76b4
16 changed files with 2575 additions and 122 deletions

View File

@@ -0,0 +1,51 @@
import { type LocationSample, type LocationSource, type LocationSourceCallbacks } from './locationSource'
export class MockLocationSource implements LocationSource {
callbacks: LocationSourceCallbacks
active: boolean
lastSample: LocationSample | null
constructor(callbacks: LocationSourceCallbacks) {
this.callbacks = callbacks
this.active = false
this.lastSample = null
}
get mode(): 'mock' {
return 'mock'
}
start(): void {
if (this.active) {
this.callbacks.onStatus('模拟定位进行中')
return
}
this.active = true
this.callbacks.onStatus('模拟定位已启动,等待外部输入')
}
stop(): void {
if (!this.active) {
this.callbacks.onStatus('模拟定位未启动')
return
}
this.active = false
this.callbacks.onStatus('模拟定位已停止')
}
destroy(): void {
this.active = false
this.lastSample = null
}
pushSample(sample: LocationSample): void {
this.lastSample = sample
if (!this.active) {
return
}
this.callbacks.onLocation(sample)
}
}