Newer
Older
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Mariano Lizarraga
committed
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- <head> -->
<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="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
<script type="text/javascript">
google.load("earth", "1", { 'language': 'en'});
var followEnabled = false;
var lastLat = 0;
var lastLon = 0;
var currLat = 47.3769;
var currLon = 8.549444;
var currAlt = 470;
var currFollowHeading = 0.0;
var homeLat = 0;
var homeLon = 0;
var homeAlt = 0;
var homeViewRange = 500;
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 = 0;
var lastRoll = 0;
var lastHeading = 0;
var M_PI = 3.14159265;
var planeOrient;
var planeLoc;
var aircraftLocations = [];
var aircraftLastLocations = [];
var attitudes = [];
var locations = [];
var trails = [];
var trailPlacemarks = [];
var trailsVisible = [];
var trailColors = [];
var waypoints = [];
//var waypointLines = [];
//var trailPlacemarks[id];
var lineStyle;
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;
function getGlobal(variable)
{
return variable;
}
function getDraggingAllowed()
{
return draggingAllowed;
}
function setDistanceMode(mode)
{
distanceMode = mode;
}
function setDraggingAllowed(allowed)
{
}
function setNewWaypointPending(pending)
{
newWaypointPending = pending;
}
function setDragWaypointPending(pending)
{
dragWaypointPending = pending;
}
function isInitialized()
{
return initialized;
}
function init()
{
google.earth.createInstance("map3d", initCallback, failureCallback);
}
function setFollowEnabled(enable)
{
followEnabled = enable;
}
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
function enableEventListener()
{
// listen for mousedown on the window (look specifically for point placemarks)
google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event)
{
if (draggingAllowed)
{
if (event.getTarget().getType() == 'KmlPlacemark' &&
event.getTarget().getGeometry().getType() == 'KmlPoint') {
//event.preventDefault();
var placemark = event.getTarget();
dragInfo = {
placemark: event.getTarget(),
dragged: false
};
}
}
});
// listen for mousemove on the globe
google.earth.addEventListener(ge.getGlobe(), 'mousemove', function(event)
{
if (draggingAllowed)
{
if (dragInfo) {
event.preventDefault();
var point = dragInfo.placemark.getGeometry();
point.setLatitude(event.getLatitude());
point.setLongitude(event.getLongitude());
dragInfo.dragged = true;
dragWaypointIndex = dragInfo.placemark.getDescription();
dragWaypointLatitude = event.getLatitude();
dragWaypointLongitude = event.getLongitude();
dragWaypointAltitude = point.getAltitude();
dragWaypointPending = true;
}
}
});
// listen for mouseup on the window
google.earth.addEventListener(ge.getWindow(), 'mouseup', function(event)
{
if (draggingAllowed)
{
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();
var point = dragInfo.placemark.getGeometry();
dragWaypointLatitude = event.getLatitude();
dragWaypointLongitude = event.getLongitude();
dragWaypointAltitude = point.getAltitude();
dragWaypointPending = true;
}
dragInfo = null;
}
}
});
// 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;
}
});
}
function setCurrAircraft(id)
{
currAircraft = id;
}
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
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;
}
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);
waypoints[index].setDescription(index+"");
}
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);
placemark.setGeometry(location);
// Add the placemark to Earth.
ge.getFeatures().appendChild(placemark);
waypoints[index] = placemark;
}
// Add connecting line
}
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);
// Write into global structure
aircraft[id] = planePlacemark;
attitudes[id] = planeOrient;
aircraftLastLocations[id] = ge.createLocation('');
//planeColor = color;
createTrail(id, color);
console.log(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);
// Add LineString points
//lineString.getCoordinates().pushLatLngAlt(48.754, -121.835, 700);
// Create a style and set width and color of line
trailPlacemarks[id].setStyleSelector(ge.createStyle(''));
lineStyle = trailPlacemarks[id].getStyleSelector().getLineStyle();
trailColors[id] = color;
lineStyle.getColor().set('00000000'); // aabbggrr format
trailsVisible[id] = false;
//ge.getFeatures().appendChild(trailPlacemarks[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);
pixhawk
committed
trails[id].setAltitudeMode(ge.ALTITUDE_ABSOLUTE);
pixhawk
committed
// Add LineString points
trails[id].getCoordinates().pushLatLngAlt(lat, lon, alt);
pixhawk
committed
// 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
pixhawk
committed
// Add the feature to Earth
if (trailsVisible[id] == true) ge.getFeatures().replaceChild(trailPlacemarks[id], trailPlacemarks[id]);
function initCallback(object)
{
pixhawk
committed
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);
pixhawk
committed
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
pixhawk
committed
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();
pixhawk
committed
initialized = true;
}
function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
{
if (id == currAircraft)
{
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.8+currLat*0.2;
lastLon = lastLon*0.8+currLon*0.2;
lastAlt = lastAlt*0.8+currAlt*0.2;
//currFollowHeading = ((yaw/M_PI)+1.0)*360.0;
// FIXME Currently invalid conversion from right-handed z-down to z-up frame
planeOrient.setRoll(((roll/M_PI))*180.0+180.0);
planeOrient.setTilt(((pitch/M_PI))*180.0+180.0);
planeOrient.setHeading(((yaw/M_PI))*180.0-90.0);
currFollowHeading = ((yaw/M_PI))*180.0;
pixhawk
committed
planeLoc.setLatitude(lastLat);
planeLoc.setLongitude(lastLon);
planeLoc.setAltitude(lastAlt);
pixhawk
committed
planeModel.setLocation(planeLoc);
pixhawk
committed
}
function enableDaylight(enabled)
{
if(enabled)
{
ge.getSun().setVisibility(true);
}
else
{
ge.getSun().setVisibility(false);
}
}
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)
{
viewMode = mode;
var currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
if (mode == 0)
{
currView.setTilt(0);
currView.setHeading(0);
}
if (mode == 1)
{
lastTilt = currView.getTilt();
lastHeading = currView.getHeading();
var lastLat2 = currView.getLatitude();
var lastLon2 = currView.getLongitude();
var lastAlt2 = currView.getAltitude();
currView.setTilt(0);
currView.setHeading(0);
currView.setLatitude(lastLat2);
currView.setLongitude(lastLon2);
currView.setAltitude(lastAlt2);
}
ge.getView().setAbstractView(currView);
function updateFollowAircraft()
{
currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
currView.setLatitude(lastLat);
currView.setLongitude(lastLon);
currView.setAltitude(lastAlt);
currView.setRange(currViewRange);
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>
</body>
</html>