Skip to content
MapWidget.cc 37.4 KiB
Newer Older
/*==================================================================
pixhawk's avatar
pixhawk committed
======================================================================*/

/**
 * @file
lm's avatar
lm committed
 *   @brief Implementation of MapWidget
pixhawk's avatar
pixhawk committed
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
lm's avatar
lm committed
 *   @author Mariano Lizarraga
pixhawk's avatar
pixhawk committed
 *
 */

lm's avatar
lm committed
#include <QComboBox>
#include <QGridLayout>
pixhawk's avatar
pixhawk committed
#include <QDir>
pixhawk's avatar
pixhawk committed
#include "MapWidget.h"
#include "ui_MapWidget.h"
lm's avatar
lm committed
#include "UASInterface.h"
#include "UASManager.h"
#include "MAV2DIcon.h"
#include "Waypoint2DIcon.h"
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
#include "MG.h"

pixhawk's avatar
pixhawk committed
MapWidget::MapWidget(QWidget *parent) :
        QWidget(parent),
        zoomLevel(0),
        uasIcons(),
        uasTrails(),
pixhawk's avatar
pixhawk committed
        m_ui(new Ui::MapWidget)
{
    m_ui->setupUi(this);
    mc = new qmapcontrol::MapControl(this->size());
    QString buttonStyle("QAbstractButton { background-color: rgba(20, 20, 20, 45%); border-color: rgba(10, 10, 10, 50%)} QAbstractButton:checked { border: 2px solid #379AC3; }");
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
    // Accept focus by clicking or keyboard
    this->setFocusPolicy(Qt::StrongFocus);
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
    // create MapControl
pixhawk's avatar
pixhawk committed
    mc->showScale(true);
pixhawk's avatar
pixhawk committed
    mc->enablePersistentCache();
    mc->setMouseTracking(true); // required to update the mouse position for diplay and capture
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
    // create MapAdapter to get maps from
lm's avatar
lm committed
    //TileMapAdapter* osmAdapter = new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
pixhawk's avatar
pixhawk committed

    qmapcontrol::MapAdapter* mapadapter_overlay = new qmapcontrol::YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=2.2&t=h&s=256&x=%2&y=%3&z=%1");
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    // MAP BACKGROUND
    mapadapter = new qmapcontrol::GoogleSatMapAdapter();
    l = new qmapcontrol::MapLayer("Google Satellite", mapadapter);
lm's avatar
lm committed
    mc->addLayer(l);
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    // STREET OVERLAY
    overlay = new qmapcontrol::MapLayer("Overlay", mapadapter_overlay);
lm's avatar
lm committed
    overlay->setVisible(false);
    mc->addLayer(overlay);
pixhawk's avatar
pixhawk committed

    // MAV FLIGHT TRACKS
    tracks = new qmapcontrol::MapLayer("Tracking", mapadapter);
    mc->addLayer(tracks);

lm's avatar
lm committed
    // WAYPOINT LAYER
    // create a layer with the mapadapter and type GeometryLayer (for waypoints)
    geomLayer = new qmapcontrol::GeometryLayer("Waypoints", mapadapter);
    //
    //    Layer* gsatLayer = new Layer("Google Satellite", gsat, Layer::MapLayer);
    //    mc->addLayer(gsatLayer);
pixhawk's avatar
pixhawk committed


    // Zurich, ETH

    int lastZoom = 16;
    double lastLat = 47.376889;
    double lastLon = 8.548056;

    QSettings settings;
    settings.beginGroup("QGC_MAPWIDGET");
    lastLat = settings.value("LAST_LATITUDE", lastLat).toDouble();
    lastLon = settings.value("LAST_LONGITUDE", lastLon).toDouble();
    lastZoom = settings.value("LAST_ZOOM", lastZoom).toInt();
    settings.endGroup();

lm's avatar
lm committed
    // SET INITIAL POSITION AND ZOOM
    // Set default zoom level
    mc->setZoom(lastZoom);
    mc->setView(QPointF(lastLon, lastLat));
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
    // Veracruz Mexico
    //mc->setView(QPointF(-96.105208,19.138955));
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    // Add controls to select map provider
    /////////////////////////////////////////////////
    QActionGroup* mapproviderGroup = new QActionGroup(this);
    osmAction = new QAction(QIcon(":/images/mapproviders/openstreetmap.png"), tr("OpenStreetMap"), mapproviderGroup);
    yahooActionMap = new QAction(QIcon(":/images/mapproviders/yahoo.png"), tr("Yahoo: Map"), mapproviderGroup);
    yahooActionSatellite = new QAction(QIcon(":/images/mapproviders/yahoo.png"), tr("Yahoo: Satellite"), mapproviderGroup);
    googleActionMap = new QAction(QIcon(":/images/mapproviders/google.png"), tr("Google: Map"), mapproviderGroup);
    googleSatAction = new QAction(QIcon(":/images/mapproviders/google.png"), tr("Google: Sat"), mapproviderGroup);
lm's avatar
lm committed
    osmAction->setCheckable(true);
    yahooActionMap->setCheckable(true);
    yahooActionSatellite->setCheckable(true);
    googleActionMap->setCheckable(true);
    googleSatAction->setCheckable(true);
    googleSatAction->setChecked(true);
    connect(mapproviderGroup, SIGNAL(triggered(QAction*)),
            this, SLOT(mapproviderSelected(QAction*)));
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    // Overlay seems currently broken
    //    yahooActionOverlay = new QAction(tr("Yahoo: street overlay"), this);
    //    yahooActionOverlay->setCheckable(true);
    //    yahooActionOverlay->setChecked(overlay->isVisible());
    //    connect(yahooActionOverlay, SIGNAL(toggled(bool)),
    //            overlay, SLOT(setVisible(bool)));
pixhawk's avatar
pixhawk committed

    //    mapproviderGroup->addAction(googleSatAction);
    //    mapproviderGroup->addAction(osmAction);
    //    mapproviderGroup->addAction(yahooActionOverlay);
    //    mapproviderGroup->addAction(googleActionMap);
    //    mapproviderGroup->addAction(yahooActionMap);
    //    mapproviderGroup->addAction(yahooActionSatellite);
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    // Create map provider selection menu
    mapMenu = new QMenu(this);
    mapMenu->addActions(mapproviderGroup->actions());
    mapMenu->addSeparator();
    //    mapMenu->addAction(yahooActionOverlay);
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
    mapButton = new QPushButton(this);
    mapButton->setText("Map Source");
    mapButton->setMenu(mapMenu);
pixhawk's avatar
pixhawk committed

pixhawk's avatar
pixhawk committed
    // display the MapControl in the application
lm's avatar
lm committed
    QGridLayout* layout = new QGridLayout(this);
pixhawk's avatar
pixhawk committed
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(mc, 0, 0);
pixhawk's avatar
pixhawk committed
    setLayout(layout);
pixhawk's avatar
pixhawk committed

    // create buttons to control the map (zoom, GPS tracking and WP capture)
pixhawk's avatar
pixhawk committed
    QPushButton* zoomin = new QPushButton(QIcon(":/images/actions/list-add.svg"), "", this);
pixhawk's avatar
pixhawk committed
    QPushButton* zoomout = new QPushButton(QIcon(":/images/actions/list-remove.svg"), "", this);
    createPath = new QPushButton(QIcon(":/images/actions/go-bottom.svg"), "", this);
    createPath->setStyleSheet(buttonStyle);
    createPath->setToolTip(tr("Start / end waypoint add mode"));
    createPath->setStatusTip(tr("Start / end waypoint add mode"));
//    clearTracking = new QPushButton(QIcon(""), "", this);
//    clearTracking->setStyleSheet(buttonStyle);
pixhawk's avatar
pixhawk committed
    followgps = new QPushButton(QIcon(":/images/actions/system-lock-screen.svg"), "", this);
    followgps->setToolTip(tr("Follow the position of the current MAV with the map center"));
    followgps->setStatusTip(tr("Follow the position of the current MAV with the map center"));
    QPushButton* goToButton = new QPushButton(QIcon(""), "T", this);
    goToButton->setStyleSheet(buttonStyle);
    goToButton->setToolTip(tr("Enter a latitude/longitude position to move the map to"));
    goToButton->setStatusTip(tr("Enter a latitude/longitude position to move the map to"));
pixhawk's avatar
pixhawk committed

    zoomin->setMaximumWidth(30);
    zoomout->setMaximumWidth(30);
    createPath->setMaximumWidth(30);
//    clearTracking->setMaximumWidth(30);
    followgps->setMaximumWidth(30);
pixhawk's avatar
pixhawk committed

    // Set checkable buttons
    // TODO: Currently checked buttons are are very difficult to distinguish when checked.
    //       create a style and the slots to change the background so it is easier to distinguish
    followgps->setCheckable(true);
    createPath->setCheckable(true);
pixhawk's avatar
pixhawk committed

    // add buttons to control the map (zoom, GPS tracking and WP capture)
lm's avatar
lm committed
    QGridLayout* innerlayout = new QGridLayout(mc);
Loading
Loading full blame...