feat: fix gps map projection and update map config
This commit is contained in:
@@ -13,6 +13,13 @@ export interface WorldTilePoint {
|
||||
y: number
|
||||
}
|
||||
|
||||
export interface MapCalibration {
|
||||
offsetEastMeters: number
|
||||
offsetNorthMeters: number
|
||||
rotationDeg: number
|
||||
scale: number
|
||||
}
|
||||
|
||||
const MAX_LATITUDE = 85.05112878
|
||||
const EARTH_RADIUS = 6378137
|
||||
|
||||
@@ -60,6 +67,43 @@ export function worldTileToLonLat(point: WorldTilePoint, zoom: number): LonLatPo
|
||||
}
|
||||
}
|
||||
|
||||
export function applyMapCalibration(point: LonLatPoint, calibration: MapCalibration, origin: LonLatPoint): LonLatPoint {
|
||||
const scale = calibration.scale || 1
|
||||
const rotationDeg = calibration.rotationDeg || 0
|
||||
const offsetEastMeters = calibration.offsetEastMeters || 0
|
||||
const offsetNorthMeters = calibration.offsetNorthMeters || 0
|
||||
|
||||
if (
|
||||
Math.abs(scale - 1) < 0.000001
|
||||
&& Math.abs(rotationDeg) < 0.000001
|
||||
&& Math.abs(offsetEastMeters) < 0.000001
|
||||
&& Math.abs(offsetNorthMeters) < 0.000001
|
||||
) {
|
||||
return point
|
||||
}
|
||||
|
||||
const originMercator = lonLatToWebMercator(origin)
|
||||
const pointMercator = lonLatToWebMercator(point)
|
||||
const deltaX = pointMercator.x - originMercator.x
|
||||
const deltaY = pointMercator.y - originMercator.y
|
||||
const scaledX = deltaX * scale
|
||||
const scaledY = deltaY * scale
|
||||
const rotationRad = rotationDeg * Math.PI / 180
|
||||
const cos = Math.cos(rotationRad)
|
||||
const sin = Math.sin(rotationRad)
|
||||
|
||||
const calibratedMercator: WebMercatorPoint = {
|
||||
x: originMercator.x + scaledX * cos - scaledY * sin + offsetEastMeters,
|
||||
y: originMercator.y + scaledX * sin + scaledY * cos + offsetNorthMeters,
|
||||
}
|
||||
|
||||
return webMercatorToLonLat(calibratedMercator)
|
||||
}
|
||||
|
||||
export function calibratedLonLatToWorldTile(point: LonLatPoint, zoom: number, calibration: MapCalibration, origin: LonLatPoint): WorldTilePoint {
|
||||
return lonLatToWorldTile(applyMapCalibration(point, calibration, origin), zoom)
|
||||
}
|
||||
|
||||
const CHINA_AXIS = 6378245
|
||||
const CHINA_EE = 0.00669342162296594323
|
||||
|
||||
|
||||
Reference in New Issue
Block a user