feat(SW-3240): Move StaticMap to design-system * Move StaticMap to design-system Approved-by: Joakim Jäderberg
24 lines
882 B
TypeScript
24 lines
882 B
TypeScript
// Helper function to calculate the latitude offset
|
|
export function calculateLatWithOffset(
|
|
latitude: number,
|
|
offsetPx: number,
|
|
zoomLevel: number
|
|
): number {
|
|
const earthCircumference = 40075017 // Earth's circumference in meters
|
|
const tileSize = 256 // Height of a tile in pixels (standard in Google Maps)
|
|
|
|
// Calculate ground resolution (meters per pixel) at the given latitude and zoom level
|
|
const groundResolution =
|
|
(earthCircumference * Math.cos((latitude * Math.PI) / 180)) /
|
|
(tileSize * Math.pow(2, zoomLevel))
|
|
|
|
// Calculate the number of meters for the given offset in pixels
|
|
const metersOffset = groundResolution * offsetPx
|
|
|
|
// Convert the meters offset into a latitude offset (1 degree latitude is ~111,320 meters)
|
|
const latOffset = metersOffset / 111320
|
|
|
|
// Return the new latitude by subtracting the offset
|
|
return latitude - latOffset
|
|
}
|