Last active
March 28, 2022 17:30
-
-
Save blaurt/b0ca054a7384ebfbea2d5fce69ae9bf4 to your computer and use it in GitHub Desktop.
transformAndPoint.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} latitude in degrees | |
* @param {number} longitude in degrees | |
* @param {number} mapWidth in pixels | |
* @param {number} mapHeight in pixels | |
*/ | |
function latLonToOffsets(latitude, longitude, mapWidth, mapHeight) { | |
const FE = 180; // false easting | |
const radius = mapWidth / (2 * Math.PI); | |
const latRad = degreesToRadians(latitude); | |
const lonRad = degreesToRadians(longitude + FE); | |
const x = lonRad * radius; | |
const yFromEquator = radius * Math.log(Math.tan(Math.PI / 4 + latRad / 2)); | |
const y = mapHeight / 2 - yFromEquator; | |
return { x, y }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment