feat: initialize mini program map engine

This commit is contained in:
2026-03-19 15:58:48 +08:00
commit 03abe28d8c
49 changed files with 28584 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { type CameraState } from '../camera/camera'
import { lonLatToWorldTile } from '../../utils/projection'
import { worldToScreen } from '../camera/camera'
import { type MapLayer, type LayerRenderContext } from './mapLayer'
import { type MapScene } from '../renderer/mapRenderer'
export interface ScreenPoint {
x: number
y: number
}
export class TrackLayer implements MapLayer {
projectPoints(scene: MapScene, camera: CameraState): ScreenPoint[] {
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,
}
})
}
draw(context: LayerRenderContext): void {
const { ctx, camera, scene } = context
const points = this.projectPoints(scene, camera)
ctx.save()
ctx.lineCap = 'round'
ctx.lineJoin = 'round'
ctx.strokeStyle = 'rgba(23, 109, 93, 0.96)'
ctx.lineWidth = 6
ctx.beginPath()
points.forEach((screenPoint, index) => {
if (index === 0) {
ctx.moveTo(screenPoint.x, screenPoint.y)
return
}
ctx.lineTo(screenPoint.x, screenPoint.y)
})
ctx.stroke()
ctx.fillStyle = '#f7fbf2'
ctx.strokeStyle = '#176d5d'
ctx.lineWidth = 4
points.forEach((screenPoint, index) => {
ctx.beginPath()
ctx.arc(screenPoint.x, screenPoint.y, 10, 0, Math.PI * 2)
ctx.fill()
ctx.stroke()
ctx.fillStyle = '#176d5d'
ctx.font = 'bold 14px sans-serif'
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
ctx.fillText(String(index + 1), screenPoint.x, screenPoint.y)
ctx.fillStyle = '#f7fbf2'
})
ctx.restore()
}
}