earth.html 8.27 KB
Newer Older
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 *** -->
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 17
var initialized = false;
var currAircraft = 220;
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
var currFollowHeading = 0.0;
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;

35
var currViewRange = 50.0;	///<< The current viewing range from this position (in meters)
36 37 38 39
var currTilt = 40.0;		///<< The tilt angle (in degrees)
var currFollowTilt = 40.0;
var currView = null;

40 41
var M_PI = 3.14159265;

42 43 44 45 46


var planeOrient;
var planeLoc;

47
var aircraft = [];
48 49
var aircraftLocations = [];
var aircraftLastLocations = [];
50 51 52
var attitudes = [];
var locations = [];
var trails = [];
53 54 55 56
var trailPlacemarks = [];
var trailsVisible = [];
var trailColors = [];
//var trailPlacemarks[id];
57
var lineStyle;
58 59

// Aircraft class
60
var planeColor = '6600ffff';
61 62 63 64 65 66 67


function isInitialized()
{
	return initialized;
}

pixhawk's avatar
pixhawk committed
68

69 70
function init()
{
71 72 73 74 75
	google.earth.createInstance("map3d", initCallback, failureCallback);
}



76 77 78 79
function setCurrAircraft(id)
{
	currAircraft = id;
}
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

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
112 113
}

pixhawk's avatar
pixhawk committed
114
function createAircraft(id, type, color)
115
{
116
	      planePlacemark = ge.createPlacemark('');
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
          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
136 137 138
          // Write into global structure
          aircraft[id] = planePlacemark;
          attitudes[id] = planeOrient;
139 140
          aircraftLocations[id] = planeLoc;
		  aircraftLastLocations[id] = ge.createLocation('');
141
          //planeColor = color;
pixhawk's avatar
pixhawk committed
142
          
143 144
          createTrail(id, color);
          console.log(color);
pixhawk's avatar
pixhawk committed
145 146 147 148
}

function createTrail(id, color)
{
149
          trailPlacemarks[id] = ge.createPlacemark('');
150
          // Create the placemark
pixhawk's avatar
pixhawk committed
151 152
// Create the LineString; set it to extend down to the ground
// and set the altitude mode
153 154 155 156
trails[id] = ge.createLineString('');
trailPlacemarks[id].setGeometry(trails[id]);
trails[id].setExtrude(false);
trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
pixhawk's avatar
pixhawk committed
157 158 159 160 161

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

// Create a style and set width and color of line
162 163
trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
pixhawk's avatar
pixhawk committed
164
lineStyle.setWidth(5);
165 166 167 168
trailColors[id] = color;
lineStyle.getColor().set('00000000');  // aabbggrr format

trailsVisible[id] = false;
pixhawk's avatar
pixhawk committed
169 170

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

pixhawk's avatar
pixhawk committed
173 174
}

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
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;
}

pixhawk's avatar
pixhawk committed
192 193
function addTrailPosition(id, lat, lon, alt)
{
194
	trails[id].setExtrude(false);
195
    trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
196

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

200 201 202 203 204 205
    // 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
206

207 208
    // Add the feature to Earth
    if (trailsVisible[id] == true) ge.getFeatures().replaceChild(trailPlacemarks[id], trailPlacemarks[id]);
pixhawk's avatar
pixhawk committed
209 210
}

211 212
function initCallback(object)
{
213 214 215 216 217 218 219
    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);
pixhawk's avatar
pixhawk committed
220
        
221 222 223 224
    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);
225

226
    initialized = true;
227 228 229 230 231 232
}

function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
	if (id == currAircraft)
	{
lm's avatar
lm committed
233 234 235 236 237
		if (lastLat == 0)
		{
			lastLat = currLat;
			lastLon = lastLon;
		}
238 239 240
		currLat = lat;
		currLon = lon;
		currAlt = alt;
241
		//currFollowHeading = ((yaw/M_PI)+1.0)*360.0;
242
	
243
	
244 245 246 247
	// 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);
248
    
249 250 251
    planeLoc.setLatitude(lat);
    planeLoc.setLongitude(lon);
    planeLoc.setAltitude(alt);
252 253
    planeModel.setLocation(planeLoc);
    }
pixhawk's avatar
pixhawk committed
254 255
}

256 257 258 259 260 261 262 263 264 265 266 267
function enableDaylight(enabled)
{
	if(enabled)
	{
		ge.getSun().setVisibility(true);
	}
	else
	{
		ge.getSun().setVisibility(false);
	}
}
		
268 269 270 271 272 273 274 275 276
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
277
}
278 279 280 281 282 283 284 285 286

function setCurrentAircraft(id)
{
	currAircraft = id;
}

function updateFollowAircraft()
{
	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
287
	// Interpolate between t-1 and t and set new states
lm's avatar
lm committed
288 289 290
	lastLat = lastLat*0.7+currLat*0.3;
	lastLon = lastLon*0.7+currLon*0.3;
	lastAlt = lastAlt*0.7+currAlt*0.3;
291 292 293 294
	currView.setLatitude(lastLat);
	currView.setLongitude(lastLon);
	currView.setAltitude(lastAlt);

295 296
	currView.setRange(currViewRange);
	currView.setTilt(currFollowTilt);
297
	currView.setHeading(currFollowHeading-90.0);
298
	
299 300 301 302 303 304 305 306 307
	ge.getView().setAbstractView(currView);
}

function failureCallback(object)
{
}
</script>


pixhawk's avatar
pixhawk committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321
    <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>