earth-singlesystem.html 21.7 KB
Newer Older
LM's avatar
LM committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <!-- <head> -->
<!-- QGroundControl -->
    <title>QGroundControl Google Earth View</title>
    <!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite-beta.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi?key=ABQIAAAA5Q6wxQ6lxKS8haLVdUJaqhSjosg_0jiTTs2iXtkDVG0n0If1mBRHzhWw5VqBZX-j4NuzoVpU-UaHVg"></script>
    <script type="text/javascript">
google.load("earth", "1", { 'language': 'en'});

var ge = null;
var initialized = false;
var currAircraft = 0;
var followEnabled = false;
var lineAltitudeOffset = 0.5; ///< 0.5 m higher than waypoint, prevents the line from entering the ground

var lastLat = 0;
var lastLon = 0;
var lastAlt = 0;
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;

var currentCameraLatitude = 0;
var currentCameraLongitude = 0;
var currentCameraAltitude = 0;

var currFollowHeading = 0.0;

var homeLat = 0;
var homeLon = 0;
var homeAlt = 0;
var homeViewRange = 800;
var homeLocation = null;
var homeGroundLevel = 0;

var currViewRange = 50.0;	///<< The current viewing range from this position (in meters)
var currTilt = 40.0;		///<< The tilt angle (in degrees)
var currFollowTilt = 40.0;
var currView = null;
var distanceMode = 0;

var viewMode = 0;
var lastTilt = currTilt;
var lastRoll = 0;
var lastHeading = 0;

var M_PI = 3.14159265;



var planeOrient;
var planeLoc;

var aircraft = [];
var aircraftLocations = [];
var aircraftLastLocations = [];
var attitudes = [];
var locations = [];
var trails = [];
var trailPlacemarks = [];
var trailsVisible = [];
var trailColors = [];
var waypoints = [];

var waypointLines = [];
var waypointLinePlacemarks = [];
var waypointLineColors = [];
//var waypointLines = [];
//var trailPlacemarks[id];
var lineStyle;

// Aircraft class
var planeColor = '6600ffff';

// Enable / disable dragging
var draggingAllowed = true;

// Waypoint interaction flags
var dragInfo = null;

var dragWaypointIndex = "";
var dragWaypointLatitude = 0;
var dragWaypointLongitude = 0;
var dragWaypointAltitude = 0;
var dragWaypointPending = false;

// Waypoint creation flags
var newWaypointLatitude = 0;
var newWaypointLongitude = 0;
var newWaypointAltitude = 0;
var newWaypointPending = false;

var clickMode = 0;

var homePlacemark = null;


// Data / heightmap
var heightMapPlacemark = null;
var heightMapModel = null;


function getGlobal(variable)
{
	return variable;
}

function getDraggingAllowed()
{
	return draggingAllowed;
}

function setDistanceMode(mode)
{
	distanceMode = mode;
}

function setDraggingAllowed(allowed)
{
	draggingAllowed = allowed;
}

function sampleCurrentPosition()
{
    var thisView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
	currentCameraLatitude = thisView.getLatitude();
	currentCameraLongitude = thisView.getLongitude();
	currentCameraGroundAltitude = ge.getGlobe().getGroundAltitude(currentCameraLatitude, currentCameraLongitude);
}

function enableSetHomeMode()
{
	clickMode = 1;
}

function setLookAtLatLon(lat, lon)
{
	// Keep the current altitude above ground, just move the position
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	currView.setLatitude(lat);
	currView.setLongitude(lon);
	ge.getView().setAbstractView(currView);
}

function setNewWaypointPending(pending)
{
	newWaypointPending = pending;
	document.getElementById('JScript_newWaypointPending').setAttribute('value',pending);
}

function setDragWaypointPending(pending)
{
	dragWaypointPending = pending;
	document.getElementById('JScript_dragWaypointPending').setAttribute('value',pending);
}

function isInitialized()
{
	return initialized;
}


function init()
{
	google.earth.createInstance("map3d", initCallback, failureCallback);
}

function setFollowEnabled(enable)
{
	followEnabled = enable;
}

function enableEventListener()
{
// listen for mousedown on the window (look specifically for point placemarks)
google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event)
{
if (clickMode == 1)
    {
    	// Set home mode
    	dragWaypointIndex = 'HOME';
    	document.getElementById('JScript_dragWaypointIndex').setAttribute('value',dragWaypointIndex);
		dragWaypointLatitude = event.getLatitude();
		dragWaypointLongitude = event.getLongitude();
		dragWaypointAltitude = ge.getGlobe().getGroundAltitude(dragWaypointLatitude, dragWaypointLongitude);
		dragWaypointPending = true;
		document.getElementById('JScript_dragWaypointLatitude').setAttribute('value',dragWaypointLatitude);
	   document.getElementById('JScript_dragWaypointLongitude').setAttribute('value',dragWaypointLongitude);
	   document.getElementById('JScript_dragWaypointAltitude').setAttribute('value',dragWaypointAltitude);
	   document.getElementById('JScript_dragWaypointPending').setAttribute('value',true);
	   setGCSHome(dragWaypointLatitude, dragWaypointLongitude, dragWaypointAltitude);
}
    
  if (event.getTarget().getType() == 'KmlPlacemark' &&
      event.getTarget().getGeometry().getType() == 'KmlPoint') {
    var placemark = event.getTarget();
    event.preventDefault();
      if (draggingAllowed)
  {
  	if (clickMode == 0)
  	{
    dragInfo = {
      placemark: event.getTarget(),
      dragged: false
    };
    }
  }
  }
});

// listen for mousemove on the globe
google.earth.addEventListener(ge.getGlobe(), 'mousemove', function(event)
{
  if (draggingAllowed && (clickMode == 0))
  {
  	if (dragInfo)
  	{
    	event.preventDefault();
    	var point = dragInfo.placemark.getGeometry();
    	point.setLatitude(event.getLatitude());
    	point.setLongitude(event.getLongitude());
    	dragInfo.dragged = true;
    	dragWaypointIndex = dragInfo.placemark.getDescription();
		document.getElementById('JScript_dragWaypointIndex').setAttribute('value',dragWaypointIndex);
		dragWaypointLatitude = event.getLatitude();
		dragWaypointLongitude = event.getLongitude();
		dragWaypointAltitude = point.getAltitude();
		dragWaypointPending = true;
		document.getElementById('JScript_dragWaypointLatitude').setAttribute('value',dragWaypointLatitude);
	    document.getElementById('JScript_dragWaypointLongitude').setAttribute('value',dragWaypointLongitude);
	    document.getElementById('JScript_dragWaypointAltitude').setAttribute('value',dragWaypointAltitude);
	    document.getElementById('JScript_dragWaypointPending').setAttribute('value',true);
  	}
  }
});

// listen for mouseup on the window
google.earth.addEventListener(ge.getWindow(), 'mouseup', function(event)
{
  if (draggingAllowed && (clickMode == 0))
  {
  if (dragInfo) {
    if (dragInfo.dragged)
    {
      	// if the placemark was dragged, prevent balloons from popping up
      	event.preventDefault();
      	// Get drag end location
      	dragWaypointIndex = dragInfo.placemark.getDescription();
		document.getElementById('JScript_dragWaypointIndex').setAttribute('value',dragWaypointIndex);
      	var point = dragInfo.placemark.getGeometry();
      	dragWaypointLatitude = event.getLatitude();
		dragWaypointLongitude = event.getLongitude();
		dragWaypointAltitude = point.getAltitude();
    	dragWaypointPending = true;
		document.getElementById('JScript_dragWaypointLatitude').setAttribute('value',dragWaypointLatitude);
	   document.getElementById('JScript_dragWaypointLongitude').setAttribute('value',dragWaypointLongitude);
	   document.getElementById('JScript_dragWaypointAltitude').setAttribute('value',dragWaypointAltitude);
	   document.getElementById('JScript_dragWaypointPending').setAttribute('value',true);
    }
    
    dragInfo = null;
  }
  }
      clickMode = 0;
});

// Listen for wp creation request on the globe

google.earth.addEventListener(ge.getGlobe(), 'dblclick', function(event){
	if (draggingAllowed)
	{
       event.preventDefault();
       newWaypointLatitude = event.getLatitude();
       newWaypointLongitude = event.getLongitude();
       newWaypointAltitude = ge.getGlobe().getGroundAltitude(newWaypointLatitude, newWaypointLongitude);
       newWaypointPending = true;
	   document.getElementById('JScript_newWaypointLatitude').setAttribute('value',newWaypointLatitude);
	   document.getElementById('JScript_newWaypointLongitude').setAttribute('value',newWaypointLongitude);
	   document.getElementById('JScript_newWaypointAltitude').setAttribute('value',newWaypointAltitude);
	   document.getElementById('JScript_newWaypointPending').setAttribute('value',true);
    }
}); 
}



function setCurrAircraft(id)
{
	currAircraft = id;
}

function setGCSHome(lat, lon, alt)
{
	// Only update if position actually changed
	if (lat != homeLat || lon != homeLon || alt != homeAlt)
	{
	homeLat = lat;
	homeLon = lon;
	homeAlt = alt;
	
	
	if (homePlacemark == null)
	{
		var placemark = ge.createPlacemark(''); 
	    var icon = ge.createIcon(''); 
	    icon.setHref('http://google-maps-icons.googlecode.com/files/blackH.png'); 
	    var style = ge.createStyle(''); 
	    style.getIconStyle().setIcon(icon); 
	    //style.getIconStyle().setScale(0.5); 
	    placemark.setStyleSelector(style);
	    placemark.setDescription('HOME');

	    // Set the placemark's location.   
	    homeLocation = ge.createPoint(''); 
	    homeLocation.setLatitude(lat); 
	    homeLocation.setLongitude(lon);
	    homeLocation.setAltitude(alt); 
	    placemark.setGeometry(homeLocation);  

	    // Add the placemark to Earth. 
	    ge.getFeatures().appendChild(placemark);
	    
	    homePlacemark = placemark;
	    }
	    else
	    {
	    	var location = ge.createPoint('');
	    	if (location.getLatitude() != lat || location.getLongitude() != lon || location.getAltitude() != alt)
	    	{
	    		location.setLatitude(lat); 
	    		location.setLongitude(lon);
	    		location.setAltitude(alt); 
	    		homePlacemark.setGeometry(location);
	    		homePlacemark.setDescription('HOME');
	    	}
	    }

	    homeGroundLevel = ge.getGlobe().getGroundAltitude(lat,lon);
	    if (homeGroundLevel == 0)
	    {
		    homeGroundLevel = alt;
	    }
	}
}

function updateWaypointListLength(id, len)
{
	// Delete any non-needed waypoints
	if (waypoints.length > len)
	{
		var initialLength = waypoints.length;
		for (var i=len; i<initialLength; i++)
		{
			var placemark = waypoints.pop();
		    ge.getFeatures().removeChild(placemark);
		    waypointLines[id].getCoordinates().pop();
		}
	}
}

function updateWaypoint(id, index, lat, lon, alt, action)
{
	// Check if waypoint exists
	if (waypoints.length > index)
	{
		// Waypoint exists
		// Set the placemark's location.   
	    var location = ge.createPoint(''); 
	    location.setLatitude(lat); 
	    location.setLongitude(lon);
	    location.setAltitude(alt); 
	    waypoints[index].setGeometry(location);
	    waypoints[index].setDescription(index+"");
	    
	    // Set the WP line location
	    waypointLines[id].getCoordinates().setLatLngAlt(index, lat, lon, alt);
	}
	else
	{
		// Waypoint does not exist yet
		var placemark = ge.createPlacemark(''); 
	    var icon = ge.createIcon('');
	    var numberstring = index;
	    if (index < 10) numberstring = '0' + numberstring
	    icon.setHref('http://google-maps-icons.googlecode.com/files/red' + numberstring +'.png'); 
	    var style = ge.createStyle('');
	    //console.log('WP ICON created:' + 'http://google-maps-icons.googlecode.com/files/red' + numberstring +'.png');
	    style.getIconStyle().setIcon(icon); 
	    //style.getIconStyle().setScale(0.5); 
	    placemark.setStyleSelector(style);
	    placemark.setDescription(index+"");

	    // Set the placemark's location.   
	    var location = ge.createPoint(''); 
	    location.setLatitude(lat); 
	    location.setLongitude(lon);
	    location.setAltitude(alt+lineAltitudeOffset); 
	    placemark.setGeometry(location);  

	    // Add the placemark to Earth. 
	    ge.getFeatures().appendChild(placemark); 
		waypoints[index] = placemark;
        
        // Add LineString points
	    waypointLines[id].getCoordinates().pushLatLngAlt(lat, lon, alt);
	}
}

function createAircraft(id, type, color)
{
	planePlacemark = ge.createPlacemark('');
	planePlacemark.setName('aircraft');
	planeModel = ge.createModel('');
	ge.getFeatures().appendChild(planePlacemark);
	planeLoc = ge.createLocation('');
	planeModel.setLocation(planeLoc);
	planeLink = ge.createLink('');
	planeOrient = ge.createOrientation(''); 
	planeModel.setOrientation(planeOrient);
	
	var factor = 1.0;

	//planeLink.setHref('http://www.asl.ethz.ch/people/rudink/senseSoarDummy.dae'); 
	planeLink.setHref('http://qgroundcontrol.org/_media/users/models/sfly-hex.dae');
	factor = 1.0/1000.0;
	//planeLink.setHref('http://qgroundcontrol.org/_media/users/models/ascent-park-glider.dae');
	planeModel.setLink(planeLink);
	var scale = planeModel.getScale();
	scale.set(scale.getX()*factor, scale.getY()*factor, scale.getZ()*factor)
	planeModel.setScale(scale);
	planeModel.setAltitudeMode (ge.ALTITUDE_ABSOLUTE); 

	planeLoc.setLatitude(currLat);
	planeLoc.setLongitude(currLon);
	planeLoc.setAltitude(currAlt);

	planePlacemark.setGeometry(planeModel);
          
	// Write into global structure
	aircraft[id] = planePlacemark;
	attitudes[id] = planeOrient;
	aircraftLocations[id] = planeLoc;
	aircraftLastLocations[id] = ge.createLocation('');
          
	createTrail(id, color);
	createWaypointLine(id, color);
}

function createTrail(id, color)
{
	trailPlacemarks[id] = ge.createPlacemark('');
	// Create the placemark
	// Create the LineString; set it to extend down to the ground
	// and set the altitude mode
	trails[id] = ge.createLineString('');
	trailPlacemarks[id].setGeometry(trails[id]);
	trails[id].setExtrude(false);
	trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);

	// Create a style and set width and color of line
	trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
	lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
	lineStyle.setWidth(5);
	trailColors[id] = color;
	lineStyle.getColor().set('00000000');  // aabbggrr format

	trailsVisible[id] = false;
}

function createWaypointLine(id, color)
{
	// Create the placemark
	waypointLinePlacemarks[id] = ge.createPlacemark('');
	// Create the LineString; set it to extend down to the ground
	// and set the altitude mode
	waypointLines[id] = ge.createLineString('');
	waypointLinePlacemarks[id].setGeometry(waypointLines[id]);
	waypointLines[id].setExtrude(false);
	waypointLines[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);

	// Add LineString points
	//lineString.getCoordinates().pushLatLngAlt(48.754, -121.835, 700);

	// Create a style and set width and color of line
	waypointLinePlacemarks[id].setStyleSelector(ge.createStyle(''));
	lineStyle = waypointLinePlacemarks[id].getStyleSelector().getLineStyle();
	lineStyle.setWidth(15);
	waypointLineColors[id] = color;
	lineStyle.getColor().set(color);  // aabbggrr format

        

        // Create a style and set width and color of line
        //waypointLinePlacemarks[id].setStyleSelector(ge.createStyle(''));
        //lineStyle = waypointLinePlacemarks[id].getStyleSelector().getLineStyle();
        //lineStyle.setWidth(15);
        //lineStyle.getColor().set(waypointLineColors[id]);  // aabbggrr format
        //lineStyle.getColor().set(color);  // aabbggrr format

	// Add the feature to Earth
	ge.getFeatures().appendChild(waypointLinePlacemarks[id]);
}

