Google's WebGL Globe允许将标记置于特定纬度。但是我们怎样才能得到当前位于屏幕前方或中心位置的lat长值。可能正在使用相机位置或旋转值。
我们可以使用下面的代码从lat long值中找到globe上的位置:
var phi = (90 - lat) * Math.PI / 180;
var theta = (180 - lng) * Math.PI / 180;
point.position.x = 200 * Math.sin(phi) * Math.cos(theta);
point.position.y = 200 * Math.cos(phi);
point.position.z = 200 * Math.sin(phi) * Math.sin(theta);
答案 0 :(得分:0)
据我所知,没有直接的方式来获得它。我看到两个选择:
您可以修改globe.js以“导出”rotation
对象:在this.scene = scene;
之后的globe.js末尾添加以下内容:
this.rotation = rotation;
或者,如果您不想修改globe.js,可以使用scene
属性,在那里找到相机,并使用其位置找到纬度和经度。可能有一种更简单的方法直接使用场景,不太确定。
请注意,globe使用three.js,因此您可以在任何搜索中使用它。
答案 1 :(得分:0)
另一种方法是使用THREE.Spherical()
:
for ($i = 1; isset($house[$i]) + 1; $i++) {
phi.innerHTML = "0";
theta.innerHTML = "0";
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 0, 10);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
var sphere = new THREE.Mesh(new THREE.SphereGeometry(2.5, 16, 12), new THREE.MeshBasicMaterial({color: "maroon", wireframe: true}));
scene.add(sphere);
renderer.domElement.addEventListener("mousedown", onMouseDown, false);
var center = new THREE.Vector2(); // default is [0.0], the center of the screen
var raycaster = new THREE.Raycaster();
var point = new THREE.Vector3();
var spherical = new THREE.Spherical();
var intersect;
function onMouseDown(event) {
raycaster.setFromCamera(center, camera);
intersect = raycaster.intersectObject(sphere);
if (intersect.length === 0) return;
sphere.worldToLocal(point.copy(intersect[0].point));
spherical.setFromVector3(point);
phi.innerHTML = THREE. Math.radToDeg(Math.PI * .5 - spherical.phi);
theta.innerHTML = THREE.Math.radToDeg(spherical.theta);
let marker = new THREE.Mesh(new THREE.BoxGeometry(.125, .125, .125), new THREE.MeshBasicMaterial({
color: Math.random() * 0xffffff,
wireframe: true
}));
marker.position.copy(intersect[0].point);
scene.add(marker);
}
render();
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
body {
overflow: hidden;
margin: 0;
}
#data{
font-family: Monotype;
color: white;
position: absolute;
}