我的项目地理根据两张单独的地理标记照片( 使用库lon_lat_to_cartesian)定位几何图形,第一个代表查看器,第二个代表几何图形。两者中的后者导致了问题。
从 exif 读取器传递 Lat'long' 数据,并成功转换为笛卡尔向量(对于第一张照片):
$("#imageInput").change(function() {
readBackgroundFile(this);
readExif(this, function(Data) {
resizeViewport(data.width, data.height);
position =lonLatToVector3(data.latitude, data.longitude);
console.log(position);
rotation = data.rotation;
updateScenePlacement(position, rotation, "viewer");
});
});
控制台日志:
Object { x: 0.30023741043429497, y: 0.9038698398763119, z: -0.3047569686449829 } glMain.js:153:5
至于第二张照片,Lat'long' 数据仍然从 exif 读取器传递,但不幸的是没有转换为笛卡尔向量,直到第 153:5 行控制台输出异常小的值:
$("#exifInput").change(function() {
readExif(this, function(data) {
position =lonLatToVector3(data.latitude, data.longitude);
console.log(position);
rotation = data.rotation;
updateScenePlacement(position, rotation, "placement");
});
});
控制台日志:
52.62939166666667 glMain.js:183:5
1.1289861111111112 glMain.js:186:5
Object { x: NaN, y: 0, z: NaN } glMain.js:162:5
Object { x: NaN, y: 0, z: NaN } glMain.js:220:5
Object { x: NaN, y: 0, z: NaN } glMain.js:226:5
Array [ NaN, 0, NaN ] glMain.js:228:0
Array [ NaN, 0, NaN ] glMain.js:230:0
Object { x: -0.002365838535297038, y: 0, z: 0.0009121675219786463 } glMain.js:162:5
为了确认这些值确实太小,我先上传了第二张照片,控制台产生了更合理的值——让我相信我的代码有问题?
这是我使用上面链接的库的特定功能:
function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();
//flips the Y axis
lat = PI / 2 - lat;
//distribute to sphere
out.set(
Math.sin( lat ) * Math.sin( lng ),
Math.cos( lat ),
Math.sin( lat ) * Math.cos( lng )
);
return out;
}
我已将完整版本的 JS 文件和控制台输出上传到我的 Git 要点:
glMain-V'lon_lat_to_cartesian-console
任何帮助将不胜感激,因为我已经看过很多次并且不知道该怎么做