function clearTrail(id)
{
	ge.getFeatures().removeChild(trailPlacemarks[id]);
	trailPlacemarks[id] = null;
	var isVisible = trailsVisible[id];
	createTrail(id, trailColors[id]);
	if (isVisible)
	{
		showTrail(id);
	}
}

function hideTrail(id)
{
	trailsVisible[id] = false;
	ge.getFeatures().removeChild(trailPlacemarks[id]);
}

function showTrail(id)
{
	ge.getFeatures().appendChild(trailPlacemarks[id]);
	trailsVisible[id] = true;
}

function setViewRange(dist)
{
	currViewRange = dist;
}

function addTrailPosition(id, lat, lon, alt)
{
	//trails[id].setExtrude(false);
    //trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);

    // Add LineString points
	trails[id].getCoordinates().pushLatLngAlt(lat, lon, alt);

    // Create a style and set width and color of line
    trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
    lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
    lineStyle.setWidth(5);
    lineStyle.getColor().set(trailColors[id]);  // aabbggrr format
}

function initCallback(object)
{
    ge = object;
    ge.getWindow().setVisibility(true);
    ge.getOptions().setStatusBarVisibility(true); 
    ge.getOptions().setScaleLegendVisibility(true);
    //ge.getOptions().setFlyToSpeed(5.0); 
    ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT); 
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
        
    ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true); 
    ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true); 
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true); 
    ge.getLayerRoot().enableLayerById(ge.LAYER_TREES, true);
    
    enableEventListener();
	document.getElementById('JScript_initialized').setAttribute('value','true');
	
	// Load heightmap
	// http://www.inf.ethz.ch/personal/lomeier/data/untex-environment.dae
	
	heightMapPlacemark = ge.createPlacemark('');
	heightMapPlacemark.setName('aircraft');
	heightMapModel = ge.createModel('');
	ge.getFeatures().appendChild(heightMapPlacemark);
	planeLoc = ge.createLocation('');
	heightMapModel.setLocation(planeLoc);
	planeLink = ge.createLink('');
	planeOrient = ge.createOrientation(''); 
	heightMapModel.setOrientation(planeOrient); 

	planeLink.setHref('http://www.inf.ethz.ch/personal/lomeier/data/untex-environment.dae'); 
	heightMapModel.setLink(planeLink);
	var scale = heightMapModel.getScale();
	var factor = 1.0;//1.0/1000.0;
	scale.set(scale.getX()*factor, scale.getY()*factor, scale.getZ()*factor)
	heightMapModel.setScale(scale);
	heightMapModel.setAltitudeMode (ge.ALTITUDE_ABSOLUTE); 

	planeLoc.setLatitude(currLat);
	planeLoc.setLongitude(currLon);
	planeLoc.setAltitude(currAlt);

	heightMapPlacemark.setGeometry(heightMapModel);
	
    initialized = true;
}

