Hello again,
You guys were brilliant earlier helping me find out how to calculate
camera altitude based on extent, but I've got another question.
I've got a small problem with my code posted below. In the setLat()
and setLng() functions I can't for the life of me get them to set when
you click
their respective buttons.
The quick fix is to comment out the two troublesome lines and simply
edit the source code for the desired latitude & longitude, but
ideally
I want the user to be able to input them just as they can input the
range. What puzzles me, is that using the exact same syntax works for
setting
the range, but doesn't work for setting the lat and lng.
My apologies if the code is a little messy, or if the fix for this is
something really simple. I'm not really sure if it's just
something wrong with my code or if it has to do with how I'm setting
my lookAt point within google earth.
Any help would greatly appreciated. Let me know if you need any
clarification.
Thanks!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /
>
<head>
<!--
Copyright 2008 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<title>Underlay Creator</title>
<!-- *** Replace the key below below with your own API key,
available at
http://code.google.com/apis/maps/signup.html *** -->
<script src="
http://www.google.com/jsapi?key=ABQIAAAAJjucYb-
UmLbNwb6Zr93UBBQcd1EN8YTzLvwr9D0CWHC9e2n4kRTOsbG1_9GnWONH739l8cAxZKvwqQ"></
script>
<script>
var ge;
var lat;
var lng;
var range;//range in nautical miles
google.load("earth", "1");
google.load("maps", "2");
function init() {
var content = document.getElementById('content');
var inputHTML = '<input id="latitude" value="Latitude"/>';
inputHTML += '<input type="button" onclick="setLat()" value="setLat
()"/>';
inputHTML += '<input id="longitude" value="Longitude"/>';
inputHTML += '<input type="button" onclick="setLng()" value="setLng
()"/>';
inputHTML += '<input id="rangeNM" value="RangeNM"/>';
inputHTML += '<input type="button" onclick="setRangeAndFly()"
value="setRangeAndFly()"/>';
content.innerHTML = inputHTML;
google.earth.createInstance('content', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
//un-comment line below to add a navigation control
//ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
//ge.setScaleLegendVisibility
//un-comment lines below to add desired layers
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false);
//ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
//ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}
function failureCB(errorCode) {}
function setLat() {
lat = document.getElementById('latitude').value;
//if you un-comment the line below, and comment the line above then
it //works as intended
//lat = 39.58031;
}
function setLng() {
lng = document.getElementById('longitude').value;
//if you un-comment the line below, and comment the line above then
it //works as intended
//lng = -108.10705;
}
function setRangeAndFly() {
range = document.getElementById('rangeNM').value;
latOffsetNauticalMiles = range;
latOffsetMiles = latOffsetNauticalMiles * 1.150779448;
latOffsetDegrees = latOffsetMiles / 69.172;
var r = 6378137; //var r = 6378700;
var F = 30.25;
var A = Math.max((lat + latOffsetDegrees), (lat - latOffsetDegrees))
- Math.min((lat + latOffsetDegrees), (lat -
latOffsetDegrees));
A = A * Math.PI / 180.0;
var x = r * Math.tan(A / 2);
var a = x / (Math.tan( F * Math.PI / 180.0));
var lookAt = ge.createLookAt('');
lookAt.set(lat, lng, a, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 0);
ge.getView().setAbstractView(lookAt);
}
google.setOnLoadCallback(init);
</script>
</head>
<body style="font-family: Arial;font-size:13px;border: 0 none;">
<div id="content" style="width: 1024px; height: 1024px;">
Loading...
</div>
</body>
</html>