feat: fix gps map projection and update map config
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type CameraState } from '../camera/camera'
|
||||
import { lonLatToWorldTile } from '../../utils/projection'
|
||||
import { calibratedLonLatToWorldTile } from '../../utils/projection'
|
||||
import { worldToScreen } from '../camera/camera'
|
||||
import { type MapLayer, type LayerRenderContext } from './mapLayer'
|
||||
import { type MapScene } from '../renderer/mapRenderer'
|
||||
@@ -9,21 +9,29 @@ export interface ScreenPoint {
|
||||
y: number
|
||||
}
|
||||
|
||||
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 TrackLayer implements MapLayer {
|
||||
projectPoints(scene: MapScene, camera: CameraState): ScreenPoint[] {
|
||||
projectPoints(scene: MapScene): ScreenPoint[] {
|
||||
const camera = buildVectorCamera(scene)
|
||||
return scene.track.map((point) => {
|
||||
const worldPoint = lonLatToWorldTile(point, scene.zoom)
|
||||
const screenPoint = worldToScreen(camera, worldPoint, false)
|
||||
return {
|
||||
x: screenPoint.x + scene.translateX,
|
||||
y: screenPoint.y + scene.translateY,
|
||||
}
|
||||
const worldPoint = calibratedLonLatToWorldTile(point, scene.zoom, scene.gpsCalibration, scene.gpsCalibrationOrigin)
|
||||
return worldToScreen(camera, worldPoint, false)
|
||||
})
|
||||
}
|
||||
|
||||
draw(context: LayerRenderContext): void {
|
||||
const { ctx, camera, scene } = context
|
||||
const points = this.projectPoints(scene, camera)
|
||||
const { ctx, scene } = context
|
||||
const points = this.projectPoints(scene)
|
||||
|
||||
ctx.save()
|
||||
ctx.lineCap = 'round'
|
||||
|
||||
Reference in New Issue
Block a user