-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6fb8c19
Showing
9 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Makefile | ||
build | ||
*.o |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
qmapboxgl copyright (c) 2015, Mapbox. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# QMapboxGL | ||
|
||
QMapboxGL is a Qt-enabled viewport for vector tiles using [Mapbox GL](https://github.com/mapbox/mapbox-gl-native) for rendering. It can be used for online and offline rendering of vector tiles. | ||
|
||
### Demo | ||
|
||
A simple example rendering the Mapbox base vector tiles layer based on [OpenStreetMap](http://www.openstreetmap.org) using different styles. | ||
|
||
 | ||
|
||
### Sample code | ||
|
||
```c++ | ||
#include <QtGui> | ||
#include <QMapboxGL> | ||
|
||
int main(int argc, char **argv) { | ||
QGuiApplication app(argc, argv); | ||
|
||
QFile data("/usr/share/mbgl/styles/emerald-v7.json"); | ||
data.open(QFile::ReadOnly); | ||
|
||
QTextStream style(&data); | ||
|
||
QMapboxGL map; | ||
map.setAccessToken(qgetenv("MAPBOX_ACCESS_TOKEN")); | ||
map.setStyleJSON(style.readAll()); | ||
|
||
map.resize(800, 600); | ||
map.show(); | ||
|
||
return app.exec(); | ||
} | ||
``` | ||
### Build instructions for Ubuntu Vivid or Debian Jessie | ||
##### Install the Mapbox GL development packages: | ||
``` | ||
$ sudo apt-add-repository ppa:tmpsantos/mapbox-gl | ||
$ sudo apt-get update | ||
$ sudo apt-install libmbgl-dev | ||
``` | ||
##### Clone this repository and build: | ||
``` | ||
$ git clone https://github.com/tmpsantos/qmapboxgl.git | ||
$ cd qmapboxgl | ||
$ mkdir build | ||
$ cd build | ||
$ qmake .. | ||
$ make | ||
``` | ||
##### Run the example: | ||
You need to export `MAPBOX_ACCESS_TOKEN` if you are using vector tiles hosted at Mapbox servers. Get one access token for free [here](https://www.mapbox.com/). | ||
``` | ||
$ MAPBOX_ACCESS_TOKEN=pk.XXXXXXXXXXXX ./qmapboxgl | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <QtWidgets> | ||
#include <QMapboxGL> | ||
|
||
QString getStyle() { | ||
static unsigned currentStyle; | ||
const char *styles[] { | ||
"/usr/share/mbgl/styles/emerald-v7.json", | ||
"/usr/share/mbgl/styles/mapbox-streets-v7.json", | ||
"/usr/share/mbgl/styles/light-v7.json", | ||
"/usr/share/mbgl/styles/dark-v7.json", | ||
}; | ||
|
||
if (currentStyle >= sizeof(styles) / sizeof(char *)) { | ||
currentStyle = 0; | ||
} | ||
|
||
QFile data(styles[++currentStyle - 1]); | ||
data.open(QFile::ReadOnly); | ||
|
||
QTextStream style(&data); | ||
return style.readAll(); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
QApplication app(argc, argv); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout; | ||
|
||
QMapboxGL *map = new QMapboxGL; | ||
map->setAccessToken(qgetenv("MAPBOX_ACCESS_TOKEN")); | ||
map->setStyleJSON(getStyle()); | ||
|
||
// Show the Nordic countries. | ||
map->setLatitude(63.761821); | ||
map->setLongitude(17.744822); | ||
map->setZoom(3.5); | ||
|
||
QWidget *container = QWidget::createWindowContainer(map); | ||
layout->addWidget(container); | ||
|
||
QPushButton *styleButton = new QPushButton("&Change map style"); | ||
layout->addWidget(styleButton); | ||
QObject::connect(styleButton, &QPushButton::clicked, [map]() { | ||
map->setStyleJSON(getStyle()); | ||
}); | ||
|
||
QPropertyAnimation latitudeAnimation(map, "latitude"); | ||
latitudeAnimation.setEasingCurve(QEasingCurve::OutQuint); | ||
latitudeAnimation.setDuration(5000); | ||
|
||
QPropertyAnimation longitudeAnimation(map, "longitude"); | ||
longitudeAnimation.setEasingCurve(QEasingCurve::OutQuint); | ||
longitudeAnimation.setDuration(5000); | ||
|
||
QPropertyAnimation zoomAnimation(map, "zoom"); | ||
zoomAnimation.setDuration(5000); | ||
|
||
QPushButton *jumpButton = new QPushButton("&Take me to Helsinki"); | ||
layout->addWidget(jumpButton); | ||
QObject::connect(jumpButton, &QPushButton::clicked, [&]() { | ||
if (zoomAnimation.state() == QAbstractAnimation::Running) { | ||
return; | ||
} | ||
|
||
// Helsinki city center. | ||
latitudeAnimation.setEndValue(60.170448); | ||
longitudeAnimation.setEndValue(24.942046); | ||
zoomAnimation.setEndValue(14.0); | ||
|
||
latitudeAnimation.start(); | ||
longitudeAnimation.start(); | ||
zoomAnimation.start(); | ||
}); | ||
|
||
QPushButton *quitButton = new QPushButton("&Quit"); | ||
layout->addWidget(quitButton); | ||
QObject::connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit())); | ||
|
||
QWidget window; | ||
window.setLayout(layout); | ||
window.resize(800, 600); | ||
window.show(); | ||
window.setWindowTitle("Mapbox GL for Qt"); | ||
|
||
return app.exec(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "qmapboxgl.h" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef QMAPBOXGL_H | ||
#define QMAPBOXGL_H | ||
|
||
#include <QOpenGLWindow> | ||
|
||
class QMapboxGLPrivate; | ||
|
||
class QMapboxGL : public QOpenGLWindow | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(double latitude READ latitude WRITE setLatitude) | ||
Q_PROPERTY(double longitude READ longitude WRITE setLongitude) | ||
Q_PROPERTY(double zoom READ zoom WRITE setZoom) | ||
|
||
public: | ||
explicit QMapboxGL(QWindow *parent = 0); | ||
virtual ~QMapboxGL(); | ||
|
||
void setAccessToken(const QString &token); | ||
void setStyleJSON(const QString &style); | ||
|
||
double latitude() const; | ||
void setLatitude(double latitude); | ||
|
||
double longitude() const; | ||
void setLongitude(double longitude); | ||
|
||
double zoom() const; | ||
void setZoom(double zoom); | ||
|
||
private: | ||
Q_DISABLE_COPY(QMapboxGL) | ||
|
||
// QOpenGLWindow implementation. | ||
void mouseMoveEvent(QMouseEvent *ev); | ||
void mousePressEvent(QMouseEvent * ev); | ||
void wheelEvent(QWheelEvent * ev); | ||
void resizeGL(int w, int h); | ||
|
||
QMapboxGLPrivate *d_ptr; | ||
}; | ||
|
||
#endif // QMAPBOXGL_H |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SUBDIRS = example | ||
|
||
QT += widgets | ||
|
||
TEMPLATE = app | ||
|
||
CONFIG += link_pkgconfig opengl c++11 debug | ||
|
||
PKGCONFIG += libmbgl | ||
|
||
SOURCES += example/example.cpp \ | ||
src/qmapboxgl.cpp | ||
|
||
HEADERS += include/qmapboxgl.h | ||
|
||
INCLUDEPATH += include |
Oops, something went wrong.