factor: Switch to Web Mercator coordinates
This commit is contained in:
@@ -188,6 +188,14 @@ export default {
|
||||
});
|
||||
if (renderer) renderer.render(scene, camera);
|
||||
};
|
||||
|
||||
// Convert lat/lon to Web Mercator meters (EPSG:3857)
|
||||
const lonLatToWebMercator = (lon, lat) => {
|
||||
const x = lon * 20037508.34 / 180;
|
||||
let y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
|
||||
y = y * 20037508.34 / 180;
|
||||
return { x, y };
|
||||
};
|
||||
|
||||
const initThreeJS = () => {
|
||||
scene = new THREE.Scene();
|
||||
@@ -230,10 +238,14 @@ export default {
|
||||
const ne = bounds.getNorthEast();
|
||||
const sw = bounds.getSouthWest();
|
||||
|
||||
camera.left = sw.lng;
|
||||
camera.right = ne.lng;
|
||||
camera.top = ne.lat;
|
||||
camera.bottom = sw.lat;
|
||||
// Convert lat/lon bounds to Web Mercator meters
|
||||
const neMerc = lonLatToWebMercator(ne.lng, ne.lat);
|
||||
const swMerc = lonLatToWebMercator(sw.lng, sw.lat);
|
||||
|
||||
camera.left = swMerc.x;
|
||||
camera.right = neMerc.x;
|
||||
camera.top = neMerc.y;
|
||||
camera.bottom = swMerc.y;
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
Reference in New Issue
Block a user