Created
July 18, 2017 11:34
-
-
Save stephanbogner/88bb95fe4f84b65fcc9bbede12af4f03 to your computer and use it in GitHub Desktop.
Simple example to convert coordinates from one projection into another one
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
// import | |
// - https://d3js.org/d3-geo.v1.min.js | |
// - https://d3js.org/d3-geo-projection.v2.min.js | |
// Keep x and y in the same range of values as coordinates | |
var x = 180; | |
var y = 90; | |
var fromXY = [x, y]; | |
var fromLonLat = d3.geoEquirectangular().invert(fromXY); | |
var toXY = d3.geoMercator()(fromLonLat); | |
//document.getElementById("console").innerHTML = 'Before <br>' + fromXY[0] + ', ' + fromXY[1] + '<br><br>After<br>' + toXY[0] + ', ' + toXY[1]; | |
console.log('Before', fromXY, 'After', toXY); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment