feat: fix gps map projection and update map config

This commit is contained in:
2026-03-23 10:05:41 +08:00
parent a4c426df8b
commit 51740761f5
11 changed files with 214 additions and 55 deletions

View File

@@ -1,18 +1,25 @@
import { type CameraState } from '../camera/camera'
import { lonLatToWorldTile } from '../../utils/projection'
import { worldToScreen } from '../camera/camera'
import { calibratedLonLatToWorldTile } from '../../utils/projection'
import { worldToScreen, type CameraState } from '../camera/camera'
import { type MapLayer, type LayerRenderContext } from './mapLayer'
import { type MapScene } from '../renderer/mapRenderer'
import { type ScreenPoint } from './trackLayer'
function buildVectorCamera(scene: MapScene): CameraState {
return {
centerWorldX: scene.exactCenterWorldX,
centerWorldY: scene.exactCenterWorldY,
viewportWidth: scene.viewportWidth,
viewportHeight: scene.viewportHeight,
visibleColumns: scene.visibleColumns,
rotationRad: scene.rotationRad,
}
}
export class GpsLayer implements MapLayer {
projectPoint(scene: MapScene, camera: CameraState): ScreenPoint {
const worldPoint = lonLatToWorldTile(scene.gpsPoint, scene.zoom)
const screenPoint = worldToScreen(camera, worldPoint, false)
return {
x: screenPoint.x + scene.translateX,
y: screenPoint.y + scene.translateY,
}
projectPoint(scene: MapScene): ScreenPoint {
const camera = buildVectorCamera(scene)
const worldPoint = calibratedLonLatToWorldTile(scene.gpsPoint, scene.zoom, scene.gpsCalibration, scene.gpsCalibrationOrigin)
return worldToScreen(camera, worldPoint, false)
}
getPulseRadius(pulseFrame: number): number {
@@ -20,8 +27,8 @@ export class GpsLayer implements MapLayer {
}
draw(context: LayerRenderContext): void {
const { ctx, camera, scene, pulseFrame } = context
const gpsScreenPoint = this.projectPoint(scene, camera)
const { ctx, scene, pulseFrame } = context
const gpsScreenPoint = this.projectPoint(scene)
const pulse = this.getPulseRadius(pulseFrame)
ctx.save()