blob: 9be16f6d117e87e76b8d2f5c7a818176269d2622 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "mapwindow.hpp"
#include <QIcon>
#include <QString>
#include <QWindow>
MapWindow::MapWindow(const QMapboxGLSettings &settings)
: m_settings(settings)
{
setWindowIcon(QIcon(":icon.png"));
}
MapWindow::~MapWindow()
{
// Make sure we have a valid context so we
// can delete the QMapboxGL.
makeCurrent();
}
qreal MapWindow::pixelRatio() {
return devicePixelRatioF();
}
void MapWindow::initializeGL()
{
m_map.reset(new QMapboxGL(nullptr, m_settings, size(), pixelRatio()));
connect(m_map.data(), SIGNAL(needsRendering()), this, SLOT(update()));
// Set default location to Helsinki.
m_map->setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
auto& styles = QMapbox::defaultStyles();
m_map->setStyleUrl(styles[0].first);
}
void MapWindow::paintGL()
{
auto move = QPointF((rand() % 40 ) - 20, (rand() % 40) - 20 );
auto scale1 = ((rand() % 30 ) - 14) / 30.0 + 1.0;
auto scale2 = QPointF(rand() % size().width(), rand() % size().height());
m_map->moveBy(move);
m_map->scaleBy(scale1, scale2);
m_map->resize(size());
#if QT_VERSION >= 0x050400
m_map->setFramebufferObject(defaultFramebufferObject(), size() * pixelRatio());
#endif
m_map->render();
}
|