Last active
June 4, 2021 17:30
-
-
Save plmrry/5934a4ac85774aa8a080b7c9e08f54d0 to your computer and use it in GitHub Desktop.
proj4 to D3 projection
This file contains 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
function radiansToDegrees(radians) { | |
return (radians * 180) / Math.PI; | |
} | |
function degreesToRadians(degrees) { | |
return degrees * (Math.PI / 180); | |
} | |
function proj4toD3(proj4String) { | |
const proj4 = require("proj4"); | |
const d3 = require("d3"); | |
const proj = proj4(proj4String); | |
const project = function(lambda, phi) { | |
return proj.forward([lambda, phi].map(radiansToDegrees)); | |
}; | |
project.invert = function(x, y) { | |
return proj.inverse([x, y]).map(degreesToRadians); | |
}; | |
const projection = d3.geoProjection(project); | |
return projection; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment