earth.html 5.51 KB
Newer Older
1 2 3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"

<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 10 11
    <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="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
    <script  type="text/javascript">
12
google.load("earth", "1", { 'language': 'en'});
pixhawk's avatar
pixhawk committed
13 14

var ge = null;
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
var initialized = false;
var aircraft = new Array();
var currAircraft = 220;
var followAircraft = false;
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;

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

var currViewRange = 3.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 planeOrient;
var planeLoc;


// Aircraft class


function isInitialized()
{
	return initialized;
}

pixhawk's avatar
pixhawk committed
49 50

function init() {
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
	google.earth.createInstance("map3d", initCallback, failureCallback);
}





function setGCSHome(lat, lon, alt)
{
	homeLat = lat;
	homeLon = lon;
	homeAlt = alt;
	
	
	
	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);  

	    // 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); 

	    homeGroundLevel = ge.getGlobe().getGroundAltitude(lat,lon);
	    if (homeGroundLevel == 0)
	    {
		    homeGroundLevel = alt;
	    }
	
	
	
	
	
	
	goHome();
pixhawk's avatar
pixhawk committed
96 97
}

98 99
function initCallback(object)
{
pixhawk's avatar
pixhawk committed
100 101 102 103 104 105 106 107 108 109 110
  ge = object;
  ge.getWindow().setVisibility(true);
          ge.getOptions().setStatusBarVisibility(true); 
        ge.getOptions().setScaleLegendVisibility(true);
        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);
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
        
        // Now after the Google Earth initialization, initialize the GCS view
        setGCSHome(currLat, currLon, currAlt);
        
        
        // Create the first aircraft model
        	// Load 3D model
	      var 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); 

          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);
          
          setAircraftPositionAttitude(220, 47.3772, currLon, currAlt+50, 20, 15, 50);
          enableFollowing(true);
          updateFollowAircraft();
        initialized = true;
        
        
}

function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
	if (id == currAircraft)
	{
		currLat = lat;
		currLon = lon;
		currAlt = alt;
	}
	
	planeOrient.setRoll(roll); 
	planeOrient.setTilt(pitch); 
	        planeOrient.setHeading(yaw);
        
        
                
        planeLoc.setLatitude(lat);
        planeLoc.setLongitude(lon);
        planeLoc.setAltitude(alt);
	
pixhawk's avatar
pixhawk committed
165 166
}

167 168 169 170 171 172 173 174 175
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
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

function setCurrentAircraft(id)
{
	currAircraft = id;
}

function enableFollowing(follow)
{
	followEnabled = follow;
}


function updateFollowAircraft()
{
	if (followEnabled)
	{
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
	currView.setLatitude(currLat);
	currView.setLongitude(currLon);
	currView.setAltitude(currAlt);
	currView.setRange(currViewRange);
	currView.setTilt(currFollowTilt);
	ge.getView().setAbstractView(currView);
	}
}

function failureCallback(object)
{
}
</script>


pixhawk's avatar
pixhawk committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222
    <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>
  </body>
</html>