function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
	if (id == currAircraft)
	{
		if (lastLat == 0)
		{
			lastLat = currLat;
			lastLon = currLon;
		}
		
		currLat = lat;
		currLon = lon;
		var trueGroundAlt = ge.getGlobe().getGroundAltitude(lat, lon);
		if (trueGroundAlt < alt)
		{
		  currAlt = alt;
	    }
	    else
	    {
	      currAlt = trueGroundAlt+0.1;
	    }
		// Interpolate between t-1 and t and set new states
		lastLat = lastLat*0.5+currLat*0.5;
		lastLon = lastLon*0.5+currLon*0.5;
		lastAlt = lastAlt*0.5+currAlt*0.5;
	
		planeOrient.setRoll(+((roll/M_PI))*180.0);
		planeOrient.setTilt(-((pitch/M_PI))*180.0);
		planeOrient.setHeading(((yaw/M_PI))*180.0-90.0);
		planeModel.setOrientation(planeOrient);
	
		currFollowHeading = currFollowHeading*0.95+0.05*(((yaw/M_PI))*180.0);
    
    	planeLoc.setLatitude(lastLat);
    	planeLoc.setLongitude(lastLon);
    	planeLoc.setAltitude(lastAlt);
    	planeModel.setLocation(planeLoc);
    
    	if (followEnabled) updateFollowAircraft();
    }
}

function enableDaylight(enabled)
{
	if(enabled)
	{
		ge.getSun().setVisibility(true);
	}
	else
	{
		ge.getSun().setVisibility(false);
	}
}

function enableAtmosphere(enabled)
{
	ge.getOptions().setAtmosphereVisibility(enabled);
}
		
function goHome()
{
	var currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
	currView.setLatitude(homeLat);
	currView.setLongitude(homeLon);
	currView.setAltitude(homeAlt);
	currView.setRange(homeViewRange);
	currView.setTilt(currTilt);
	ge.getView().setAbstractView(currView);
}

function setCurrentAircraft(id)
{
	currAircraft = id;
}

/** @brief Set the current view mode
 *
 * @param mode 0: side map view, 1: top/north map view, 2: fixed chase cam, 3: free chase cam
 */
function setViewMode(mode)
{
	var currView = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
	
	if (mode == 0)
	{
		currView.setTilt(lastTilt);
		currView.setHeading(lastHeading);
	}
	
	if (mode == 1 && viewMode != mode)
	{
		lastTilt = currView.getTilt();
		lastHeading = currView.getHeading();
		currView.setTilt(0);
		currView.setHeading(0);
	}
	
	viewMode = mode;
	
	ge.getView().setAbstractView(currView);
}

function updateFollowAircraft()
{
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
	currView.setLatitude(lastLat);
	currView.setLongitude(lastLon);
	
	if (distanceMode == 1)
	{
		var groundAltitude = ge.getGlobe().getGroundAltitude(lastLat, lastLon);
		currView.setAltitude(groundAltitude);
	}
	
	if (distanceMode == 0) currView.setAltitude(lastAlt);

	currView.setRange(currViewRange);
	
	if (viewMode != 3) // VIEW_MODE_CHASE_FREE
	{
		currView.setTilt(currFollowTilt);
		currView.setHeading(currFollowHeading);
	}
	ge.getView().setAbstractView(currView);
}

function failureCallback(object)
{
}
</script>


    <style type="text/css">
    html, body {
      margin: 0;
      width: 100%;
      height: 100%;
    }
    </style>
  </head>
  <body onload='init()' id='body'>
    <center>
      <div id='map3d' style='margin: 0; spacing: 0; height: 100%; width: 100%'></div>
    </center>
	<input type="hidden" id="JScript_initialized" value="false" />
    <input type="hidden" id="JScript_dragWaypointIndex" value="0" />
	<input type="hidden" id="JScript_dragWaypointLatitude" value="0" />
	<input type="hidden" id="JScript_dragWaypointLongitude" value="0" />
	<input type="hidden" id="JScript_dragWaypointAltitude" value="0" />
	<input type="hidden" id="JScript_dragWaypointPending" value="false" />
	<input type="hidden" id="JScript_newWaypointLatitude" value="0" />
	<input type="hidden" id="JScript_newWaypointLongitude" value="0" />
	<input type="hidden" id="JScript_newWaypointAltitude" value="0" />
	<input type="hidden" id="JScript_newWaypointPending" value="false" />
	<input type="hidden" id="JScript_currentCameraLatitude" value="0" />
	<input type="hidden" id="JScript_currentCameraLongitude" value="0" />
	<input type="hidden" id="JScript_currentCameraGroundAltitude" value="0" />
  </body>
</html>