gpt4 book ai didi

javascript - 如何传递文本框的内容来设置谷歌地球插件中的相机?

转载 作者:行者123 更新时间:2023-11-28 08:09:32 30 4
gpt4 key购买 nike

目前我正在使用 Google 地球插件代码。此时我正在尝试根据某些文本框的内容移动相机。这是我目前拥有的代码。

var ge;

google.load("earth", "1");

function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
//create boxes
addSampleUIHtml(
'<input id="Altitude" type="text" value="500000"/>');
addSampleUIHtml(
'<input id="Longitude" type="text" value="2"/>');
addSampleUIHtml(
'<input id="Latitude" type="text" value="42"/>');
addSampleUIHtml(
'<input id="Heading" type="text" value="0"/>');
addSampleUIHtml(
'<input id="Tilt" type="text" value="0"/>');
addSampleUIHtml(
'<input id="Roll" type="text" value="0"/>');
addSampleButton('Move the camera', buttonClick);
}

function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);

// just for debugging purposes
document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}

function failureCallback(errorCode) {
}

function buttonClick() {

var AltitudeInBox=document.getElementById('Altitude').value

var CameraAt= ge.getView().copyAsCamera(ge.ALTITUDE_ABSOLUTE);
CameraAt.set ( 41.383, // latitude +-90
2.183 , // longitude +-180
AltitudeInBox, // altitude (m)
ge.ALTITUDE_ABSOLUTE, // reference altitude mode
0, //heading Direction (that is, North, South, East, West), in degrees. Default=0 (North). Values range from 0 to 360 degrees
0, //Tilt 0 to 360 degrees.
0 //Rotation, in degrees around the Z axis. -180 to +180 degrees.

ge.getView().setAbstractView(CameraAt)
}

当我将变量 AltitudeInBox 定义为 Altitude 框的内容时,勇气将传递给它。我厚颜无耻地使用警报函数 (alert(AltitudeInBox);),但是当我将变量 AltitudeInBox 作为函数 CameraAt.set 的参数传递时,我没有得到任何结果。我怀疑变量 AltitudeInBox 被分配为图表而不是数字,但不知道如何更改它。先感谢您。

最佳答案

好吧,我找到了解决方案。这是初学者的错误。声明如下:

 var AltitudeInBox=document.getElementById('Altitude').value

将高度框的内容指定为图表变量,但以下代码需要一个数字

   CameraAt.set   (  41.383, // latitude +-90
2.183 , // longitude +-180
AltitudeInBox, // altitude (m)
ge.ALTITUDE_ABSOLUTE, // reference altitude mode
0, //heading Direction (that is, North, South, East,West), in degrees. Default=0 (North). Values range from 0 to 360 degrees
0, //Tilt 0 to 360 degrees.
0 //Rotation, in degrees around the Z axis. -180 to +180degrees.

解决方案是使用 parseFloat() 或 parseInt(),如下所示。

   CameraAt.set   (  parseFloat(document.getElementById('Latitude').value),
parseFloat(document.getElementById('Longitude').value) ,
parseFloat(document.getElementById('Altitude').value),
ge.ALTITUDE_ABSOLUTE, //altitude mode
parseFloat(document.getElementById('Heading').value),
parseFloat(document.getElementById('Tilt').value),
parseFloat(document.getElementById('Roll').value) )

关于javascript - 如何传递文本框的内容来设置谷歌地球插件中的相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24443297/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com