earth.html 21 KB
Newer Older
oberion's avatar
oberion committed
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 3

<html>
pixhawk's avatar
pixhawk committed
4
  <head>
5 6
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <!-- <head> -->
7
<!-- QGroundControl -->
pixhawk's avatar
pixhawk committed
8 9
    <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 *** -->
lm's avatar
lm committed
10
    <!--<script type="text/javascript" src="https://getfirebug.com/firebug-lite-beta.js"></script>-->
11 12
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
    <script type="text/javascript">
13
google.load("earth", "1", { 'language': 'en'});
pixhawk's avatar
pixhawk committed
14 15

var ge = null;
16
var initialized = false;
lm's avatar
lm committed
17
var currAircraft = 0;
18
var followEnabled = false;
19 20 21

var lastLat = 0;
var lastLon = 0;
lm's avatar
lm committed
22
var lastAlt = 0;
23 24 25
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;
26 27 28 29 30

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

31
var currFollowHeading = 0.0;
32 33 34 35

var homeLat = 0;
var homeLon = 0;
var homeAlt = 0;
36
var homeViewRange = 800;
37 38 39
var homeLocation = null;
var homeGroundLevel = 0;

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

46
var viewMode = 0;
47
var lastTilt = currTilt;
48 49 50
var lastRoll = 0;
var lastHeading = 0;

51 52
var M_PI = 3.14159265;

53 54 55 56 57


var planeOrient;
var planeLoc;

58
var aircraft = [];
59 60
var aircraftLocations = [];
var aircraftLastLocations = [];
61 62 63
var attitudes = [];
var locations = [];
var trails = [];
64 65 66
var trailPlacemarks = [];
var trailsVisible = [];
var trailColors = [];
pixhawk's avatar
pixhawk committed
67
var waypoints = [];
LM's avatar
LM committed
68 69 70 71

var waypointLines = [];
var waypointLinePlacemarks = [];
var waypointLineColors = [];
pixhawk's avatar
pixhawk committed
72
//var waypointLines = [];
73
//var trailPlacemarks[id];
74
var lineStyle;
75 76

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

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
// 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;

97 98
var clickMode = 0;

99 100
var homePlacemark = null;

101 102 103 104 105 106 107 108 109 110
function getGlobal(variable)
{
	return variable;
}

function getDraggingAllowed()
{
	return draggingAllowed;
}

111 112 113 114 115
function setDistanceMode(mode)
{
	distanceMode = mode;
}

116 117
function setDraggingAllowed(allowed)
{
118
	draggingAllowed = allowed;
119 120
}

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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);
}

143 144 145
function setNewWaypointPending(pending)
{
	newWaypointPending = pending;
146
	document.getElementById('JScript_newWaypointPending').setAttribute('value',pending);
147 148 149 150 151
}

function setDragWaypointPending(pending)
{
	dragWaypointPending = pending;
152
	document.getElementById('JScript_dragWaypointPending').setAttribute('value',pending);
153
}
154 155 156 157 158 159

function isInitialized()
{
	return initialized;
}

pixhawk's avatar
pixhawk committed
160

161 162
function init()
{
163 164 165
	google.earth.createInstance("map3d", initCallback, failureCallback);
}

pixhawk's avatar
pixhawk committed
166 167 168 169 170
function setFollowEnabled(enable)
{
	followEnabled = enable;
}

171 172 173 174 175
function enableEventListener()
{
// listen for mousedown on the window (look specifically for point placemarks)
google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event)
{
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
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);
}
    
192 193 194
  if (event.getTarget().getType() == 'KmlPlacemark' &&
      event.getTarget().getGeometry().getType() == 'KmlPoint') {
    var placemark = event.getTarget();
195 196 197
    event.preventDefault();
      if (draggingAllowed)
  {
198 199
  	if (clickMode == 0)
  	{
200 201 202 203
    dragInfo = {
      placemark: event.getTarget(),
      dragged: false
    };
204
    }
205 206 207 208 209 210 211
  }
  }
});

// listen for mousemove on the globe
google.earth.addEventListener(ge.getGlobe(), 'mousemove', function(event)
{
212
  if (draggingAllowed && (clickMode == 0))
213 214 215 216 217 218 219 220
  {
  if (dragInfo) {
    event.preventDefault();
    var point = dragInfo.placemark.getGeometry();
    point.setLatitude(event.getLatitude());
    point.setLongitude(event.getLongitude());
    dragInfo.dragged = true;
    dragWaypointIndex = dragInfo.placemark.getDescription();
221
	document.getElementById('JScript_dragWaypointIndex').setAttribute('value',dragWaypointIndex);
222 223 224 225
	dragWaypointLatitude = event.getLatitude();
	dragWaypointLongitude = event.getLongitude();
	dragWaypointAltitude = point.getAltitude();
	dragWaypointPending = true;
226 227 228 229
	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);
230 231 232 233 234 235 236
  }
  }
});

// listen for mouseup on the window
google.earth.addEventListener(ge.getWindow(), 'mouseup', function(event)
{
237
  if (draggingAllowed && (clickMode == 0))
238 239 240 241 242 243 244 245
  {
  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();
246
		document.getElementById('JScript_dragWaypointIndex').setAttribute('value',dragWaypointIndex);
247 248 249 250 251
      	var point = dragInfo.placemark.getGeometry();
      	dragWaypointLatitude = event.getLatitude();
		dragWaypointLongitude = event.getLongitude();
		dragWaypointAltitude = point.getAltitude();
    	dragWaypointPending = true;
252 253 254 255
		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);
256 257 258 259 260
    }
    
    dragInfo = null;
  }
  }
261
      clickMode = 0;
262 263 264 265 266 267 268 269 270 271 272 273
});

// 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;
274 275 276 277
	   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);
278 279 280 281
    }
}); 
}

282 283


284 285 286 287
function setCurrAircraft(id)
{
	currAircraft = id;
}
288 289 290

function setGCSHome(lat, lon, alt)
{
291 292 293
	// Only update if position actually changed
	if (lat != homeLat || lon != homeLon || alt != homeAlt)
	{
294 295 296 297 298
	homeLat = lat;
	homeLon = lon;
	homeAlt = alt;
	
	
299 300
	if (homePlacemark == null)
	{
301 302 303 304 305 306
	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); 
307 308
	    placemark.setStyleSelector(style);
	    placemark.setDescription('HOME');
309 310 311 312 313 314 315 316 317

	    // 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. 
318 319 320 321 322 323
	    ge.getFeatures().appendChild(placemark);
	    
	    homePlacemark = placemark;
	    }
	    else
	    {
324 325 326 327 328 329 330 331 332
	    	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');
	    	}
333
	    }
334 335 336 337 338 339

	    homeGroundLevel = ge.getGlobe().getGroundAltitude(lat,lon);
	    if (homeGroundLevel == 0)
	    {
		    homeGroundLevel = alt;
	    }
340
	}
pixhawk's avatar
pixhawk committed
341 342
}

pixhawk's avatar
pixhawk committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
function updateWaypointListLength(id, len)
{
	// Delete any non-needed waypoints
	if (waypoints.length > len)
	{
		for (var i=len; i<waypoints.length; i++)
		{
			var placemark = waypoints.pop();
		    ge.getFeatures().removeChild(placemark);
		}
	}
}

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); 
lm's avatar
lm committed
367
	    waypoints[index].setGeometry(location);
368
	    waypoints[index].setDescription(index+"");
pixhawk's avatar
pixhawk committed
369 370 371 372 373 374 375 376 377
	}
	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'); 
lm's avatar
lm committed
378
	    var style = ge.createStyle('');
379
	    //console.log('WP ICON created:' + 'http://google-maps-icons.googlecode.com/files/red' + numberstring +'.png');
pixhawk's avatar
pixhawk committed
380 381
	    style.getIconStyle().setIcon(icon); 
	    //style.getIconStyle().setScale(0.5); 
382 383
	    placemark.setStyleSelector(style);
	    placemark.setDescription(index+"");
pixhawk's avatar
pixhawk committed
384 385 386 387 388 389 390 391 392 393 394

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

	    // Add the placemark to Earth. 
	    ge.getFeatures().appendChild(placemark); 
		waypoints[index] = placemark;
oberion's avatar
oberion committed
395
	}
LM's avatar
LM committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
		
		// Add waypoint line
	    waypointLines[id].setExtrude(false);
        waypointLines[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);

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

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

        // Add the feature to Earth
        //if (waypointLinesVisible[id] == true) 
oberion's avatar
oberion committed
413
        //ge.getFeatures().replaceChild(waypointLinePlacemarks[id], waypointLinePlacemarks[id]);  // does not work
LM's avatar
LM committed
414
	
pixhawk's avatar
pixhawk committed
415 416 417 418
	// Add connecting line
	
}

pixhawk's avatar
pixhawk committed
419
function createAircraft(id, type, color)
420
{
421
	      planePlacemark = ge.createPlacemark('');
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
          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); 

          planeLink.setHref('http://qgroundcontrol.org/_media/users/models/multiplex-twinstar.dae');
          planeModel.setLink(planeLink);
          planeModel.setAltitudeMode (ge.ALTITUDE_ABSOLUTE); 

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

          planePlacemark.setGeometry(planeModel);
          
pixhawk's avatar
pixhawk committed
441 442 443
          // Write into global structure
          aircraft[id] = planePlacemark;
          attitudes[id] = planeOrient;
444
          aircraftLocations[id] = planeLoc;
445
		  aircraftLastLocations[id] = ge.createLocation('');
446
          //planeColor = color;
pixhawk's avatar
pixhawk committed
447
          
448
          createTrail(id, color);
LM's avatar
LM committed
449
          createWaypointLine(id, color);
450
          //console.log(color);
pixhawk's avatar
pixhawk committed
451 452 453 454
}

function createTrail(id, color)
{
455
          trailPlacemarks[id] = ge.createPlacemark('');
456
          // Create the placemark
pixhawk's avatar
pixhawk committed
457 458
// Create the LineString; set it to extend down to the ground
// and set the altitude mode
459 460 461 462
trails[id] = ge.createLineString('');
trailPlacemarks[id].setGeometry(trails[id]);
trails[id].setExtrude(false);
trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
pixhawk's avatar
pixhawk committed
463 464 465 466 467

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

// Create a style and set width and color of line
468 469
trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
pixhawk's avatar
pixhawk committed
470
lineStyle.setWidth(5);
471 472 473 474
trailColors[id] = color;
lineStyle.getColor().set('00000000');  // aabbggrr format

trailsVisible[id] = false;
pixhawk's avatar
pixhawk committed
475 476

// Add the feature to Earth
477
//ge.getFeatures().appendChild(trailPlacemarks[id]);
478

pixhawk's avatar
pixhawk committed
479 480
}

LM's avatar
LM committed
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
function createWaypointLine(id, color)
{
          waypointLinePlacemarks[id] = ge.createPlacemark('');
          // Create the placemark
// 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(10);
waypointLineColors[id] = color;
lineStyle.getColor().set('00000000');  // aabbggrr format

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

}

lm's avatar
lm committed
507
function clearTrail(id)
508 509 510 511 512 513 514 515 516 517 518 519
{
	ge.getFeatures().removeChild(trailPlacemarks[id]);
	trailPlacemarks[id] = null;
	var isVisible = trailsVisible[id];
	createTrail(id, trailColors[id]);
	if (isVisible)
	{
		showTrail(id);
	}
}

function hideTrail(id)
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
{
	trailsVisible[id] = false;
	ge.getFeatures().removeChild(trailPlacemarks[id]);
}

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

function setViewRange(dist)
{
	currViewRange = dist;
}

pixhawk's avatar
pixhawk committed
536 537
function addTrailPosition(id, lat, lon, alt)
{
538
	trails[id].setExtrude(false);
539
    trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
540

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

544 545 546 547 548 549
    // 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
    //lineStyle.getColor().set(color);  // aabbggrr format
550

551 552
    // Add the feature to Earth
    if (trailsVisible[id] == true) ge.getFeatures().replaceChild(trailPlacemarks[id], trailPlacemarks[id]);
pixhawk's avatar
pixhawk committed
553 554
}

555 556
function initCallback(object)
{
557 558 559 560
    ge = object;
    ge.getWindow().setVisibility(true);
    ge.getOptions().setStatusBarVisibility(true); 
    ge.getOptions().setScaleLegendVisibility(true);
pixhawk's avatar
pixhawk committed
561 562
    //ge.getOptions().setFlyToSpeed(5.0); 
    ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT); 
563
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
pixhawk's avatar
pixhawk committed
564
        
565 566 567 568
    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);
569 570
    
    enableEventListener();
571
	document.getElementById('JScript_initialized').setAttribute('value','true');
572
    initialized = true;
573 574 575 576 577 578
}

function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
	if (id == currAircraft)
	{
lm's avatar
lm committed
579 580 581
		if (lastLat == 0)
		{
			lastLat = currLat;
pixhawk's avatar
pixhawk committed
582
			lastLon = currLon;
lm's avatar
lm committed
583
		}
584 585
		currLat = lat;
		currLon = lon;
586 587 588 589 590 591 592 593 594
		var trueGroundAlt = ge.getGlobe().getGroundAltitude(lat, lon);
		if (trueGroundAlt < alt)
		{
		  currAlt = alt;
	    }
	    else
	    {
	      currAlt = trueGroundAlt+0.1;
	    }
pixhawk's avatar
pixhawk committed
595 596 597 598
		// Interpolate between t-1 and t and set new states
		lastLat = lastLat*0.8+currLat*0.2;
		lastLon = lastLon*0.8+currLon*0.2;
		lastAlt = lastAlt*0.8+currAlt*0.2;
599
		//currFollowHeading = ((yaw/M_PI)+1.0)*360.0;
600
	
601
	
602
	// FIXME Currently invalid conversion from right-handed z-down to z-up frame
603 604
	planeOrient.setRoll(((roll/M_PI))*180.0+180.0);
	planeOrient.setTilt(((pitch/M_PI))*180.0+180.0);
605
	planeOrient.setHeading(((yaw/M_PI))*180.0-90.0);
pixhawk's avatar
pixhawk committed
606
	
607
	currFollowHeading = ((yaw/M_PI))*180.0;
608
    
pixhawk's avatar
pixhawk committed
609 610 611
    planeLoc.setLatitude(lastLat);
    planeLoc.setLongitude(lastLon);
    planeLoc.setAltitude(lastAlt);
612
    planeModel.setLocation(planeLoc);
pixhawk's avatar
pixhawk committed
613 614
    
    if (followEnabled) updateFollowAircraft();
615
    }
pixhawk's avatar
pixhawk committed
616 617
}

618 619 620 621 622 623 624 625 626 627 628
function enableDaylight(enabled)
{
	if(enabled)
	{
		ge.getSun().setVisibility(true);
	}
	else
	{
		ge.getSun().setVisibility(false);
	}
}
629 630 631 632 633

function enableAtmosphere(enabled)
{
	ge.getOptions().setAtmosphereVisibility(enabled);
}
634
		
635 636 637 638 639 640 641 642 643
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);
pixhawk's avatar
pixhawk committed
644
}
645 646 647 648 649 650

function setCurrentAircraft(id)
{
	currAircraft = id;
}

651 652
/** @brief Set the current view mode
 *
653
 * @param mode 0: side map view, 1: top/north map view, 2: fixed chase cam, 3: free chase cam
654 655 656
 */
function setViewMode(mode)
{
657
	var currView = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
658 659 660
	
	if (mode == 0)
	{
661 662
		currView.setTilt(lastTilt);
		currView.setHeading(lastHeading);
663
	}
664
	if (mode == 1 && viewMode != mode)
665 666 667 668 669 670 671
	{
		lastTilt = currView.getTilt();
		lastHeading = currView.getHeading();
		currView.setTilt(0);
		currView.setHeading(0);
	}
	
672 673
	viewMode = mode;
	
674
	ge.getView().setAbstractView(currView);
675 676
}

677 678 679
function updateFollowAircraft()
{
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
680 681
	currView.setLatitude(lastLat);
	currView.setLongitude(lastLon);
682 683 684 685 686 687 688 689
	
	if (distanceMode == 1)
	{
		var groundAltitude = ge.getGlobe().getGroundAltitude(lastLat, lastLon);
		currView.setAltitude(groundAltitude);
	}
	
	if (distanceMode == 0) currView.setAltitude(lastAlt);
690

691
	currView.setRange(currViewRange);
692 693 694 695 696 697
	
	if (viewMode != 3) // VIEW_MODE_CHASE_FREE
	{
		currView.setTilt(currFollowTilt);
		currView.setHeading(currFollowHeading);
	}
698
	
699 700 701 702 703 704 705 706 707
	ge.getView().setAbstractView(currView);
}

function failureCallback(object)
{
}
</script>


pixhawk's avatar
pixhawk committed
708 709 710 711 712 713 714 715 716 717 718 719
    <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>
720 721 722 723 724 725 726 727 728 729
	<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" />
730 731 732
	<input type="hidden" id="JScript_currentCameraLatitude" value="0" />
	<input type="hidden" id="JScript_currentCameraLongitude" value="0" />
	<input type="hidden" id="JScript_currentCameraGroundAltitude" value="0" />
pixhawk's avatar
pixhawk committed
733 734
  </body>
</html>