Created
October 28, 2016 11:27
-
-
Save anonymous/d3a559bd309d7f17bc3030955083dba6 to your computer and use it in GitHub Desktop.
Marble paint layer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include <QApplication> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
MainWindow w; | |
w.show(); | |
return a.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include <marble/MarbleWidget.h> | |
#include <marble/GeoPainter.h> | |
#include "mypaintlayer.h" | |
#include <QMenuBar> | |
MainWindow::MainWindow(QWidget *parent) | |
: QMainWindow(parent) | |
{ | |
map_widget = new Marble::MarbleWidget(); | |
map_widget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml"); | |
home = new Marble::GeoDataCoordinates(4.75028, 52.09761, 0.0, Marble::GeoDataCoordinates::Degree); | |
map_widget->centerOn(*home); | |
map_widget->setZoom(3500); | |
layerList = new QList<MyPaintLayer*>(); | |
map_widget->setShowCompass(false); | |
map_widget->setShowCrosshairs(false); | |
map_widget->setShowGrid(false); | |
map_widget->setShowScaleBar(false); | |
map_widget->setShowOverviewMap(false); | |
setCentralWidget(map_widget); | |
mainMenu = menuBar()->addMenu("Main menu"); | |
addLayer = new QAction("Add Layer", this); | |
mainMenu->addAction(addLayer); | |
removeLayer = new QAction("Remove Layer", this); | |
mainMenu->addAction(removeLayer); | |
connect(addLayer, SIGNAL(triggered()), this, SLOT(onLayerAdded())); | |
connect(removeLayer, SIGNAL(triggered()), this, SLOT(onLayerRemoved())); | |
} | |
void MainWindow::onLayerAdded() | |
{ | |
MyPaintLayer *pLayer = new MyPaintLayer(map_widget, *home); | |
map_widget->addLayer(pLayer); | |
layerList->append(pLayer); | |
map_widget->update(); | |
} | |
void MainWindow::onLayerRemoved() | |
{ | |
map_widget->removeLayer(layerList->last()); | |
layerList->removeLast(); | |
map_widget->update(); | |
} | |
MainWindow::~MainWindow() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
#include <marble/MarbleWidget.h> | |
#include <QMenu> | |
#include <QAction> | |
#include "mypaintlayer.h" | |
#include <QList> | |
class MainWindow : public QMainWindow | |
{ | |
Q_OBJECT | |
public: | |
MainWindow(QWidget *parent = 0); | |
~MainWindow(); | |
private: | |
QMenu *mainMenu; | |
QAction *addLayer; | |
QAction *removeLayer; | |
Marble::GeoDataCoordinates *home; | |
Marble::MarbleWidget *map_widget; | |
QList<MyPaintLayer*> *layerList; | |
private slots: | |
void onLayerAdded(); | |
void onLayerRemoved(); | |
}; | |
#endif // MAINWINDOW_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mypaintlayer.h" | |
#include <marble/GeoDataLinearRing.h> | |
#include <math.h> | |
MyPaintLayer::MyPaintLayer(MarbleWidget* widget, GeoDataCoordinates &origin) : | |
m_widget(widget), | |
m_index(0), | |
origin(origin) | |
{ | |
} | |
QStringList MyPaintLayer::renderPosition() const | |
{ | |
return QStringList() << "SURFACE"; | |
} | |
bool MyPaintLayer::render(GeoPainter *painter, ViewportParams *viewport, | |
const QString& renderPos, GeoSceneLayer * layer) | |
{ | |
qDebug() << "render object: " << this; | |
painter->setRenderHint(QPainter::Antialiasing, true); | |
painter->setPen(QPen(QBrush(QColor::fromRgb(255,255,255,200)), 3.0, Qt::SolidLine, Qt::RoundCap )); | |
painter->setBrush(QBrush(QColor::fromRgb(255,255,255,100))); | |
GeoDataLinearRing *ring = new GeoDataLinearRing(); | |
GeoDataCoordinates one = origin.moveByBearing(0, 0); | |
GeoDataCoordinates two = one.moveByBearing(M_PI/2, 0.000004); | |
GeoDataCoordinates three = two.moveByBearing(M_PI, 0.000004); | |
GeoDataCoordinates four = three.moveByBearing(3*M_PI/2, 0.000004); | |
ring->append(one); | |
ring->append(two); | |
ring->append(three); | |
ring->append(four); | |
painter->drawPolygon(*ring); | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MYPAINTLAYER_H | |
#define MYPAINTLAYER_H | |
#include <marble/MarbleWidget.h> | |
#include <marble/MarbleMap.h> | |
#include <marble/MarbleModel.h> | |
#include <marble/GeoPainter.h> | |
#include <marble/LayerInterface.h> | |
using namespace Marble; | |
class MyPaintLayer : public QObject, public LayerInterface | |
{ | |
Q_OBJECT | |
public: | |
MyPaintLayer(MarbleWidget* widget, GeoDataCoordinates &origin); | |
virtual QStringList renderPosition() const; | |
virtual bool render(GeoPainter *painter, ViewportParams *viewport, | |
const QString& renderPos = "NONE", GeoSceneLayer * layer = 0); | |
private: | |
MarbleWidget* m_widget; | |
GeoDataCoordinates origin; | |
int m_index; | |
}; | |
#endif // MYPAINTLAYER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment