-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What projection is used for the ThreeJS coordinate system? #981
Comments
If you would like to upvote the priority of this issue, please comment below or react on the original post above with 👍 so we can see what is popular when we triage.@Krassnig Thank you for opening this issue. 🙏
This is an automated message, feel free to ignore. |
First of all, where did you get the x/y values from? And, are you using an anchor point for the three.js overlay? |
Thank you for helping me! I got the coordinates from the google maps click event (lat lng) and converted it into a ThreeJS coordinate using The code below is a minimal reproduction: const loader = new Loader({ apiKey: API_KEY });
await loader.importLibrary('maps');
const map = new google.maps.Map(document.getElementById('map')!, {
center: { lat: 48.20877521256814, lng: 16.372467530134163 }, // central Vienna
zoom: 20,
mapId: '15431d2b469f209e',
disableDefaultUI: false
});
const overlay = new ThreeJSOverlayView({
anchor: { lat: 0, lng: 0, altitude: 0 },
map,
upAxis: 'Z',
});
map.addListener('click', (e: any) => {
const vec = overlay.latLngAltitudeToVector3({ lat: e.latLng.lat(), lng: e.latLng.lng(), altitude: 0 });
const backlatlng = xyToLatLng([vec.x, vec.y]);
console.log('xyToLatLng([', vec.x, ',', vec.y, ']) = { lat:', backlatlng.lat, ', lng: ', backlatlng.lng, ' }');
// xyToLatLng([ 1820541.7625204194 , 6134799.8559301235 ]) -> { lat: 48.20880202465933 , lng: 16.372499716642768 }
// epsg.io using EPSG:3857 1820541.7625204194 , 6134799.8559301235 -> 48.1677013 16.354205
});
// taken from https://github.com/googlemaps/js-three/blob/main/src/util.ts#L89-L96
/**
* Converts WebMercator meters to WGS84 latitude/longitude.
* (WebMercator (EPSG:3857) --> WGS84)
*/
function xyToLatLng(p: number[]): google.maps.LatLngLiteral {
const EARTH_RADIUS = 6371010.0;
const [x, y] = p;
return {
lat: radToDeg(Math.PI * 0.5 - 2.0 * Math.atan(Math.exp(-y / EARTH_RADIUS))),
lng: radToDeg(x) / EARTH_RADIUS,
};
}
function radToDeg(radians: number) {
return radians / Math.PI * 180;
} Click anywhere in the world and then take the console output of The functions |
ok, so the main question is about the discrepancy between the numbers you get from epsg.io and this library? |
I was expecting it to be some kind of common projection? Is it not? Fundamentally, I just want to know if I can use a predefined projection or if I have to transform my geometries to EPSG:4326 and then further transform them with |
I think I just remembered what was special about the projections used here (I don't know why it is that way, but I've had my formulae confirmed by the engineers who built the WebGlOverlayView at google). The original "Web Mercator" / EPSG:3857 projection uses an earth radius of 6,378,137 meters, and the implementation used here uses a radius of 6,371,010 meters (I believe this is some sort of result of using the s2 geometry library internally). I haven't done the math but I'm ready to believe this could be the reason for discrepancies. |
Thank you very much for your help!
In hindsight it kind of is right there in the code 😅. |
Hello,
I'm currently struggling with placing a few geometries and I can't quite figure out the coordinate system used.
Although the comment https://github.com/googlemaps/js-three/blob/main/src/util.ts#L89-L96
states that it is
(WebMercator (EPSG:3857) --> WGS84)
I get different result when I put a coordinate into epsg.io:https://epsg.io/transform#s_srs=3857&t_srs=4326&x=1820541.7625204&y=6134799.8559301
vs.
xyToLatLng([ 1820541.7625204194 , 6134799.8559301235 ]) -> { lat: 48.20880202465933 , lng: 16.372499716642768 }
epsg.io: 48.1677013 16.354205
xyToLL : 48.2088020 16.372499
It would be really great if you could help me!
Thank you!
The text was updated successfully, but these errors were encountered: