earth.html 7.34 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
var initialized = false;
var currAircraft = 220;
pixhawk's avatar
pixhawk committed
17
var followEnabled = false;
18 19 20
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;
pixhawk's avatar
pixhawk committed
21
var currFollowHeading = 0.0;
22 23 24 25 26 27 28 29 30 31 32 33 34

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;

pixhawk's avatar
pixhawk committed
35 36
var M_PI = 3.14159265;

37 38 39 40 41


var planeOrient;
var planeLoc;

pixhawk's avatar
pixhawk committed
42 43 44 45
var aircraft = [];
var attitudes = [];
var locations = [];
var trails = [];
46 47 48
var trail;
var lineStringPlacemark;
var lineStyle;
49 50 51 52 53 54 55 56 57

// Aircraft class


function isInitialized()
{
	return initialized;
}

pixhawk's avatar
pixhawk committed
58 59

function init() {
60 61 62 63 64
	google.earth.createInstance("map3d", initCallback, failureCallback);
}



pixhawk's avatar
pixhawk committed
65 66 67 68
function setCurrAircraft(id)
{
	currAircraft = id;
}
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

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;
	    }
pixhawk's avatar
pixhawk committed
101 102 103 104
}

function createAircraft(id, type, color)
{
105
	      planePlacemark = ge.createPlacemark('');
pixhawk's avatar
pixhawk committed
106
          planePlacemark.setName('aircraft');
107
          planeModel = ge.createModel('');
pixhawk's avatar
pixhawk committed
108
          ge.getFeatures().appendChild(planePlacemark);
109
          planeLoc = ge.createLocation('');
pixhawk's avatar
pixhawk committed
110
          planeModel.setLocation(planeLoc);
111 112
          planeLink = ge.createLink('');
          planeOrient = ge.createOrientation(''); 
pixhawk's avatar
pixhawk committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
          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);
          
          // Write into global structure
          aircraft[id] = planePlacemark;
          attitudes[id] = planeOrient;
          locations[id] = planeLoc;
          
130
          //createTrail(id, color);
pixhawk's avatar
pixhawk committed
131 132 133 134
}

function createTrail(id, color)
{
135 136
          lineStringPlacemark = ge.createPlacemark('');
          // Create the placemark
pixhawk's avatar
pixhawk committed
137 138
// Create the LineString; set it to extend down to the ground
// and set the altitude mode
139 140 141 142
trail = ge.createLineString('');
lineStringPlacemark.setGeometry(trail);
trail.setExtrude(true);
trail.setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
pixhawk's avatar
pixhawk committed
143 144 145 146 147 148

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

// Create a style and set width and color of line
lineStringPlacemark.setStyleSelector(ge.createStyle(''));
149
lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
pixhawk's avatar
pixhawk committed
150
lineStyle.setWidth(5);
151
lineStyle.getColor().set(color);
pixhawk's avatar
pixhawk committed
152 153 154 155
//lineStyle.getColor().set(color);  // aabbggrr format

// Add the feature to Earth
ge.getFeatures().appendChild(lineStringPlacemark);
156

pixhawk's avatar
pixhawk committed
157 158 159 160
}

function addTrailPosition(id, lat, lon, alt)
{
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	trail.setExtrude(true);
trail.setAltitudeMode(ge.ALTITUDE_ABSOLUTE);

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

// Create a style and set width and color of line
lineStringPlacemark.setStyleSelector(ge.createStyle(''));
lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
lineStyle.setWidth(5);
lineStyle.getColor().set('99bbaaff');
//lineStyle.getColor().set(color);  // aabbggrr format

// Add the feature to Earth
ge.getFeatures().replaceChild(lineStringPlacemark, lineStringPlacemark);
pixhawk's avatar
pixhawk committed
177 178
}

179 180
function initCallback(object)
{
pixhawk's avatar
pixhawk committed
181 182 183 184 185 186 187 188 189 190 191
  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);
192

193 194
        createTrail(220, 'bb2222ff');
        createAircraft(220);
195 196 197 198 199 200 201 202 203 204 205 206 207

        initialized = true;
        
        
}

function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
	if (id == currAircraft)
	{
		currLat = lat;
		currLon = lon;
		currAlt = alt;
pixhawk's avatar
pixhawk committed
208
		currFollowHeading = ((yaw/M_PI)+1.0)*360.0;
209 210
	}
	
pixhawk's avatar
pixhawk committed
211 212 213 214
	// FIXME Currently invalid conversion from right-handed z-down to z-up frame
	planeOrient.setRoll(((roll/M_PI)+1.0)*360.0);
	planeOrient.setTilt(((pitch/M_PI)+1.0)*360.0);
	planeOrient.setHeading(((yaw/M_PI)+1.0)*360.0);
215 216 217
        
        
                
pixhawk's avatar
pixhawk committed
218 219 220
    planeLoc.setLatitude(lat);
    planeLoc.setLongitude(lon);
    planeLoc.setAltitude(alt);
221
	
pixhawk's avatar
pixhawk committed
222 223
}

224 225 226 227 228 229 230 231 232 233 234 235
function enableDaylight(enabled)
{
	if(enabled)
	{
		ge.getSun().setVisibility(true);
	}
	else
	{
		ge.getSun().setVisibility(false);
	}
}
		
236 237 238 239 240 241 242 243 244
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
245
}
246 247 248 249 250 251 252 253 254 255 256 257 258 259

function setCurrentAircraft(id)
{
	currAircraft = id;
}

function updateFollowAircraft()
{
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
	currView.setLatitude(currLat);
	currView.setLongitude(currLon);
	currView.setAltitude(currAlt);
	currView.setRange(currViewRange);
	currView.setTilt(currFollowTilt);
pixhawk's avatar
pixhawk committed
260
	currView.setHeading(currFollowHeading-90.0);
261 262 263 264 265 266 267 268 269
	ge.getView().setAbstractView(currView);
}

function failureCallback(object)
{
}
</script>


pixhawk's avatar
pixhawk committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283
    <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>