[qt] Only build core platform as part of main maplibre-native repo (#1740)
This commit is contained in:
5
.github/actions/qt5-build/entrypoint.sh
vendored
5
.github/actions/qt5-build/entrypoint.sh
vendored
@@ -14,9 +14,6 @@ cmake ../source/ \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_IGNORE_ICU=OFF \
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
-DMLN_QT_IGNORE_ICU=OFF
|
||||
ninja
|
||||
ninja install
|
||||
|
||||
7
.github/actions/qt6-build/entrypoint.sh
vendored
7
.github/actions/qt6-build/entrypoint.sh
vendored
@@ -12,11 +12,6 @@ qt-cmake ../source/ \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_IGNORE_ICU=OFF \
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
-DMLN_QT_IGNORE_ICU=OFF
|
||||
ninja
|
||||
ninja install
|
||||
cd ../install
|
||||
ln -s lib64 lib
|
||||
|
||||
173
.github/workflows/qt-ci.yml
vendored
173
.github/workflows/qt-ci.yml
vendored
@@ -64,12 +64,6 @@ jobs:
|
||||
qt_version: 5.15.2
|
||||
qt_target: desktop
|
||||
compiler: ""
|
||||
- name: Linux
|
||||
os: ubuntu-22.04
|
||||
build_type: RelWithDebInfo
|
||||
qt_version: 6.5.3
|
||||
qt_target: desktop
|
||||
compiler: ""
|
||||
- name: Linux_GCC13
|
||||
os: ubuntu-22.04
|
||||
build_type: RelWithDebInfo
|
||||
@@ -102,7 +96,7 @@ jobs:
|
||||
compiler: "llvm@17"
|
||||
- name: win64_msvc2019
|
||||
os: windows-2022
|
||||
build_type: "RelWithDebInfo;Debug"
|
||||
build_type: "RelWithDebInfo"
|
||||
compiler_type: x64
|
||||
compiler_version: 14.29
|
||||
qt_version: 5.15.2
|
||||
@@ -111,31 +105,13 @@ jobs:
|
||||
qt_tools: ""
|
||||
- name: win64_msvc2019
|
||||
os: windows-2022
|
||||
build_type: "RelWithDebInfo;Debug"
|
||||
build_type: "RelWithDebInfo"
|
||||
compiler_type: x64
|
||||
compiler_version: 14.29
|
||||
qt_version: 6.5.3
|
||||
qt_target: desktop
|
||||
qt_arch: win64_msvc2019_64
|
||||
qt_tools: ""
|
||||
- name: win64_mingw
|
||||
os: windows-2022
|
||||
build_type: RelWithDebInfo
|
||||
compiler_type: mingw810_64
|
||||
compiler_version: 8.10.0
|
||||
qt_version: 5.15.2
|
||||
qt_target: desktop
|
||||
qt_arch: win64_mingw81
|
||||
qt_tools: tools_mingw,qt.tools.win64_mingw810
|
||||
- name: win64_mingw
|
||||
os: windows-2022
|
||||
build_type: RelWithDebInfo
|
||||
compiler_type: mingw1120_64
|
||||
compiler_version: 11.2.0
|
||||
qt_version: 6.5.3
|
||||
qt_target: desktop
|
||||
qt_arch: win64_mingw
|
||||
qt_tools: tools_mingw90
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
BUILD_TYPE: ${{ matrix.build_type }}
|
||||
@@ -159,6 +135,22 @@ jobs:
|
||||
git submodule sync --recursive
|
||||
git -c core.longpaths=true -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 || true
|
||||
|
||||
- name: Install test dependencies
|
||||
if: runner.os == 'Linux' && matrix.compiler != ''
|
||||
run: |
|
||||
sudo apt-get install \
|
||||
libxkbcommon-x11-0 \
|
||||
libxcb-cursor0 \
|
||||
libxcb-icccm4 \
|
||||
libxcb-image0 \
|
||||
libxcb-keysyms1 \
|
||||
libxcb-randr0 \
|
||||
libxcb-render-util0 \
|
||||
libxcb-xinerama0 \
|
||||
libxcb-xfixes0 \
|
||||
libegl1-mesa \
|
||||
fonts-noto-cjk
|
||||
|
||||
- name: Install compiler
|
||||
id: install_compiler
|
||||
if: runner.os == 'Linux' && matrix.compiler != ''
|
||||
@@ -242,13 +234,10 @@ jobs:
|
||||
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX="../install" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="${DEPLOYMENT_TARGET}" \
|
||||
-DCMAKE_OSX_ARCHITECTURES="${DEPLOYMENT_ARCH}" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
-DMLN_WITH_QT=ON
|
||||
ninja
|
||||
ninja install
|
||||
|
||||
- name: Build maplibre-native (Linux, Qt5)
|
||||
if: runner.os == 'Linux' && matrix.qt_version == '5.15.2'
|
||||
@@ -267,13 +256,10 @@ jobs:
|
||||
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX="../install" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
-DMLN_WITH_QT=ON
|
||||
ninja
|
||||
ninja install
|
||||
|
||||
- name: Build maplibre-native (Linux, Qt6, custom compiler)
|
||||
- name: Build maplibre-native (Linux, Qt6, custom compiler, internal libraries)
|
||||
if: runner.os == 'Linux' && matrix.qt_version != '5.15.2' && matrix.compiler != ''
|
||||
run: |
|
||||
mkdir build-internal && cd build-internal
|
||||
@@ -283,11 +269,17 @@ jobs:
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON \
|
||||
-DMLN_QT_WITH_INTERNAL_ICU=ON \
|
||||
-DMLN_QT_WITH_INTERNAL_SQLITE=ON
|
||||
ninja
|
||||
|
||||
- name: Run tests (Linux)
|
||||
if: runner.os == 'Linux' && matrix.qt_version != '5.15.2' && matrix.compiler != ''
|
||||
uses: coactions/setup-xvfb@v1
|
||||
with:
|
||||
run: ctest --output-on-failure
|
||||
working-directory: build
|
||||
|
||||
- name: Build maplibre-native (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
shell: bash
|
||||
@@ -300,112 +292,5 @@ jobs:
|
||||
-DCMAKE_CONFIGURATION_TYPES="${BUILD_TYPE}" \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER="ccache.exe" \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache.exe" \
|
||||
-DCMAKE_INSTALL_PREFIX="../install" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
-DMLN_WITH_QT=ON
|
||||
ninja.exe
|
||||
ninja.exe install
|
||||
|
||||
- name: Create artifacts
|
||||
shell: bash
|
||||
env:
|
||||
QT_ARCH: ${{ matrix.name }}
|
||||
QT_VERSION: ${{ matrix.qt_version }}
|
||||
run: |
|
||||
pushd install
|
||||
tar cjvf "../maplibre-native_${QT_ARCH}_Qt${QT_VERSION}.tar.bz2" ./*
|
||||
popd
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }}
|
||||
path: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }}.tar.bz2
|
||||
|
||||
test-tarball:
|
||||
needs: build
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- name: Linux
|
||||
os: ubuntu-22.04
|
||||
qt_version: 6.5.3
|
||||
qt_target: desktop
|
||||
- name: macOS
|
||||
os: macos-12
|
||||
qt_version: 6.5.3
|
||||
qt_target: desktop
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
QT_ARCH: ${{ matrix.name }}
|
||||
QT_VERSION: ${{ matrix.qt_version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: source
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }}
|
||||
|
||||
- name: Download Qt
|
||||
uses: jurplel/install-qt-action@v3
|
||||
with:
|
||||
aqtversion: ==2.1.*
|
||||
version: ${{ env.QT_VERSION }}
|
||||
dir: ${{ github.workspace }}
|
||||
target: ${{ matrix.qt_target }}
|
||||
|
||||
- name: Setup Xcode
|
||||
if: runner.os == 'macOS'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: latest-stable
|
||||
|
||||
- name: Build test app
|
||||
run: |
|
||||
mkdir install && cd install
|
||||
tar xf "../maplibre-native_${QT_ARCH}_Qt${QT_VERSION}.tar.bz2"
|
||||
cd ..
|
||||
export CMAKE_PREFIX_PATH="$PWD/install"
|
||||
mkdir build && cd build
|
||||
cmake ../source/platform/qt/app/
|
||||
make
|
||||
|
||||
release:
|
||||
name: Release QMapLibreGL
|
||||
if: github.ref_type == 'tag'
|
||||
runs-on: ubuntu-22.04
|
||||
needs: test-tarball
|
||||
strategy:
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
name: [Linux, macOS, win64_msvc2019, win64_mingw]
|
||||
qt_version: [5.15.2, 6.5.3]
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }}
|
||||
|
||||
- name: Name tarball
|
||||
env:
|
||||
TAG_NAME: ${{ github.ref_name }}
|
||||
TAG_PLATFORM: ${{ matrix.name }}
|
||||
QT_VERSION: ${{ matrix.qt_version }}
|
||||
run: |
|
||||
mv "maplibre-native_${TAG_PLATFORM}_Qt${QT_VERSION}.tar.bz2" "QMapLibreGL_${TAG_NAME//qt-/}_Qt${QT_VERSION}_${TAG_PLATFORM}.tar.bz2"
|
||||
|
||||
- name: Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: QMapLibreGL_*.tar.bz2
|
||||
allowUpdates: true
|
||||
draft: true
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,6 +21,7 @@
|
||||
|
||||
.DS_Store
|
||||
.cache
|
||||
compile_commands.json
|
||||
/build
|
||||
**/.idea
|
||||
/platform/android/MapboxGLAndroidSDKTestApp/local.properties
|
||||
|
||||
@@ -2,14 +2,8 @@
|
||||
|
||||
## Upcoming
|
||||
|
||||
### ✨ New features
|
||||
|
||||
- Support for GeoJSON feature collections using std::list ([#541](https://github.com/maplibre/maplibre-native/pull/541)).
|
||||
- Based on Qt 6.5.0
|
||||
|
||||
### 🐞 Bug fixes
|
||||
|
||||
- Fixed bitcode issues on iOS.
|
||||
MapLibre native Qt bindings have been moved to
|
||||
[maplibre-native-qt](https://github.com/maplibre/maplibre-native-qt) repository.
|
||||
|
||||
## v2.0.1
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(Qt@QT_VERSION_MAJOR@
|
||||
COMPONENTS Gui @REQUIRED_QT_VERSION@)
|
||||
find_dependency(Qt@QT_VERSION_MAJOR@
|
||||
COMPONENTS Network @REQUIRED_QT_VERSION@)
|
||||
|
||||
if(@MLN_QT_STATIC@ AND NOT @MLN_QT_INSIDE_PLUGIN@ AND NOT @MLN_QT_WITH_INTERNAL_SQLITE@)
|
||||
find_dependency(Qt@QT_VERSION_MAJOR@
|
||||
COMPONENTS Sql @REQUIRED_QT_VERSION@)
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/QMapLibreGLTargets.cmake")
|
||||
@PACKAGE_INCLUDE_QCHTARGETS@
|
||||
@@ -1,46 +1,8 @@
|
||||
# MapLibre Native for Qt
|
||||
|
||||
[](https://github.com/maplibre/maplibre-native/actions/workflows/qt-ci.yml)
|
||||
[](https://github.com/maplibre/maplibre-native/actions/workflows/qt-ci.yml)
|
||||
|
||||
This is a community maintained MapLibre SDK for usage in Qt apps.
|
||||
Both Qt5 (minimal 5.6) and Qt6 are supported.
|
||||
Note that only OpenGL rendering is supported at the moment.
|
||||
|
||||
## Supported platforms
|
||||
|
||||
- macOS
|
||||
- iOS
|
||||
- Android
|
||||
- Linux
|
||||
- Windows
|
||||
|
||||
## Building
|
||||
|
||||
This project uses out of source build. CMake 3.10 or later is used to generate
|
||||
make files. Ninja is recommended.
|
||||
|
||||
Before the project can be built Qt installation needs to be added to the `PATH`:
|
||||
|
||||
```shell
|
||||
export PATH=<path_to_Qt>/Qt/<Qt_version>/<Qt_platform>/bin:$PATH
|
||||
```
|
||||
|
||||
A minimal set of commands to build and install is
|
||||
|
||||
```shell
|
||||
mkdir build && cd build
|
||||
cmake ../maplibre-native/ \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=<installation_prefix> \
|
||||
-DMLN_WITH_QT=ON
|
||||
ninja
|
||||
ninja install
|
||||
```
|
||||
|
||||
`<installation_prefix>` above should be replaced with a wished installation path.
|
||||
Files installed there can later be used as the dependency for your app.
|
||||
|
||||
For platform-specific details look at build scripts provided
|
||||
in the [scripts](scripts) folder. Each script requires (at least) paths
|
||||
to source and installation locations.
|
||||
MapLibre native Qt bindings have been moved to
|
||||
[maplibre-native-qt](https://github.com/maplibre/maplibre-native-qt) repository.
|
||||
This folder only contains minimal platform-specific implementation and allows
|
||||
sufficient testing of the MapLibre Core built with Qt as platform.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
2.0.1
|
||||
@@ -1,30 +0,0 @@
|
||||
# minimal CMakeLists.txt for QMapLibreGL usage
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(hellomaplibre VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if(APPLE) # suppress some warnings in Qt6
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
endif()
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGLWidgets Widgets)
|
||||
qt_standard_project_setup()
|
||||
|
||||
find_package(QMapLibreGL REQUIRED)
|
||||
|
||||
add_executable(hellomaplibre
|
||||
main.cpp
|
||||
mapwindow.cpp
|
||||
mapwindow.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(hellomaplibre
|
||||
PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::OpenGLWidgets
|
||||
Qt6::Widgets
|
||||
QMapLibreGL
|
||||
)
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "mapwindow.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QMapLibreGL::Settings settings;
|
||||
settings.setCacheDatabasePath("/tmp/mbgl-cache.db");
|
||||
settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
||||
|
||||
settings.setClientName("TestApp");
|
||||
settings.setClientVersion("1.0");
|
||||
|
||||
MapWindow window(settings);
|
||||
|
||||
window.resize(800, 600);
|
||||
window.show();
|
||||
|
||||
if (argc == 2 && QString("--test") == argv[1]) {
|
||||
window.selfTest();
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -1,474 +0,0 @@
|
||||
#include "mapwindow.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QIcon>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QString>
|
||||
|
||||
int kAnimationDuration = 10000;
|
||||
|
||||
MapWindow::MapWindow(const QMapLibreGL::Settings &settings)
|
||||
: m_settings(settings) {
|
||||
setWindowIcon(QIcon(":icon.png"));
|
||||
}
|
||||
|
||||
MapWindow::~MapWindow() {
|
||||
// Make sure we have a valid context so we
|
||||
// can delete the QMapLibreGL::Map.
|
||||
makeCurrent();
|
||||
}
|
||||
|
||||
void MapWindow::selfTest() {
|
||||
if (m_bearingAnimation) {
|
||||
m_bearingAnimation->setDuration(kAnimationDuration);
|
||||
m_bearingAnimation->setEndValue(m_map->bearing() + 360 * 4);
|
||||
m_bearingAnimation->start();
|
||||
}
|
||||
|
||||
if (m_zoomAnimation) {
|
||||
m_zoomAnimation->setDuration(kAnimationDuration);
|
||||
m_zoomAnimation->setEndValue(m_map->zoom() + 3);
|
||||
m_zoomAnimation->start();
|
||||
}
|
||||
}
|
||||
|
||||
qreal MapWindow::pixelRatio() {
|
||||
return devicePixelRatioF();
|
||||
}
|
||||
|
||||
void MapWindow::animationFinished() {
|
||||
qDebug() << "Animation ticks/s: " << m_animationTicks / static_cast<float>(kAnimationDuration) * 1000.;
|
||||
qDebug() << "Frame draws/s: " << m_frameDraws / static_cast<float>(kAnimationDuration) * 1000.;
|
||||
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void MapWindow::animationValueChanged() {
|
||||
m_animationTicks++;
|
||||
}
|
||||
|
||||
void MapWindow::changeStyle() {
|
||||
static uint8_t currentStyleIndex;
|
||||
|
||||
auto &styles = m_map->defaultStyles();
|
||||
|
||||
m_map->setStyleUrl(styles[currentStyleIndex].first);
|
||||
setWindowTitle(QString("MapLibre Native: ") + styles[currentStyleIndex].second);
|
||||
|
||||
if (++currentStyleIndex == styles.size()) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
|
||||
m_sourceAdded = false;
|
||||
}
|
||||
|
||||
void MapWindow::keyPressEvent(QKeyEvent *ev) {
|
||||
switch (ev->key()) {
|
||||
case Qt::Key_S:
|
||||
changeStyle();
|
||||
break;
|
||||
case Qt::Key_L: {
|
||||
if (m_sourceAdded) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_sourceAdded = true;
|
||||
|
||||
// Not in all styles, but will work on streets
|
||||
QString before = "waterway-label";
|
||||
|
||||
QFile geojson(":source1.geojson");
|
||||
geojson.open(QIODevice::ReadOnly);
|
||||
|
||||
// The data source for the route line and markers
|
||||
QVariantMap routeSource;
|
||||
routeSource["type"] = "geojson";
|
||||
routeSource["data"] = geojson.readAll();
|
||||
m_map->addSource("routeSource", routeSource);
|
||||
|
||||
// The route case, painted before the route
|
||||
QVariantMap routeCase;
|
||||
routeCase["id"] = "routeCase";
|
||||
routeCase["type"] = "line";
|
||||
routeCase["source"] = "routeSource";
|
||||
m_map->addLayer(routeCase, before);
|
||||
|
||||
m_map->setPaintProperty("routeCase", "line-color", QColor("white"));
|
||||
m_map->setPaintProperty("routeCase", "line-width", 20.0);
|
||||
m_map->setLayoutProperty("routeCase", "line-join", "round");
|
||||
m_map->setLayoutProperty("routeCase", "line-cap", "round");
|
||||
|
||||
// The route, painted on top of the route case
|
||||
QVariantMap route;
|
||||
route["id"] = "route";
|
||||
route["type"] = "line";
|
||||
route["source"] = "routeSource";
|
||||
m_map->addLayer(route, before);
|
||||
|
||||
m_map->setPaintProperty("route", "line-color", QColor("blue"));
|
||||
m_map->setPaintProperty("route", "line-width", 8.0);
|
||||
m_map->setLayoutProperty("route", "line-join", "round");
|
||||
m_map->setLayoutProperty("route", "line-cap", "round");
|
||||
|
||||
QVariantList lineDashArray;
|
||||
lineDashArray.append(1);
|
||||
lineDashArray.append(2);
|
||||
|
||||
m_map->setPaintProperty("route", "line-dasharray", lineDashArray);
|
||||
|
||||
// Markers at the beginning and end of the route
|
||||
m_map->addImage("label-arrow", QImage(":label-arrow.svg"));
|
||||
m_map->addImage("label-background", QImage(":label-background.svg"));
|
||||
|
||||
QVariantMap markerArrow;
|
||||
markerArrow["id"] = "markerArrow";
|
||||
markerArrow["type"] = "symbol";
|
||||
markerArrow["source"] = "routeSource";
|
||||
m_map->addLayer(markerArrow);
|
||||
|
||||
m_map->setLayoutProperty("markerArrow", "icon-image", "label-arrow");
|
||||
m_map->setLayoutProperty("markerArrow", "icon-size", 0.5);
|
||||
m_map->setLayoutProperty("markerArrow", "icon-ignore-placement", true);
|
||||
|
||||
QVariantList arrowOffset;
|
||||
arrowOffset.append(0.0);
|
||||
arrowOffset.append(-15.0);
|
||||
m_map->setLayoutProperty("markerArrow", "icon-offset", arrowOffset);
|
||||
|
||||
QVariantMap markerBackground;
|
||||
markerBackground["id"] = "markerBackground";
|
||||
markerBackground["type"] = "symbol";
|
||||
markerBackground["source"] = "routeSource";
|
||||
m_map->addLayer(markerBackground);
|
||||
|
||||
m_map->setLayoutProperty("markerBackground", "icon-image", "label-background");
|
||||
m_map->setLayoutProperty("markerBackground", "text-field", "{name}");
|
||||
m_map->setLayoutProperty("markerBackground", "icon-text-fit", "both");
|
||||
m_map->setLayoutProperty("markerBackground", "icon-ignore-placement", true);
|
||||
m_map->setLayoutProperty("markerBackground", "text-ignore-placement", true);
|
||||
m_map->setLayoutProperty("markerBackground", "text-anchor", "left");
|
||||
m_map->setLayoutProperty("markerBackground", "text-size", 16.0);
|
||||
m_map->setLayoutProperty("markerBackground", "text-padding", 0.0);
|
||||
m_map->setLayoutProperty("markerBackground", "text-line-height", 1.0);
|
||||
m_map->setLayoutProperty("markerBackground", "text-max-width", 8.0);
|
||||
|
||||
QVariantList iconTextFitPadding;
|
||||
iconTextFitPadding.append(15.0);
|
||||
iconTextFitPadding.append(10.0);
|
||||
iconTextFitPadding.append(15.0);
|
||||
iconTextFitPadding.append(10.0);
|
||||
m_map->setLayoutProperty("markerBackground", "icon-text-fit-padding", iconTextFitPadding);
|
||||
|
||||
QVariantList backgroundOffset;
|
||||
backgroundOffset.append(-0.5);
|
||||
backgroundOffset.append(-1.5);
|
||||
m_map->setLayoutProperty("markerBackground", "text-offset", backgroundOffset);
|
||||
|
||||
m_map->setPaintProperty("markerBackground", "text-color", QColor("white"));
|
||||
|
||||
QVariantList filterExpression;
|
||||
filterExpression.append("==");
|
||||
filterExpression.append("$type");
|
||||
filterExpression.append("Point");
|
||||
|
||||
QVariantList filter;
|
||||
filter.append(filterExpression);
|
||||
|
||||
m_map->setFilter("markerArrow", filter);
|
||||
m_map->setFilter("markerBackground", filter);
|
||||
|
||||
// Tilt the labels when tilting the map and make them larger
|
||||
m_map->setLayoutProperty("road-label-large", "text-size", 30.0);
|
||||
m_map->setLayoutProperty("road-label-large", "text-pitch-alignment", "viewport");
|
||||
|
||||
m_map->setLayoutProperty("road-label-medium", "text-size", 30.0);
|
||||
m_map->setLayoutProperty("road-label-medium", "text-pitch-alignment", "viewport");
|
||||
|
||||
m_map->setLayoutProperty("road-label-small", "text-pitch-alignment", "viewport");
|
||||
m_map->setLayoutProperty("road-label-small", "text-size", 30.0);
|
||||
|
||||
// Buildings extrusion
|
||||
QVariantMap buildings;
|
||||
buildings["id"] = "3d-buildings";
|
||||
buildings["source"] = "composite";
|
||||
buildings["source-layer"] = "building";
|
||||
buildings["type"] = "fill-extrusion";
|
||||
buildings["minzoom"] = 15.0;
|
||||
m_map->addLayer(buildings);
|
||||
|
||||
QVariantList buildingsFilterExpression;
|
||||
buildingsFilterExpression.append("==");
|
||||
buildingsFilterExpression.append("extrude");
|
||||
buildingsFilterExpression.append("true");
|
||||
|
||||
QVariantList buildingsFilter;
|
||||
buildingsFilter.append(buildingsFilterExpression);
|
||||
|
||||
m_map->setFilter("3d-buildings", buildingsFilterExpression);
|
||||
|
||||
QString fillExtrusionColorJSON = R"JSON(
|
||||
[
|
||||
"interpolate",
|
||||
["linear"],
|
||||
["get", "height"],
|
||||
0.0, "blue",
|
||||
20.0, "royalblue",
|
||||
40.0, "cyan",
|
||||
60.0, "lime",
|
||||
80.0, "yellow",
|
||||
100.0, "red"
|
||||
]
|
||||
)JSON";
|
||||
|
||||
m_map->setPaintProperty("3d-buildings", "fill-extrusion-color", fillExtrusionColorJSON);
|
||||
m_map->setPaintProperty("3d-buildings", "fill-extrusion-opacity", .6);
|
||||
|
||||
QVariantMap extrusionHeight;
|
||||
extrusionHeight["type"] = "identity";
|
||||
extrusionHeight["property"] = "height";
|
||||
|
||||
m_map->setPaintProperty("3d-buildings", "fill-extrusion-height", extrusionHeight);
|
||||
|
||||
QVariantMap extrusionBase;
|
||||
extrusionBase["type"] = "identity";
|
||||
extrusionBase["property"] = "min_height";
|
||||
|
||||
m_map->setPaintProperty("3d-buildings", "fill-extrusion-base", extrusionBase);
|
||||
} break;
|
||||
case Qt::Key_1: {
|
||||
if (m_symbolAnnotationId.isNull()) {
|
||||
QMapLibreGL::Coordinate coordinate = m_map->coordinate();
|
||||
QMapLibreGL::SymbolAnnotation symbol{coordinate, "default_marker"};
|
||||
m_map->addAnnotationIcon("default_marker", QImage(":default_marker.svg"));
|
||||
m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::SymbolAnnotation>(symbol));
|
||||
} else {
|
||||
m_map->removeAnnotation(m_symbolAnnotationId.toUInt());
|
||||
m_symbolAnnotationId.clear();
|
||||
}
|
||||
} break;
|
||||
case Qt::Key_2: {
|
||||
if (m_lineAnnotationId.isNull()) {
|
||||
QMapLibreGL::Coordinates coordinates;
|
||||
coordinates.push_back(m_map->coordinateForPixel({0, 0}));
|
||||
coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), qreal(size().height())}));
|
||||
|
||||
QMapLibreGL::CoordinatesCollection collection;
|
||||
collection.push_back(coordinates);
|
||||
|
||||
QMapLibreGL::CoordinatesCollections lineGeometry;
|
||||
lineGeometry.push_back(collection);
|
||||
|
||||
QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(
|
||||
QMapLibreGL::ShapeAnnotationGeometry::LineStringType, lineGeometry);
|
||||
|
||||
QMapLibreGL::LineAnnotation line;
|
||||
line.geometry = annotationGeometry;
|
||||
line.opacity = 0.5f;
|
||||
line.width = 1.0f;
|
||||
line.color = Qt::red;
|
||||
m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::LineAnnotation>(line));
|
||||
} else {
|
||||
m_map->removeAnnotation(m_lineAnnotationId.toUInt());
|
||||
m_lineAnnotationId.clear();
|
||||
}
|
||||
} break;
|
||||
case Qt::Key_3: {
|
||||
if (m_fillAnnotationId.isNull()) {
|
||||
QMapLibreGL::Coordinates coordinates;
|
||||
coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), 0}));
|
||||
coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), qreal(size().height())}));
|
||||
coordinates.push_back(m_map->coordinateForPixel({0, qreal(size().height())}));
|
||||
coordinates.push_back(m_map->coordinateForPixel({0, 0}));
|
||||
|
||||
QMapLibreGL::CoordinatesCollection collection;
|
||||
collection.push_back(coordinates);
|
||||
|
||||
QMapLibreGL::CoordinatesCollections fillGeometry;
|
||||
fillGeometry.push_back(collection);
|
||||
|
||||
QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(
|
||||
QMapLibreGL::ShapeAnnotationGeometry::PolygonType, fillGeometry);
|
||||
|
||||
QMapLibreGL::FillAnnotation fill;
|
||||
fill.geometry = annotationGeometry;
|
||||
fill.opacity = 0.5f;
|
||||
fill.color = Qt::green;
|
||||
fill.outlineColor = QVariant::fromValue<QColor>(QColor(Qt::black));
|
||||
m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::FillAnnotation>(fill));
|
||||
} else {
|
||||
m_map->removeAnnotation(m_fillAnnotationId.toUInt());
|
||||
m_fillAnnotationId.clear();
|
||||
}
|
||||
} break;
|
||||
case Qt::Key_5: {
|
||||
if (m_map->layerExists("circleLayer")) {
|
||||
m_map->removeLayer("circleLayer");
|
||||
m_map->removeSource("circleSource");
|
||||
} else {
|
||||
QMapLibreGL::Coordinates coordinates;
|
||||
coordinates.push_back(m_map->coordinate());
|
||||
|
||||
QMapLibreGL::CoordinatesCollection collection;
|
||||
collection.push_back(coordinates);
|
||||
|
||||
QMapLibreGL::CoordinatesCollections point;
|
||||
point.push_back(collection);
|
||||
|
||||
QMapLibreGL::Feature feature(QMapLibreGL::Feature::PointType, point, {}, {});
|
||||
|
||||
QVariantMap circleSource;
|
||||
circleSource["type"] = "geojson";
|
||||
circleSource["data"] = QVariant::fromValue<QMapLibreGL::Feature>(feature);
|
||||
m_map->addSource("circleSource", circleSource);
|
||||
|
||||
QVariantMap circle;
|
||||
circle["id"] = "circleLayer";
|
||||
circle["type"] = "circle";
|
||||
circle["source"] = "circleSource";
|
||||
m_map->addLayer(circle);
|
||||
|
||||
m_map->setPaintProperty("circleLayer", "circle-radius", 10.0);
|
||||
m_map->setPaintProperty("circleLayer", "circle-color", QColor("black"));
|
||||
}
|
||||
} break;
|
||||
case Qt::Key_6: {
|
||||
if (m_map->layerExists("innerCirclesLayer") || m_map->layerExists("outerCirclesLayer")) {
|
||||
m_map->removeLayer("innerCirclesLayer");
|
||||
m_map->removeLayer("outerCirclesLayer");
|
||||
m_map->removeSource("innerCirclesSource");
|
||||
m_map->removeSource("outerCirclesSource");
|
||||
} else {
|
||||
auto makePoint = [&](double dx, double dy, const QString &color) {
|
||||
auto coordinate = m_map->coordinate();
|
||||
coordinate.first += dx;
|
||||
coordinate.second += dy;
|
||||
return QMapLibreGL::Feature{
|
||||
QMapLibreGL::Feature::PointType, {{{coordinate}}}, {{"color", color}}, {}};
|
||||
};
|
||||
|
||||
// multiple features by QVector<QMapLibreGL::Feature>
|
||||
QVector<QMapLibreGL::Feature> inner{
|
||||
makePoint(0.001, 0, "red"), makePoint(0, 0.001, "green"), makePoint(0, -0.001, "blue")};
|
||||
|
||||
m_map->addSource("innerCirclesSource", {{"type", "geojson"}, {"data", QVariant::fromValue(inner)}});
|
||||
m_map->addLayer({{"id", "innerCirclesLayer"}, {"type", "circle"}, {"source", "innerCirclesSource"}});
|
||||
|
||||
// multiple features by QList<QMapLibreGL::Feature>
|
||||
QList<QMapLibreGL::Feature> outer{makePoint(0.002, 0.002, "cyan"),
|
||||
makePoint(-0.002, 0.002, "magenta"),
|
||||
makePoint(0.002, -0.002, "yellow"),
|
||||
makePoint(-0.002, -0.002, "black")};
|
||||
|
||||
m_map->addSource("outerCirclesSource", {{"type", "geojson"}, {"data", QVariant::fromValue(outer)}});
|
||||
m_map->addLayer({{"id", "outerCirclesLayer"}, {"type", "circle"}, {"source", "outerCirclesSource"}});
|
||||
|
||||
QVariantList getColor{"get", "color"};
|
||||
m_map->setPaintProperty("innerCirclesLayer", "circle-radius", 10.0);
|
||||
m_map->setPaintProperty("innerCirclesLayer", "circle-color", getColor);
|
||||
m_map->setPaintProperty("outerCirclesLayer", "circle-radius", 15.0);
|
||||
m_map->setPaintProperty("outerCirclesLayer", "circle-color", getColor);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
void MapWindow::mousePressEvent(QMouseEvent *ev) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
m_lastPos = ev->position();
|
||||
#else
|
||||
m_lastPos = ev->localPos();
|
||||
#endif
|
||||
|
||||
if (ev->type() == QEvent::MouseButtonPress) {
|
||||
if (ev->buttons() == (Qt::LeftButton | Qt::RightButton)) {
|
||||
changeStyle();
|
||||
}
|
||||
}
|
||||
|
||||
if (ev->type() == QEvent::MouseButtonDblClick) {
|
||||
if (ev->buttons() == Qt::LeftButton) {
|
||||
m_map->scaleBy(2.0, m_lastPos);
|
||||
} else if (ev->buttons() == Qt::RightButton) {
|
||||
m_map->scaleBy(0.5, m_lastPos);
|
||||
}
|
||||
}
|
||||
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
void MapWindow::mouseMoveEvent(QMouseEvent *ev) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
const QPointF &position = ev->position();
|
||||
#else
|
||||
const QPointF &position = ev->localPos();
|
||||
#endif
|
||||
|
||||
QPointF delta = position - m_lastPos;
|
||||
if (!delta.isNull()) {
|
||||
if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) {
|
||||
m_map->pitchBy(delta.y());
|
||||
} else if (ev->buttons() == Qt::LeftButton) {
|
||||
m_map->moveBy(delta);
|
||||
} else if (ev->buttons() == Qt::RightButton) {
|
||||
m_map->rotateBy(m_lastPos, position);
|
||||
}
|
||||
}
|
||||
|
||||
m_lastPos = position;
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
void MapWindow::wheelEvent(QWheelEvent *ev) {
|
||||
if (ev->angleDelta().y() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float factor = ev->angleDelta().y() / 1200.;
|
||||
if (ev->angleDelta().y() < 0) {
|
||||
factor = factor > -1 ? factor : 1 / factor;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
m_map->scaleBy(1 + factor, ev->position());
|
||||
#else
|
||||
m_map->scaleBy(1 + factor, ev->pos());
|
||||
#endif
|
||||
ev->accept();
|
||||
}
|
||||
|
||||
void MapWindow::initializeGL() {
|
||||
m_map.reset(new QMapLibreGL::Map(nullptr, m_settings, size(), pixelRatio()));
|
||||
connect(m_map.get(), SIGNAL(needsRendering()), this, SLOT(update()));
|
||||
|
||||
// Set default location to Helsinki.
|
||||
m_map->setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 5);
|
||||
|
||||
QString styleUrl = qgetenv("MLN_STYLE_URL");
|
||||
if (styleUrl.isEmpty()) {
|
||||
changeStyle();
|
||||
} else {
|
||||
m_map->setStyleUrl(styleUrl);
|
||||
setWindowTitle(QString("MapLibre Native: ") + styleUrl);
|
||||
}
|
||||
|
||||
m_bearingAnimation = new QPropertyAnimation(m_map.get(), "bearing");
|
||||
m_zoomAnimation = new QPropertyAnimation(m_map.get(), "zoom");
|
||||
|
||||
connect(m_zoomAnimation, &QPropertyAnimation::finished, this, &MapWindow::animationFinished);
|
||||
connect(m_zoomAnimation, &QPropertyAnimation::valueChanged, this, &MapWindow::animationValueChanged);
|
||||
}
|
||||
|
||||
void MapWindow::paintGL() {
|
||||
m_frameDraws++;
|
||||
m_map->resize(size());
|
||||
m_map->setFramebufferObject(defaultFramebufferObject(), size() * pixelRatio());
|
||||
m_map->render();
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef MAPWINDOW_H
|
||||
#define MAPWINDOW_H
|
||||
|
||||
#include <QMapLibreGL/Map>
|
||||
#include <QMapLibreGL/Settings>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MapWindow : public QOpenGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapWindow(const QMapLibreGL::Settings &);
|
||||
~MapWindow();
|
||||
|
||||
void selfTest();
|
||||
|
||||
protected slots:
|
||||
void animationValueChanged();
|
||||
void animationFinished();
|
||||
|
||||
private:
|
||||
void changeStyle();
|
||||
qreal pixelRatio();
|
||||
|
||||
// QWidget implementation.
|
||||
void keyPressEvent(QKeyEvent *ev) final;
|
||||
void mousePressEvent(QMouseEvent *ev) final;
|
||||
void mouseMoveEvent(QMouseEvent *ev) final;
|
||||
void wheelEvent(QWheelEvent *ev) final;
|
||||
|
||||
// Q{,Open}GLWidget implementation.
|
||||
void initializeGL() final;
|
||||
void paintGL() final;
|
||||
|
||||
QPointF m_lastPos;
|
||||
|
||||
QMapLibreGL::Settings m_settings;
|
||||
std::unique_ptr<QMapLibreGL::Map> m_map{};
|
||||
|
||||
QPropertyAnimation *m_bearingAnimation{};
|
||||
QPropertyAnimation *m_zoomAnimation{};
|
||||
|
||||
unsigned m_animationTicks{};
|
||||
unsigned m_frameDraws{};
|
||||
|
||||
QVariant m_symbolAnnotationId;
|
||||
QVariant m_lineAnnotationId;
|
||||
QVariant m_fillAnnotationId;
|
||||
|
||||
bool m_sourceAdded{};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,19 +0,0 @@
|
||||
include($QT_INSTALL_DOCS/global/macros.qdocconf)
|
||||
include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf)
|
||||
include($QT_INSTALL_DOCS/global/compat.qdocconf)
|
||||
include($QT_INSTALL_DOCS/global/fileextensions.qdocconf)
|
||||
include($QT_INSTALL_DOCS/global/qt-html-templates-online.qdocconf)
|
||||
|
||||
Cpp.ignoretokens = Q_MAPLIBRE_EXPORT
|
||||
|
||||
project = QMapLibreGL
|
||||
description = MapLibre Native SDK for Qt
|
||||
language = Cpp
|
||||
|
||||
outputdir = docs
|
||||
headerdirs += include
|
||||
sourcedirs += src
|
||||
|
||||
indexes = $QT_INSTALL_DOCS/qtcore/qtcore.index \
|
||||
$QT_INSTALL_DOCS/qtgui/qtgui.index \
|
||||
$QT_INSTALL_DOCS/qtnetwork/qtnetwork.index
|
||||
@@ -1 +0,0 @@
|
||||
#include "map.hpp"
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "export.hpp"
|
||||
#include "map.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "types.hpp"
|
||||
#include "utils.hpp"
|
||||
@@ -1 +0,0 @@
|
||||
#include "settings.hpp"
|
||||
@@ -1 +0,0 @@
|
||||
#include "types.hpp"
|
||||
@@ -1 +0,0 @@
|
||||
#include "utils.hpp"
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef QMAPLIBRE_EXPORT_H
|
||||
#define QMAPLIBRE_EXPORT_H
|
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
#if !defined(QT_MAPLIBREGL_STATIC)
|
||||
#if defined(QT_BUILD_MAPLIBREGL_LIB)
|
||||
#define Q_MAPLIBREGL_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define Q_MAPLIBREGL_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define Q_MAPLIBREGL_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // QMAPLIBRE_EXPORT_H
|
||||
@@ -1,197 +0,0 @@
|
||||
#ifndef QMAPLIBREGL_MAP_H
|
||||
#define QMAPLIBREGL_MAP_H
|
||||
|
||||
#include <QMapLibreGL/Settings>
|
||||
#include <QMapLibreGL/Types>
|
||||
|
||||
#include <QImage>
|
||||
#include <QMargins>
|
||||
#include <QObject>
|
||||
#include <QPointF>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
class MapPrivate;
|
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
class Q_MAPLIBREGL_EXPORT Map : public QObject {
|
||||
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)
|
||||
Q_PROPERTY(double bearing READ bearing WRITE setBearing)
|
||||
Q_PROPERTY(double pitch READ pitch WRITE setPitch)
|
||||
Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson)
|
||||
Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl)
|
||||
Q_PROPERTY(double scale READ scale WRITE setScale)
|
||||
Q_PROPERTY(QMapLibreGL::Coordinate coordinate READ coordinate WRITE setCoordinate)
|
||||
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
|
||||
|
||||
public:
|
||||
enum MapChange {
|
||||
MapChangeRegionWillChange = 0,
|
||||
MapChangeRegionWillChangeAnimated,
|
||||
MapChangeRegionIsChanging,
|
||||
MapChangeRegionDidChange,
|
||||
MapChangeRegionDidChangeAnimated,
|
||||
MapChangeWillStartLoadingMap,
|
||||
MapChangeDidFinishLoadingMap,
|
||||
MapChangeDidFailLoadingMap,
|
||||
MapChangeWillStartRenderingFrame,
|
||||
MapChangeDidFinishRenderingFrame,
|
||||
MapChangeDidFinishRenderingFrameFullyRendered,
|
||||
MapChangeWillStartRenderingMap,
|
||||
MapChangeDidFinishRenderingMap,
|
||||
MapChangeDidFinishRenderingMapFullyRendered,
|
||||
MapChangeDidFinishLoadingStyle,
|
||||
MapChangeSourceDidChange
|
||||
};
|
||||
|
||||
enum MapLoadingFailure {
|
||||
StyleParseFailure,
|
||||
StyleLoadFailure,
|
||||
NotFoundFailure,
|
||||
UnknownFailure
|
||||
};
|
||||
|
||||
// Determines the orientation of the map.
|
||||
enum NorthOrientation {
|
||||
NorthUpwards, // Default
|
||||
NorthRightwards,
|
||||
NorthDownwards,
|
||||
NorthLeftwards,
|
||||
};
|
||||
|
||||
Map(QObject *parent = 0, const Settings & = Settings(), const QSize &size = QSize(), qreal pixelRatio = 1);
|
||||
virtual ~Map();
|
||||
|
||||
QString styleJson() const;
|
||||
QString styleUrl() const;
|
||||
|
||||
void setStyleJson(const QString &);
|
||||
void setStyleUrl(const QString &);
|
||||
|
||||
double latitude() const;
|
||||
void setLatitude(double latitude);
|
||||
|
||||
double longitude() const;
|
||||
void setLongitude(double longitude);
|
||||
|
||||
double scale() const;
|
||||
void setScale(double scale, const QPointF ¢er = QPointF());
|
||||
|
||||
double zoom() const;
|
||||
void setZoom(double zoom);
|
||||
|
||||
double minimumZoom() const;
|
||||
double maximumZoom() const;
|
||||
|
||||
double bearing() const;
|
||||
void setBearing(double degrees);
|
||||
void setBearing(double degrees, const QPointF ¢er);
|
||||
|
||||
double pitch() const;
|
||||
void setPitch(double pitch);
|
||||
void pitchBy(double pitch);
|
||||
|
||||
NorthOrientation northOrientation() const;
|
||||
void setNorthOrientation(NorthOrientation);
|
||||
|
||||
Coordinate coordinate() const;
|
||||
void setCoordinate(const Coordinate &);
|
||||
void setCoordinateZoom(const Coordinate &, double zoom);
|
||||
|
||||
void jumpTo(const CameraOptions &);
|
||||
|
||||
void setGestureInProgress(bool inProgress);
|
||||
|
||||
void setTransitionOptions(qint64 duration, qint64 delay = 0);
|
||||
|
||||
void addAnnotationIcon(const QString &name, const QImage &sprite);
|
||||
|
||||
AnnotationID addAnnotation(const Annotation &);
|
||||
void updateAnnotation(AnnotationID, const Annotation &);
|
||||
void removeAnnotation(AnnotationID);
|
||||
|
||||
bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
|
||||
bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value);
|
||||
|
||||
bool isFullyLoaded() const;
|
||||
|
||||
void moveBy(const QPointF &offset);
|
||||
void scaleBy(double scale, const QPointF ¢er = QPointF());
|
||||
void rotateBy(const QPointF &first, const QPointF &second);
|
||||
|
||||
void resize(const QSize &size);
|
||||
|
||||
QPointF pixelForCoordinate(const Coordinate &) const;
|
||||
Coordinate coordinateForPixel(const QPointF &) const;
|
||||
|
||||
CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne) const;
|
||||
CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne, double bearing, double pitch);
|
||||
|
||||
void setMargins(const QMargins &margins);
|
||||
QMargins margins() const;
|
||||
|
||||
void addSource(const QString &sourceID, const QVariantMap ¶ms);
|
||||
bool sourceExists(const QString &sourceID);
|
||||
void updateSource(const QString &sourceID, const QVariantMap ¶ms);
|
||||
void removeSource(const QString &sourceID);
|
||||
|
||||
void addImage(const QString &name, const QImage &sprite);
|
||||
void removeImage(const QString &name);
|
||||
|
||||
void addCustomLayer(const QString &id,
|
||||
std::unique_ptr<CustomLayerHostInterface> host,
|
||||
const QString &before = QString());
|
||||
void addLayer(const QVariantMap ¶ms, const QString &before = QString());
|
||||
bool layerExists(const QString &id);
|
||||
void removeLayer(const QString &id);
|
||||
|
||||
QVector<QString> layerIds() const;
|
||||
|
||||
void setFilter(const QString &layer, const QVariant &filter);
|
||||
QVariant getFilter(const QString &layer) const;
|
||||
// When rendering on a different thread,
|
||||
// should be called on the render thread.
|
||||
void createRenderer();
|
||||
void destroyRenderer();
|
||||
void setFramebufferObject(quint32 fbo, const QSize &size);
|
||||
|
||||
const QVector<QPair<QString, QString>> &defaultStyles() const;
|
||||
|
||||
public slots:
|
||||
void render();
|
||||
void connectionEstablished();
|
||||
|
||||
// Commit changes, load all the resources
|
||||
// and renders the map when completed.
|
||||
void startStaticRender();
|
||||
|
||||
signals:
|
||||
void needsRendering();
|
||||
void mapChanged(Map::MapChange);
|
||||
void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason);
|
||||
void copyrightsChanged(const QString ©rightsHtml);
|
||||
|
||||
void staticRenderFinished(const QString &error);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(Map)
|
||||
|
||||
MapPrivate *d_ptr;
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::Map::MapChange);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::Map::MapLoadingFailure);
|
||||
|
||||
#endif // QMAPLIBREGL_MAP_H
|
||||
@@ -1,117 +0,0 @@
|
||||
#ifndef QMAPLIBREGL_SETTINGS_H
|
||||
#define QMAPLIBREGL_SETTINGS_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QString>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "export.hpp"
|
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
// TODO: this will be wrapped at some point
|
||||
namespace mbgl {
|
||||
class TileServerOptions;
|
||||
}
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
class Q_MAPLIBREGL_EXPORT Settings {
|
||||
public:
|
||||
Settings();
|
||||
|
||||
enum GLContextMode {
|
||||
UniqueGLContext = 0,
|
||||
SharedGLContext
|
||||
};
|
||||
|
||||
enum MapMode {
|
||||
Continuous = 0,
|
||||
Static
|
||||
};
|
||||
|
||||
enum ConstrainMode {
|
||||
NoConstrain = 0,
|
||||
ConstrainHeightOnly,
|
||||
ConstrainWidthAndHeight
|
||||
};
|
||||
|
||||
enum ViewportMode {
|
||||
DefaultViewport = 0,
|
||||
FlippedYViewport
|
||||
};
|
||||
|
||||
enum SettingsTemplate {
|
||||
DefaultSettings = 0,
|
||||
MapLibreSettings,
|
||||
MapTilerSettings,
|
||||
MapboxSettings
|
||||
};
|
||||
|
||||
GLContextMode contextMode() const;
|
||||
void setContextMode(GLContextMode);
|
||||
|
||||
MapMode mapMode() const;
|
||||
void setMapMode(MapMode);
|
||||
|
||||
ConstrainMode constrainMode() const;
|
||||
void setConstrainMode(ConstrainMode);
|
||||
|
||||
ViewportMode viewportMode() const;
|
||||
void setViewportMode(ViewportMode);
|
||||
|
||||
unsigned cacheDatabaseMaximumSize() const;
|
||||
void setCacheDatabaseMaximumSize(unsigned);
|
||||
|
||||
QString cacheDatabasePath() const;
|
||||
void setCacheDatabasePath(const QString &);
|
||||
|
||||
QString assetPath() const;
|
||||
void setAssetPath(const QString &);
|
||||
|
||||
QString apiKey() const;
|
||||
void setApiKey(const QString &);
|
||||
|
||||
QString apiBaseUrl() const;
|
||||
void setApiBaseUrl(const QString &);
|
||||
|
||||
QString localFontFamily() const;
|
||||
void setLocalFontFamily(const QString &);
|
||||
|
||||
QString clientName() const;
|
||||
void setClientName(const QString &);
|
||||
|
||||
QString clientVersion() const;
|
||||
void setClientVersion(const QString &);
|
||||
|
||||
std::function<std::string(const std::string &)> resourceTransform() const;
|
||||
void setResourceTransform(const std::function<std::string(const std::string &)> &);
|
||||
|
||||
void resetToTemplate(SettingsTemplate);
|
||||
|
||||
QVector<QPair<QString, QString>> defaultStyles() const;
|
||||
|
||||
mbgl::TileServerOptions *tileServerOptionsInternal() const;
|
||||
|
||||
private:
|
||||
GLContextMode m_contextMode;
|
||||
MapMode m_mapMode;
|
||||
ConstrainMode m_constrainMode;
|
||||
ViewportMode m_viewportMode;
|
||||
|
||||
unsigned m_cacheMaximumSize;
|
||||
QString m_cacheDatabasePath;
|
||||
QString m_assetPath;
|
||||
QString m_apiKey;
|
||||
QString m_localFontFamily;
|
||||
QString m_clientName;
|
||||
QString m_clientVersion;
|
||||
std::function<std::string(const std::string &)> m_resourceTransform;
|
||||
|
||||
mbgl::TileServerOptions *m_tileServerOptionsInternal{};
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
|
||||
#endif // QMAPLIBREGL_SETTINGS_H
|
||||
@@ -1,148 +0,0 @@
|
||||
#ifndef QMAPLIBREGL_TYPES_H
|
||||
#define QMAPLIBREGL_TYPES_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
#include "export.hpp"
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
typedef QPair<double, double> Coordinate;
|
||||
typedef QPair<Coordinate, double> CoordinateZoom;
|
||||
typedef QPair<double, double> ProjectedMeters;
|
||||
|
||||
typedef QVector<Coordinate> Coordinates;
|
||||
typedef QVector<Coordinates> CoordinatesCollection;
|
||||
|
||||
typedef QVector<CoordinatesCollection> CoordinatesCollections;
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT Feature {
|
||||
enum Type {
|
||||
PointType = 1,
|
||||
LineStringType,
|
||||
PolygonType
|
||||
};
|
||||
|
||||
/*! Class constructor. */
|
||||
Feature(Type type_ = PointType,
|
||||
const CoordinatesCollections& geometry_ = CoordinatesCollections(),
|
||||
const QVariantMap& properties_ = QVariantMap(),
|
||||
const QVariant& id_ = QVariant())
|
||||
: type(type_),
|
||||
geometry(geometry_),
|
||||
properties(properties_),
|
||||
id(id_) {}
|
||||
|
||||
Type type;
|
||||
CoordinatesCollections geometry;
|
||||
QVariantMap properties;
|
||||
QVariant id;
|
||||
};
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT ShapeAnnotationGeometry {
|
||||
enum Type {
|
||||
LineStringType = 1,
|
||||
PolygonType,
|
||||
MultiLineStringType,
|
||||
MultiPolygonType
|
||||
};
|
||||
|
||||
/*! Class constructor. */
|
||||
ShapeAnnotationGeometry(Type type_ = LineStringType,
|
||||
const CoordinatesCollections& geometry_ = CoordinatesCollections())
|
||||
: type(type_),
|
||||
geometry(geometry_) {}
|
||||
|
||||
Type type;
|
||||
CoordinatesCollections geometry;
|
||||
};
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT SymbolAnnotation {
|
||||
Coordinate geometry;
|
||||
QString icon;
|
||||
};
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT LineAnnotation {
|
||||
/*! Class constructor. */
|
||||
LineAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(),
|
||||
float opacity_ = 1.0f,
|
||||
float width_ = 1.0f,
|
||||
const QColor& color_ = Qt::black)
|
||||
: geometry(geometry_),
|
||||
opacity(opacity_),
|
||||
width(width_),
|
||||
color(color_) {}
|
||||
|
||||
ShapeAnnotationGeometry geometry;
|
||||
float opacity;
|
||||
float width;
|
||||
QColor color;
|
||||
};
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT FillAnnotation {
|
||||
/*! Class constructor. */
|
||||
FillAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(),
|
||||
float opacity_ = 1.0f,
|
||||
const QColor& color_ = Qt::black,
|
||||
const QVariant& outlineColor_ = QVariant())
|
||||
: geometry(geometry_),
|
||||
opacity(opacity_),
|
||||
color(color_),
|
||||
outlineColor(outlineColor_) {}
|
||||
|
||||
ShapeAnnotationGeometry geometry;
|
||||
float opacity;
|
||||
QColor color;
|
||||
QVariant outlineColor;
|
||||
};
|
||||
|
||||
typedef QVariant Annotation;
|
||||
typedef quint32 AnnotationID;
|
||||
typedef QVector<AnnotationID> AnnotationIDs;
|
||||
|
||||
struct Q_MAPLIBREGL_EXPORT CameraOptions {
|
||||
QVariant center; // Coordinate
|
||||
QVariant anchor; // QPointF
|
||||
QVariant zoom; // double
|
||||
QVariant bearing; // double
|
||||
QVariant pitch; // double
|
||||
};
|
||||
|
||||
// This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters.
|
||||
struct Q_MAPLIBREGL_EXPORT CustomLayerRenderParameters {
|
||||
double width;
|
||||
double height;
|
||||
double latitude;
|
||||
double longitude;
|
||||
double zoom;
|
||||
double bearing;
|
||||
double pitch;
|
||||
double fieldOfView;
|
||||
};
|
||||
|
||||
class Q_MAPLIBREGL_EXPORT CustomLayerHostInterface {
|
||||
public:
|
||||
virtual ~CustomLayerHostInterface() = default;
|
||||
virtual void initialize() = 0;
|
||||
virtual void render(const CustomLayerRenderParameters&) = 0;
|
||||
virtual void deinitialize() = 0;
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::Coordinate);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::Coordinates);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollection);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollections);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::Feature);
|
||||
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::SymbolAnnotation);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::ShapeAnnotationGeometry);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::LineAnnotation);
|
||||
Q_DECLARE_METATYPE(QMapLibreGL::FillAnnotation);
|
||||
|
||||
#endif // QMAPLIBREGL_TYPES_H
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef QMAPLIBREGL_UTILS_H
|
||||
#define QMAPLIBREGL_UTILS_H
|
||||
|
||||
#include "export.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
enum NetworkMode {
|
||||
Online, // Default
|
||||
Offline,
|
||||
};
|
||||
|
||||
Q_MAPLIBREGL_EXPORT NetworkMode networkMode();
|
||||
Q_MAPLIBREGL_EXPORT void setNetworkMode(NetworkMode);
|
||||
|
||||
Q_MAPLIBREGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom);
|
||||
Q_MAPLIBREGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &);
|
||||
Q_MAPLIBREGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &);
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
|
||||
#endif // QMAPLIBREGL_UTILS_H
|
||||
@@ -1,16 +1,7 @@
|
||||
message(STATUS "Configuring GL-Native with Qt bindings")
|
||||
message(STATUS "Configuring MapLibre Native with Qt platform")
|
||||
|
||||
file(READ "${PROJECT_SOURCE_DIR}/platform/qt/VERSION" MLN_QT_VERSION)
|
||||
string(REGEX REPLACE "\n" "" MLN_QT_VERSION "${MLN_QT_VERSION}") # get rid of the newline at the end
|
||||
set(MLN_QT_VERSION_COMPATIBILITY 2.0.0)
|
||||
message(STATUS "Version ${MLN_QT_VERSION}")
|
||||
|
||||
option(MLN_QT_LIBRARY_ONLY "Build only libraries" OFF)
|
||||
option(MLN_QT_STATIC "Build MapLibre Native Qt bindings staticly" OFF)
|
||||
option(MLN_QT_INSIDE_PLUGIN "Build QMapLibreGL as OBJECT library, so it can be bundled into separate single plugin lib." OFF)
|
||||
option(MLN_QT_WITH_HEADLESS "Build MapLibre Native Qt with headless support" ON)
|
||||
option(MLN_QT_LIBRARY_ONLY "Build only MapLibre Native Qt bindings libraries" OFF)
|
||||
option(MLN_QT_WITH_INTERNAL_SQLITE "Build MapLibre Native Qt bindings with internal sqlite" OFF)
|
||||
option(MLN_QT_DEPLOYMENT "Autogenerate files necessary for deployment" OFF)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
find_package(Threads REQUIRED)
|
||||
@@ -46,13 +37,6 @@ find_package(Qt${QT_VERSION_MAJOR}
|
||||
Network
|
||||
REQUIRED)
|
||||
|
||||
if(NOT MLN_QT_LIBRARY_ONLY)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
|
||||
if (Qt6_FOUND)
|
||||
find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MLN_QT_WITH_INTERNAL_SQLITE)
|
||||
find_package(Qt${QT_VERSION_MAJOR}Sql REQUIRED)
|
||||
else()
|
||||
@@ -71,15 +55,6 @@ if (MSVC)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
message(STATUS "Building for ABI: ${ANDROID_ABI}")
|
||||
set(CMAKE_STATIC_LIBRARY_SUFFIX "_${ANDROID_ABI}.a")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
||||
set(CMAKE_DEBUG_POSTFIX "_debug")
|
||||
elseif(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
endif()
|
||||
|
||||
target_sources(
|
||||
mbgl-core
|
||||
PRIVATE
|
||||
@@ -109,10 +84,10 @@ target_sources(
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/filesystem.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/monotonic_timer.cpp
|
||||
$<$<BOOL:${MLN_QT_WITH_HEADLESS}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/headless_backend_qt.cpp>
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task_impl.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/gl_functions.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/headless_backend_qt.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_request.cpp
|
||||
@@ -129,6 +104,11 @@ target_sources(
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer_impl.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/utf.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_observer.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.hpp
|
||||
)
|
||||
|
||||
target_compile_definitions(
|
||||
@@ -142,7 +122,6 @@ target_include_directories(
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/platform/default/include
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/nunicode.cmake)
|
||||
|
||||
set_property(TARGET mbgl-core PROPERTY AUTOMOC ON)
|
||||
@@ -165,221 +144,29 @@ target_link_libraries(
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
)
|
||||
|
||||
# Interface library for object linking
|
||||
add_library(mbgl-core-interface INTERFACE)
|
||||
target_link_libraries(
|
||||
mbgl-core-interface
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:mbgl-core> $<TARGET_OBJECTS:mbgl-core>
|
||||
$<BUILD_INTERFACE:mbgl-vendor-parsedate> $<TARGET_OBJECTS:mbgl-vendor-parsedate>
|
||||
$<BUILD_INTERFACE:mbgl-vendor-nunicode> $<TARGET_OBJECTS:mbgl-vendor-nunicode>
|
||||
$<BUILD_INTERFACE:mbgl-vendor-csscolorparser> $<TARGET_OBJECTS:mbgl-vendor-csscolorparser>
|
||||
$<$<BOOL:${MLN_QT_WITH_INTERNAL_SQLITE}>:$<BUILD_INTERFACE:mbgl-vendor-sqlite>>
|
||||
$<$<BOOL:${MLN_QT_WITH_INTERNAL_SQLITE}>:$<TARGET_OBJECTS:mbgl-vendor-sqlite>>
|
||||
)
|
||||
export(TARGETS mbgl-core-interface FILE MapboxCoreTargets.cmake APPEND)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
if (MLN_QT_WITH_INTERNAL_ICU)
|
||||
target_link_libraries(mbgl-core PUBLIC $<BUILD_INTERFACE:mbgl-vendor-icu>)
|
||||
target_link_libraries(mbgl-core-interface INTERFACE $<BUILD_INTERFACE:mbgl-vendor-icu> $<TARGET_OBJECTS:mbgl-vendor-icu>)
|
||||
else()
|
||||
target_link_libraries(mbgl-core PUBLIC ICU::uc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(qmaplibregl_headers
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/QMapLibreGL
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/export.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/map.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Map
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/settings.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Settings
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/types.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Types
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/utils.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Utils
|
||||
)
|
||||
|
||||
if (MLN_QT_INSIDE_PLUGIN)
|
||||
add_library(qmaplibregl OBJECT)
|
||||
elseif(MLN_QT_STATIC)
|
||||
add_library(qmaplibregl STATIC)
|
||||
else()
|
||||
add_library(qmaplibregl SHARED)
|
||||
endif()
|
||||
|
||||
target_sources(
|
||||
qmaplibregl
|
||||
PRIVATE
|
||||
${qmaplibregl_headers}
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/map.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/map_p.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/settings.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/types.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_observer.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/conversion.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.hpp
|
||||
)
|
||||
|
||||
# Linux/Mac: Set framework, version and headers
|
||||
set_target_properties(
|
||||
qmaplibregl PROPERTIES
|
||||
AUTOMOC ON
|
||||
EXPORT_NAME QMapLibreGL
|
||||
OUTPUT_NAME QMapLibreGL
|
||||
VERSION ${MLN_QT_VERSION}
|
||||
SOVERSION ${MLN_QT_VERSION_COMPATIBILITY}
|
||||
PUBLIC_HEADER "${qmaplibregl_headers}"
|
||||
)
|
||||
if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
|
||||
qt_enable_autogen_tool(qmaplibregl "moc" ON)
|
||||
endif()
|
||||
if (APPLE AND NOT MLN_QT_STATIC AND NOT MLN_QT_INSIDE_PLUGIN)
|
||||
set_target_properties(
|
||||
qmaplibregl PROPERTIES
|
||||
FRAMEWORK ON
|
||||
FRAMEWORK_VERSION A
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.QMapLibreGL
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION}
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION}
|
||||
)
|
||||
target_include_directories(
|
||||
qmaplibregl
|
||||
INTERFACE
|
||||
$<INSTALL_INTERFACE:lib/QMapLibreGL.framework>
|
||||
# Object library list
|
||||
get_directory_property(MLN_QT_HAS_PARENT PARENT_DIRECTORY)
|
||||
if(MLN_QT_HAS_PARENT)
|
||||
set(MLN_QT_VENDOR_LIBRARIES
|
||||
mbgl-vendor-parsedate
|
||||
mbgl-vendor-nunicode
|
||||
mbgl-vendor-csscolorparser
|
||||
$<$<BOOL:${MLN_QT_WITH_INTERNAL_SQLITE}>:$<BUILD_INTERFACE:mbgl-vendor-sqlite>>
|
||||
$<$<AND:$<PLATFORM_ID:Linux>,$<BOOL:${MLN_QT_WITH_INTERNAL_ICU}>>:$<BUILD_INTERFACE:mbgl-vendor-icu>>
|
||||
PARENT_SCOPE
|
||||
)
|
||||
endif()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapLibreGL/)
|
||||
|
||||
configure_package_config_file(
|
||||
"platform/qt/QMapLibreGLConfig.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
|
||||
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
|
||||
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||
|
||||
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake
|
||||
VERSION ${MLN_QT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
|
||||
install(EXPORT QMapLibreGLTargets
|
||||
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
|
||||
COMPONENT development)
|
||||
|
||||
export(EXPORT QMapLibreGLTargets)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake"
|
||||
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
|
||||
COMPONENT development)
|
||||
|
||||
install(
|
||||
DIRECTORY include/mbgl
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
COMPONENT development
|
||||
)
|
||||
|
||||
if(MLN_QT_DEPLOYMENT)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/LICENSE.md
|
||||
DESTINATION .)
|
||||
endif()
|
||||
|
||||
# FIXME: Because of rapidjson conversion
|
||||
target_include_directories(
|
||||
qmaplibregl
|
||||
PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/include
|
||||
)
|
||||
|
||||
target_compile_definitions(
|
||||
qmaplibregl
|
||||
PRIVATE
|
||||
QT_BUILD_MAPLIBREGL_LIB
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
qmaplibregl
|
||||
PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:mbgl-compiler-options>
|
||||
$<BUILD_INTERFACE:mbgl-core-interface>
|
||||
)
|
||||
|
||||
if (MLN_QT_STATIC OR MLN_QT_INSIDE_PLUGIN)
|
||||
# Don't add import/export into public header because we don't build shared library.
|
||||
# In case on MLN_QT_INSIDE_PLUGIN it's always OBJECT library and bundled into one
|
||||
# single Qt plugin lib.
|
||||
target_compile_definitions(
|
||||
qmaplibregl
|
||||
PUBLIC QT_MAPLIBREGL_STATIC
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
install(TARGETS qmaplibregl
|
||||
EXPORT QMapLibreGLTargets
|
||||
# Explicit set of DESTINATION is needed for older CMake versions.
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/QMapLibreGL"
|
||||
)
|
||||
|
||||
if(NOT MLN_QT_LIBRARY_ONLY)
|
||||
set(mbglqt_sources
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/app/main.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/app/mapwindow.cpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/app/mapwindow.hpp
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/resources/common.qrc
|
||||
)
|
||||
if (COMMAND qt_add_executable)
|
||||
qt_add_executable(mbgl-qt ${mbglqt_sources})
|
||||
else()
|
||||
add_executable(mbgl-qt ${mbglqt_sources})
|
||||
endif()
|
||||
|
||||
# Qt public API should keep compatibility with old compilers for legacy systems
|
||||
set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98)
|
||||
set_property(TARGET mbgl-qt PROPERTY AUTOMOC ON)
|
||||
|
||||
target_link_libraries(
|
||||
mbgl-qt
|
||||
PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
$<$<BOOL:${Qt6_FOUND}>:Qt${QT_VERSION_MAJOR}::OpenGLWidgets>
|
||||
mbgl-compiler-options
|
||||
qmaplibregl
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
mbgl-qt
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/platform/qt/include
|
||||
)
|
||||
endif()
|
||||
|
||||
# tests
|
||||
if(NOT MLN_QT_LIBRARY_ONLY AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
# test runner
|
||||
add_executable(
|
||||
mbgl-test-runner
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/test/main.cpp
|
||||
@@ -418,18 +205,3 @@ if(NOT MLN_QT_LIBRARY_ONLY AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
|
||||
add_test(NAME mbgl-test-runner COMMAND mbgl-test-runner WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
find_program(MLN_QDOC NAMES qdoc)
|
||||
|
||||
if(MLN_QDOC)
|
||||
add_custom_target(mbgl-qt-docs)
|
||||
|
||||
add_custom_command(
|
||||
TARGET mbgl-qt-docs PRE_BUILD
|
||||
COMMAND
|
||||
${MLN_QDOC}
|
||||
${PROJECT_SOURCE_DIR}/platform/qt/config.qdocconf
|
||||
-outputdir
|
||||
${CMAKE_BINARY_DIR}/docs
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="icon.png">../../../misc/mb-icon-blue-square.png</file>
|
||||
<file alias="default_marker.svg">../../../platform/default/resources/default_marker.svg</file>
|
||||
<file>source1.geojson</file>
|
||||
<file>source2.geojson</file>
|
||||
<file>label-arrow.svg</file>
|
||||
<file>label-background.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="40"
|
||||
height="40"
|
||||
id="svg3840"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="New document 3">
|
||||
<defs
|
||||
id="defs3842" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="3.8146973"
|
||||
inkscape:cx="26.909082"
|
||||
inkscape:cy="41.484288"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false" />
|
||||
<metadata
|
||||
id="metadata3845">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1012.3622)">
|
||||
<g
|
||||
id="g3811"
|
||||
transform="translate(0,1012.3622)">
|
||||
<g
|
||||
id="g3802">
|
||||
<g
|
||||
id="g3794">
|
||||
<g
|
||||
transform="translate(0,-1012.3622)"
|
||||
id="layer1-7">
|
||||
<g
|
||||
style="stroke-width:0;stroke-miterlimit:4"
|
||||
stroke-miterlimit="4"
|
||||
id="g3763">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path2987"
|
||||
transform="translate(0,1012.3622)"
|
||||
d="M 5,0 18.03125,30.40625 A 5,5 0 0 0 15,35 5,5 0 0 0 25,35 5,5 0 0 0 21.96875,30.40625 L 35,0 5,0 z"
|
||||
style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;enable-background:accumulate" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
transform="matrix(0.39999698,0,0,0.39999698,12.00006,1033.3623)"
|
||||
d="m 25,35 a 5,5 0 1 1 -10,0 5,5 0 1 1 10,0 z"
|
||||
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;enable-background:accumulate"
|
||||
id="path3759" />
|
||||
<rect
|
||||
x="0"
|
||||
y="0"
|
||||
width="40"
|
||||
height="40"
|
||||
transform="translate(0,1012.3622)"
|
||||
style="color:#000000;fill-opacity:0;enable-background:accumulate"
|
||||
id="rect3761" />
|
||||
</g>
|
||||
</g>
|
||||
<rect
|
||||
y="0"
|
||||
x="0"
|
||||
height="40"
|
||||
width="40"
|
||||
id="rect3792"
|
||||
style="color:#000000;fill:#000000;fill-opacity:0;fill-rule:nonzero;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.2 KiB |
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg id="svg3926" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="40" width="120" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<defs id="defs3928">
|
||||
<linearGradient id="linearGradient3793" y2="5" gradientUnits="userSpaceOnUse" x2="40" y1="30" x1="40">
|
||||
<stop id="stop3789" stop-color="#000" offset="0"/>
|
||||
<stop id="stop3791" stop-color="#000" stop-opacity="0.50196081" offset="1"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<metadata id="metadata3931">
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g id="layer1" transform="translate(0,-1012.3622)">
|
||||
<g id="g3788" transform="translate(-40,1012.3622)">
|
||||
<rect id="rect2991" style="enable-background:accumulate;color:#000000;" fill-rule="nonzero" ry="3" height="30" width="120" y="5" x="40" fill="url(#linearGradient3793)"/>
|
||||
<rect id="rect3018" style="enable-background:accumulate;color:#000000;" fill-opacity="0" height="40" width="120" y="0" x="40"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
File diff suppressed because it is too large
Load Diff
@@ -1,92 +0,0 @@
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"type": "label",
|
||||
"name": "Start"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [
|
||||
24.943320751190186,
|
||||
60.166471893909794
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"type": "label",
|
||||
"name": "End"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [
|
||||
24.942440986633297,
|
||||
60.16715507391703
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"type": "label",
|
||||
"name": "Traffic Accident"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [
|
||||
24.94018793106079,
|
||||
60.16696293097573
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
24.943320751190186,
|
||||
60.166471893909794
|
||||
],
|
||||
[
|
||||
24.934544563293453,
|
||||
60.16347213858629
|
||||
],
|
||||
[
|
||||
24.93321418762207,
|
||||
60.16446497048834
|
||||
],
|
||||
[
|
||||
24.94018793106079,
|
||||
60.16696293097573
|
||||
],
|
||||
[
|
||||
24.93875026702881,
|
||||
60.16806240040351
|
||||
],
|
||||
[
|
||||
24.937891960144043,
|
||||
60.16777419352904
|
||||
],
|
||||
[
|
||||
24.936089515686035,
|
||||
60.169033745694826
|
||||
],
|
||||
[
|
||||
24.9384069442749,
|
||||
60.16984495711831
|
||||
],
|
||||
[
|
||||
24.942440986633297,
|
||||
60.16715507391703
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -z ${3+x} ]]; then
|
||||
echo "Error: Pass Qt installation path as the third argument" 1>&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [[ -z ${4+x} ]]; then
|
||||
echo "Error: Pass Android ABI as the fourth argument" 1>&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
cmake "$1" \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" \
|
||||
-DANDROID_ABI="$4" \
|
||||
-DANDROID_NATIVE_API_LEVEL=21 \
|
||||
-G Ninja \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_STATIC=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON \
|
||||
-DCMAKE_CXX_FLAGS_RELEASE=-g0 \
|
||||
-DCMAKE_INSTALL_PREFIX="$2" \
|
||||
-DCMAKE_FIND_ROOT_PATH="$3/android" \
|
||||
-DCMAKE_PREFIX_PATH="$3/android"
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cmake "$1" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2"
|
||||
@@ -1,8 +0,0 @@
|
||||
$path = $args[0]
|
||||
$install = $args[1]
|
||||
|
||||
cmake -S "$path" `
|
||||
-GNinja `
|
||||
-DCMAKE_BUILD_TYPE="Release" `
|
||||
-DCMAKE_INSTALL_PREFIX="$install" `
|
||||
-DMLN_WITH_QT=ON
|
||||
@@ -1,10 +0,0 @@
|
||||
$path = $args[0]
|
||||
$install = $args[1]
|
||||
|
||||
cmake -S "$path" `
|
||||
-GNinja `
|
||||
-DCMAKE_BUILD_TYPE="Release" `
|
||||
-DCMAKE_INSTALL_PREFIX="$install" `
|
||||
-DMLN_WITH_QT=ON `
|
||||
-DMLN_QT_STATIC=ON `
|
||||
-DMLN_QT_LIBRARY_ONLY=ON
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -z ${3+x} ]]; then
|
||||
echo "Error: Pass Qt installation path as the third argument" 1>&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
cmake "$1" \
|
||||
-G"Ninja Multi-Config" \
|
||||
-DCMAKE_SYSTEM_NAME="iOS" \
|
||||
-DCMAKE_CONFIGURATION_TYPES="Release;Debug" \
|
||||
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="12.0" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_STATIC=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2" \
|
||||
-DCMAKE_FIND_ROOT_PATH="$3/ios" \
|
||||
-DCMAKE_PREFIX_PATH="$3/ios"
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cmake "$1" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="10.13" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2"
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cmake "$1" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="10.13" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_STATIC=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2"
|
||||
@@ -1,8 +0,0 @@
|
||||
$path = $args[0]
|
||||
$install = $args[1]
|
||||
|
||||
qt-cmake -S "$path" `
|
||||
-GNinja `
|
||||
-DCMAKE_BUILD_TYPE="Release" `
|
||||
-DCMAKE_INSTALL_PREFIX="$install" `
|
||||
-DMLN_WITH_QT=ON
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
qt-cmake "$1" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" \
|
||||
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2"
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z ${1+x} ]]; then
|
||||
echo "Error: Pass the path to maplibre-native as first argument" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z ${2+x} ]]; then
|
||||
echo "Error: Pass the install prefix as the second argument" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
qt-cmake "$1" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" \
|
||||
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_STATIC=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$2"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/Map>
|
||||
|
||||
#include "utils/map_observer.hpp"
|
||||
#include "utils/map_renderer.hpp"
|
||||
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/renderer/renderer_frontend.hpp>
|
||||
#include <mbgl/storage/resource_transform.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSize>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
class MapPrivate : public QObject, public mbgl::RendererFrontend {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapPrivate(Map*, const Settings&, const QSize& size, qreal pixelRatio);
|
||||
virtual ~MapPrivate();
|
||||
|
||||
// mbgl::RendererFrontend implementation.
|
||||
void reset() final {}
|
||||
void setObserver(mbgl::RendererObserver&) final;
|
||||
void update(std::shared_ptr<mbgl::UpdateParameters>) final;
|
||||
|
||||
// These need to be called on the same thread.
|
||||
void createRenderer();
|
||||
void destroyRenderer();
|
||||
void render();
|
||||
void setFramebufferObject(quint32 fbo, const QSize& size);
|
||||
|
||||
using PropertySetter = std::optional<mbgl::style::conversion::Error> (mbgl::style::Layer::*)(
|
||||
const std::string&, const mbgl::style::conversion::Convertible&);
|
||||
bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value);
|
||||
|
||||
mbgl::EdgeInsets margins;
|
||||
std::unique_ptr<mbgl::Map> mapObj{};
|
||||
QVector<QPair<QString, QString>> defaultStyles;
|
||||
|
||||
public slots:
|
||||
void requestRendering();
|
||||
|
||||
signals:
|
||||
void needsRendering();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(MapPrivate)
|
||||
|
||||
std::recursive_mutex m_mapRendererMutex;
|
||||
std::shared_ptr<mbgl::RendererObserver> m_rendererObserver{};
|
||||
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters{};
|
||||
|
||||
std::unique_ptr<MapObserver> m_mapObserver{};
|
||||
std::unique_ptr<MapRenderer> m_mapRenderer{};
|
||||
std::unique_ptr<mbgl::Actor<mbgl::ResourceTransform::TransformCallback>> m_resourceTransform{};
|
||||
|
||||
Settings::GLContextMode m_mode;
|
||||
qreal m_pixelRatio;
|
||||
|
||||
QString m_localFontFamily;
|
||||
|
||||
std::atomic_flag m_renderQueued = ATOMIC_FLAG_INIT;
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,437 +0,0 @@
|
||||
#include <QMapLibreGL/Settings>
|
||||
|
||||
#include <mbgl/gfx/renderer_backend.hpp>
|
||||
#include <mbgl/map/mode.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/tile_server_options.hpp>
|
||||
#include <mbgl/util/traits.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4805)
|
||||
#endif
|
||||
|
||||
// mbgl::GLContextMode
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::UniqueGLContext) ==
|
||||
mbgl::underlying_type(mbgl::gfx::ContextMode::Unique),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::SharedGLContext) ==
|
||||
mbgl::underlying_type(mbgl::gfx::ContextMode::Shared),
|
||||
"error");
|
||||
|
||||
// mbgl::MapMode
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Continuous) ==
|
||||
mbgl::underlying_type(mbgl::MapMode::Continuous),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Static) == mbgl::underlying_type(mbgl::MapMode::Static),
|
||||
"error");
|
||||
|
||||
// mbgl::ConstrainMode
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::NoConstrain) ==
|
||||
mbgl::underlying_type(mbgl::ConstrainMode::None),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainHeightOnly) ==
|
||||
mbgl::underlying_type(mbgl::ConstrainMode::HeightOnly),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainWidthAndHeight) ==
|
||||
mbgl::underlying_type(mbgl::ConstrainMode::WidthAndHeight),
|
||||
"error");
|
||||
|
||||
// mbgl::ViewportMode
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::DefaultViewport) ==
|
||||
mbgl::underlying_type(mbgl::ViewportMode::Default),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::FlippedYViewport) ==
|
||||
mbgl::underlying_type(mbgl::ViewportMode::FlippedY),
|
||||
"error");
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::Settings
|
||||
\brief The Settings class stores the initial configuration for
|
||||
QMapLibreGL::Map.
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Settings is used to configure QMapLibreGL::Map at the moment of its
|
||||
creation. Once created, the Settings of a QMapLibreGL::Map can no longer be
|
||||
changed.
|
||||
|
||||
Cache-related settings are shared between all QMapLibreGL::Map instances
|
||||
using the same cache path. The first map to configure cache properties such
|
||||
as size will force the configuration to all newly instantiated
|
||||
QMapLibreGL::Map objects using the same cache in the same process.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::Settings::GLContextMode
|
||||
|
||||
This enum sets the expectations for the OpenGL state.
|
||||
|
||||
\value UniqueGLContext The OpenGL context is only used by QMapLibreGL::Map,
|
||||
so it is not reset before each rendering. Use this mode if the intention is
|
||||
to only draw a fullscreen map.
|
||||
|
||||
\value SharedGLContext The OpenGL context is shared and the state will be
|
||||
marked dirty - which invalidates any previously assumed GL state. The
|
||||
embedder is responsible for clearing up the viewport prior to calling
|
||||
QMapLibreGL::Map::render. The embedder is also responsible for resetting its
|
||||
own GL state after QMapLibreGL::Map::render has finished, if needed.
|
||||
|
||||
\sa contextMode()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::Settings::MapMode
|
||||
|
||||
This enum sets the map rendering mode
|
||||
|
||||
\value Continuous The map will render as data arrives from the network and
|
||||
react immediately to state changes.
|
||||
|
||||
This is the default mode and the preferred when the map is intended to be
|
||||
interactive.
|
||||
|
||||
\value Static The map will no longer react to state changes and will only
|
||||
be rendered when QMapLibreGL::Map::startStaticRender is called. After all the
|
||||
resources are loaded, the QMapLibreGL::Map::staticRenderFinished signal is emitted.
|
||||
|
||||
This mode is useful for taking a snapshot of the finished rendering result
|
||||
of the map into a QImage.
|
||||
|
||||
\sa mapMode()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::Settings::ConstrainMode
|
||||
|
||||
This enum determines if the map wraps.
|
||||
|
||||
\value NoConstrain The map will wrap on the horizontal axis.
|
||||
Since it doesn't make sense to wrap on the vertical axis in a Web Mercator
|
||||
projection, the map will scroll and show some empty space.
|
||||
|
||||
\value ConstrainHeightOnly The map will wrap around the horizontal
|
||||
axis, like a spinning globe. This is the recommended constrain mode.
|
||||
|
||||
\value ConstrainWidthAndHeight The map won't wrap and panning is restricted
|
||||
to the boundaries of the map.
|
||||
|
||||
\sa constrainMode()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::Settings::ViewportMode
|
||||
|
||||
This enum flips the map vertically.
|
||||
|
||||
\value DefaultViewport Native orientation.
|
||||
|
||||
\value FlippedYViewport Mirrored vertically.
|
||||
|
||||
\sa viewportMode()
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructs a Settings object with the default values. The default
|
||||
configuration is valid for initializing a QMapLibreGL::Map.
|
||||
*/
|
||||
Settings::Settings()
|
||||
: m_contextMode(Settings::SharedGLContext),
|
||||
m_mapMode(Settings::Continuous),
|
||||
m_constrainMode(Settings::ConstrainHeightOnly),
|
||||
m_viewportMode(Settings::DefaultViewport),
|
||||
m_cacheMaximumSize(mbgl::util::DEFAULT_MAX_CACHE_SIZE),
|
||||
m_cacheDatabasePath(":memory:"),
|
||||
m_assetPath(QCoreApplication::applicationDirPath()),
|
||||
m_apiKey(qgetenv("MLN_API_KEY")),
|
||||
m_tileServerOptionsInternal(new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration())) {}
|
||||
|
||||
/*!
|
||||
Returns the OpenGL context mode. This is specially important when mixing
|
||||
with other OpenGL draw calls.
|
||||
|
||||
By default, it is set to Settings::SharedGLContext.
|
||||
*/
|
||||
Settings::GLContextMode Settings::contextMode() const {
|
||||
return m_contextMode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the OpenGL context \a mode.
|
||||
*/
|
||||
void Settings::setContextMode(GLContextMode mode) {
|
||||
m_contextMode = mode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the map mode. Static mode will emit a signal for
|
||||
rendering a map only when the map is fully loaded.
|
||||
Animations like style transitions and labels fading won't
|
||||
be seen.
|
||||
|
||||
The Continuous mode will emit the signal for every new
|
||||
change on the map and it is usually what you expect for
|
||||
a interactive map.
|
||||
|
||||
By default, it is set to QMapLibreGL::Settings::Continuous.
|
||||
*/
|
||||
Settings::MapMode Settings::mapMode() const {
|
||||
return m_mapMode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the map \a mode.
|
||||
*/
|
||||
void Settings::setMapMode(MapMode mode) {
|
||||
m_mapMode = mode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the constrain mode. This is used to limit the map to wrap
|
||||
around the globe horizontally.
|
||||
|
||||
By default, it is set to QMapLibreGL::Settings::ConstrainHeightOnly.
|
||||
*/
|
||||
Settings::ConstrainMode Settings::constrainMode() const {
|
||||
return m_constrainMode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the map constrain \a mode.
|
||||
*/
|
||||
void Settings::setConstrainMode(ConstrainMode mode) {
|
||||
m_constrainMode = mode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the viewport mode. This is used to flip the vertical
|
||||
orientation of the map as some devices may use inverted orientation.
|
||||
|
||||
By default, it is set to QMapLibreGL::Settings::DefaultViewport.
|
||||
*/
|
||||
Settings::ViewportMode Settings::viewportMode() const {
|
||||
return m_viewportMode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the viewport \a mode.
|
||||
*/
|
||||
void Settings::setViewportMode(ViewportMode mode) {
|
||||
m_viewportMode = mode;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the cache database maximum hard size in bytes. The database
|
||||
will grow until the limit is reached. Setting a maximum size smaller
|
||||
than the current size of an existing database results in undefined
|
||||
behavior
|
||||
|
||||
By default, it is set to 50 MB.
|
||||
*/
|
||||
unsigned Settings::cacheDatabaseMaximumSize() const {
|
||||
return m_cacheMaximumSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the maximum allowed cache database \a size in bytes.
|
||||
*/
|
||||
void Settings::setCacheDatabaseMaximumSize(unsigned size) {
|
||||
m_cacheMaximumSize = size;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the cache database path. The cache is used for storing
|
||||
recently used resources like tiles and also an offline tile database
|
||||
pre-populated by the
|
||||
\l {https://github.com/mapbox/mapbox-gl-native/blob/master/bin/offline.sh}
|
||||
{Offline Tool}.
|
||||
|
||||
By default, it is set to \c :memory: meaning it will create an in-memory
|
||||
cache instead of a file on disk.
|
||||
*/
|
||||
QString Settings::cacheDatabasePath() const {
|
||||
return m_cacheDatabasePath;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the cache database \a path.
|
||||
|
||||
Setting the \a path to \c :memory: will create an in-memory cache.
|
||||
*/
|
||||
void Settings::setCacheDatabasePath(const QString &path) {
|
||||
m_cacheDatabasePath = path;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the asset path, which is the root directory from where
|
||||
the \c asset:// scheme gets resolved in a style. \c asset:// can be used
|
||||
for loading a resource from the disk in a style rather than fetching
|
||||
it from the network.
|
||||
|
||||
By default, it is set to the value returned by QCoreApplication::applicationDirPath().
|
||||
*/
|
||||
QString Settings::assetPath() const {
|
||||
return m_assetPath;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the asset \a path.
|
||||
*/
|
||||
void Settings::setAssetPath(const QString &path) {
|
||||
m_assetPath = path;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the API key.
|
||||
|
||||
By default, it is taken from the environment variable \c MLN_API_KEY
|
||||
or empty if the variable is not set.
|
||||
*/
|
||||
QString Settings::apiKey() const {
|
||||
return m_apiKey;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the API key.
|
||||
|
||||
MapTiler-hosted and Mapbox-hosted vector tiles and styles require an API
|
||||
key or access token.
|
||||
*/
|
||||
void Settings::setApiKey(const QString &key) {
|
||||
m_apiKey = key;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the API base URL.
|
||||
*/
|
||||
QString Settings::apiBaseUrl() const {
|
||||
return QString::fromStdString(m_tileServerOptionsInternal->baseURL());
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the API base \a url.
|
||||
|
||||
The API base URL is the URL that the \b "mapbox://" protocol will
|
||||
be resolved to. It defaults to "https://api.mapbox.com" but can be
|
||||
changed, for instance, to a tile cache server address.
|
||||
*/
|
||||
void Settings::setApiBaseUrl(const QString &url) {
|
||||
m_tileServerOptionsInternal = &m_tileServerOptionsInternal->withBaseURL(url.toStdString());
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the local font family. Returns an empty string if no local font family is set.
|
||||
*/
|
||||
QString Settings::localFontFamily() const {
|
||||
return m_localFontFamily;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the local font family.
|
||||
|
||||
Rendering Chinese/Japanese/Korean (CJK) ideographs and precomposed Hangul
|
||||
Syllables requires downloading large amounts of font data, which can
|
||||
significantly slow map load times. Use the localIdeographFontFamily setting
|
||||
to speed up map load times by using locally available fonts instead of font
|
||||
data fetched from the server.
|
||||
*/
|
||||
void Settings::setLocalFontFamily(const QString &family) {
|
||||
m_localFontFamily = family;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the client name. Returns an empty string if no client name is set.
|
||||
*/
|
||||
QString Settings::clientName() const {
|
||||
return m_clientName;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the client name.
|
||||
*/
|
||||
void Settings::setClientName(const QString &name) {
|
||||
m_clientName = name;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the client version. Returns an empty string if no client version is set.
|
||||
*/
|
||||
QString Settings::clientVersion() const {
|
||||
return m_clientVersion;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the client version.
|
||||
*/
|
||||
void Settings::setClientVersion(const QString &version) {
|
||||
m_clientVersion = version;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns resource transformation callback used to transform requested URLs.
|
||||
*/
|
||||
std::function<std::string(const std::string &)> Settings::resourceTransform() const {
|
||||
return m_resourceTransform;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the resource \a transform callback.
|
||||
|
||||
When given, resource transformation callback will be used to transform the
|
||||
requested resource URLs before they are requested from internet. This can be
|
||||
used add or remove custom parameters, or reroute certain requests to other
|
||||
servers or endpoints.
|
||||
*/
|
||||
void Settings::setResourceTransform(const std::function<std::string(const std::string &)> &transform) {
|
||||
m_resourceTransform = transform;
|
||||
}
|
||||
|
||||
/*!
|
||||
Reset all settings based on the given template.
|
||||
|
||||
MapLibre can support servers with different resource path structure.
|
||||
Some of the most common servers like Maptiler and Mapbox are defined
|
||||
in the library. This function will re-initialise all settings based
|
||||
on the default values of specific service provider defaults.
|
||||
*/
|
||||
void Settings::resetToTemplate(SettingsTemplate settings_template) {
|
||||
if (m_tileServerOptionsInternal) delete m_tileServerOptionsInternal;
|
||||
|
||||
if (settings_template == MapLibreSettings) {
|
||||
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapLibreConfiguration());
|
||||
} else if (settings_template == MapTilerSettings) {
|
||||
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapTilerConfiguration());
|
||||
} else if (settings_template == MapboxSettings) {
|
||||
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapboxConfiguration());
|
||||
} else {
|
||||
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
All predefined styles.
|
||||
|
||||
Return all styles that are defined in default settings.
|
||||
*/
|
||||
QVector<QPair<QString, QString>> Settings::defaultStyles() const {
|
||||
QVector<QPair<QString, QString>> styles;
|
||||
for (const auto &style : tileServerOptionsInternal()->defaultStyles()) {
|
||||
styles.append(
|
||||
QPair<QString, QString>(QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName())));
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
|
||||
mbgl::TileServerOptions *Settings::tileServerOptionsInternal() const {
|
||||
return m_tileServerOptionsInternal;
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,182 +0,0 @@
|
||||
#include <QMapLibreGL/Types>
|
||||
|
||||
#include "mbgl/util/geometry.hpp"
|
||||
#include "mbgl/util/traits.hpp"
|
||||
|
||||
// mbgl::FeatureType
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::LineStringType) ==
|
||||
mbgl::underlying_type(mbgl::FeatureType::LineString),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PolygonType) ==
|
||||
mbgl::underlying_type(mbgl::FeatureType::Polygon),
|
||||
"error");
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
/*!
|
||||
\namespace QMapLibreGL
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Contains miscellaneous MapLibre types and utilities used throughout QMapLibreGLGL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::Coordinate
|
||||
|
||||
Alias for QPair<double, double>.
|
||||
Representation for geographical coordinates - latitude and longitude, respectively.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::CoordinateZoom
|
||||
|
||||
Alias for QPair<Coordinate, double>.
|
||||
Used as return value in QMapLibreGLGL::coordinateZoomForBounds.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::ProjectedMeters
|
||||
|
||||
Alias for QPair<double, double>.
|
||||
Representation for projected meters - northing and easting, respectively.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::Coordinates
|
||||
|
||||
Alias for QVector<QMapLibreGL::Coordinate>.
|
||||
A list of QMapLibreGL::Coordinate objects.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::CoordinatesCollection
|
||||
|
||||
Alias for QVector<QMapLibreGL::Coordinates>.
|
||||
A list of QMapLibreGL::Coordinates objects.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::CoordinatesCollections
|
||||
|
||||
Alias for QVector<QMapLibreGL::CoordinatesCollection>.
|
||||
A list of QMapLibreGL::CoordinatesCollection objects.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::Feature
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Represents \l {https://www.mapbox.com/help/define-features/}{map features}
|
||||
via its \a type (PointType, LineStringType or PolygonType), \a geometry, \a
|
||||
properties map and \a id (optional).
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::Feature::Type
|
||||
|
||||
This enum is used as basis for geometry disambiguation in
|
||||
QMapLibreGL::Feature.
|
||||
|
||||
\value PointType A point geometry type. Means a single or a collection
|
||||
of points. \value LineStringType A line string geometry type. Means a single
|
||||
or a collection of line strings. \value PolygonType A polygon geometry
|
||||
type. Means a single or a collection of polygons.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::ShapeAnnotationGeometry
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Represents a shape annotation geometry.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::ShapeAnnotationGeometry::Type
|
||||
|
||||
This enum is used as basis for shape annotation geometry disambiguation.
|
||||
|
||||
\value PolygonType A polygon geometry type.
|
||||
\value LineStringType A line string geometry type.
|
||||
\value MultiPolygonType A polygon geometry collection type.
|
||||
\value MultiLineStringType A line string geometry collection type.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::SymbolAnnotation
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
A symbol annotation comprises of its geometry and an icon identifier.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::LineAnnotation
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Represents a line annotation object, along with its properties.
|
||||
|
||||
A line annotation comprises of its geometry and line properties such as
|
||||
opacity, width and color.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::FillAnnotation
|
||||
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
Represents a fill annotation object, along with its properties.
|
||||
|
||||
A fill annotation comprises of its geometry and fill properties such as
|
||||
opacity, color and outline color.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::Annotation
|
||||
|
||||
Alias for QVariant.
|
||||
Container that encapsulates either a symbol, a line, a fill or a style
|
||||
sourced annotation.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::AnnotationID
|
||||
|
||||
Alias for quint32 representing an annotation identifier.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QMapLibreGL::AnnotationIDs
|
||||
|
||||
Alias for QVector<quint32> representing a container of annotation identifiers.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::CameraOptions
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
QMapLibreGL::CameraOptions provides camera options to the renderer.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::CustomLayerHostInterface
|
||||
|
||||
Represents a host interface to be implemented for rendering custom layers.
|
||||
|
||||
\warning This is used for delegating the rendering of a layer to the user of
|
||||
this API and is not officially supported. Use at your own risk.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QMapLibreGL::CustomLayerRenderParameters
|
||||
\inmodule MapLibre Maps SDK for Qt
|
||||
|
||||
QMapLibreGL::CustomLayerRenderParameters provides the data passed on each
|
||||
render pass for a custom layer.
|
||||
*/
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,74 +0,0 @@
|
||||
#include <QMapLibreGL/Utils>
|
||||
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/traits.hpp>
|
||||
#include <mbgl/util/projection.hpp>
|
||||
|
||||
#include <QOpenGLContext>
|
||||
|
||||
// mbgl::NetworkStatus::Status
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online),
|
||||
"error");
|
||||
static_assert(mbgl::underlying_type(QMapLibreGL::Offline) ==
|
||||
mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline),
|
||||
"error");
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
/*!
|
||||
\enum QMapLibreGL::NetworkMode
|
||||
|
||||
This enum represents whether server requests can be performed via network.
|
||||
|
||||
\value Online Server network requests are accessible.
|
||||
\value Offline Only requests to the local cache are accessible.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMapLibreGL::NetworkMode QMapLibreGL::networkMode()
|
||||
|
||||
Returns the current QMapLibreGL::NetworkMode.
|
||||
*/
|
||||
NetworkMode networkMode() {
|
||||
return static_cast<NetworkMode>(mbgl::NetworkStatus::Get());
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void QMapLibreGL::setNetworkMode(QMapLibreGL::NetworkMode mode)
|
||||
|
||||
Forwards the network status \a mode to MapLibre Native engine.
|
||||
|
||||
File source requests uses the available network when \a mode is set to \b
|
||||
Online, otherwise scoped to the local cache.
|
||||
*/
|
||||
void setNetworkMode(NetworkMode mode) {
|
||||
mbgl::NetworkStatus::Set(static_cast<mbgl::NetworkStatus::Status>(mode));
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the amount of meters per pixel from a given \a latitude and \a zoom.
|
||||
*/
|
||||
double metersPerPixelAtLatitude(double latitude, double zoom) {
|
||||
return mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoom);
|
||||
}
|
||||
|
||||
/*!
|
||||
Return the projected meters for a given \a coordinate object.
|
||||
*/
|
||||
ProjectedMeters projectedMetersForCoordinate(const Coordinate &coordinate) {
|
||||
auto projectedMeters = mbgl::Projection::projectedMetersForLatLng(
|
||||
mbgl::LatLng{coordinate.first, coordinate.second});
|
||||
return ProjectedMeters(projectedMeters.northing(), projectedMeters.easting());
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the coordinate for a given \a projectedMeters object.
|
||||
*/
|
||||
Coordinate coordinateForProjectedMeters(const ProjectedMeters &projectedMeters) {
|
||||
auto latLng = mbgl::Projection::latLngForProjectedMeters(
|
||||
mbgl::ProjectedMeters{projectedMeters.first, projectedMeters.second});
|
||||
return Coordinate(latLng.latitude(), latLng.longitude());
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,213 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/Types>
|
||||
|
||||
#include "geojson.hpp"
|
||||
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
|
||||
#include <QColor>
|
||||
#include <QVariant>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
std::string convertColor(const QColor& color);
|
||||
|
||||
template <>
|
||||
class ConversionTraits<QVariant> {
|
||||
public:
|
||||
static bool isUndefined(const QVariant& value) { return value.isNull() || !value.isValid(); }
|
||||
|
||||
static bool isArray(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantList));
|
||||
#else
|
||||
return value.canConvert(QVariant::List);
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::size_t arrayLength(const QVariant& value) { return value.toList().size(); }
|
||||
|
||||
static QVariant arrayMember(const QVariant& value, std::size_t i) { return value.toList()[static_cast<int>(i)]; }
|
||||
|
||||
static bool isObject(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantMap)) ||
|
||||
value.typeId() == QMetaType::QByteArray
|
||||
#else
|
||||
return value.canConvert(QVariant::Map) || value.type() == QVariant::ByteArray
|
||||
#endif
|
||||
|| QString(value.typeName()) == QStringLiteral("QMapLibreGL::Feature") ||
|
||||
value.userType() == qMetaTypeId<QVector<QMapLibreGL::Feature>>() ||
|
||||
value.userType() == qMetaTypeId<QList<QMapLibreGL::Feature>>() ||
|
||||
value.userType() == qMetaTypeId<std::list<QMapLibreGL::Feature>>();
|
||||
}
|
||||
|
||||
static std::optional<QVariant> objectMember(const QVariant& value, const char* key) {
|
||||
auto map = value.toMap();
|
||||
auto iter = map.constFind(key);
|
||||
|
||||
if (iter != map.constEnd()) {
|
||||
return iter.value();
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
static std::optional<Error> eachMember(const QVariant& value, Fn&& fn) {
|
||||
auto map = value.toMap();
|
||||
auto iter = map.constBegin();
|
||||
|
||||
while (iter != map.constEnd()) {
|
||||
std::optional<Error> result = fn(iter.key().toStdString(), QVariant(iter.value()));
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::optional<bool> toBool(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (value.typeId() == QMetaType::Bool) {
|
||||
#else
|
||||
if (value.type() == QVariant::Bool) {
|
||||
#endif
|
||||
return value.toBool();
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<float> toNumber(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) {
|
||||
#else
|
||||
if (value.type() == QVariant::Int || value.type() == QVariant::Double) {
|
||||
#endif
|
||||
return value.toFloat();
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<double> toDouble(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) {
|
||||
#else
|
||||
if (value.type() == QVariant::Int || value.type() == QVariant::Double) {
|
||||
#endif
|
||||
return value.toDouble();
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<std::string> toString(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (value.typeId() == QMetaType::QString) {
|
||||
return value.toString().toStdString();
|
||||
} else if (value.typeId() == QMetaType::QColor) {
|
||||
return convertColor(value.value<QColor>());
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
#else
|
||||
if (value.type() == QVariant::String) {
|
||||
return value.toString().toStdString();
|
||||
} else if (value.type() == QVariant::Color) {
|
||||
return convertColor(value.value<QColor>());
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::optional<Value> toValue(const QVariant& value) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (value.typeId() == QMetaType::Bool) {
|
||||
return {value.toBool()};
|
||||
} else if (value.typeId() == QMetaType::QString) {
|
||||
return {value.toString().toStdString()};
|
||||
} else if (value.typeId() == QMetaType::QColor) {
|
||||
return {convertColor(value.value<QColor>())};
|
||||
} else if (value.typeId() == QMetaType::Int) {
|
||||
return {int64_t(value.toInt())};
|
||||
} else if (QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::Double))) {
|
||||
return {value.toDouble()};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
#else
|
||||
if (value.type() == QVariant::Bool) {
|
||||
return {value.toBool()};
|
||||
} else if (value.type() == QVariant::String) {
|
||||
return {value.toString().toStdString()};
|
||||
} else if (value.type() == QVariant::Color) {
|
||||
return {convertColor(value.value<QColor>())};
|
||||
} else if (value.type() == QVariant::Int) {
|
||||
return {int64_t(value.toInt())};
|
||||
} else if (value.canConvert(QVariant::Double)) {
|
||||
return {value.toDouble()};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::optional<GeoJSON> toGeoJSON(const QVariant& value, Error& error) {
|
||||
if (value.typeName() == QStringLiteral("QMapLibreGL::Feature")) {
|
||||
return GeoJSON{QMapLibreGL::GeoJSON::asFeature(value.value<QMapLibreGL::Feature>())};
|
||||
} else if (value.userType() == qMetaTypeId<QVector<QMapLibreGL::Feature>>()) {
|
||||
return featureCollectionToGeoJSON(value.value<QVector<QMapLibreGL::Feature>>());
|
||||
} else if (value.userType() == qMetaTypeId<QList<QMapLibreGL::Feature>>()) {
|
||||
return featureCollectionToGeoJSON(value.value<QList<QMapLibreGL::Feature>>());
|
||||
} else if (value.userType() == qMetaTypeId<std::list<QMapLibreGL::Feature>>()) {
|
||||
return featureCollectionToGeoJSON(value.value<std::list<QMapLibreGL::Feature>>());
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
} else if (value.typeId() != QMetaType::QByteArray) {
|
||||
#else
|
||||
} else if (value.type() != QVariant::ByteArray) {
|
||||
#endif
|
||||
error = {"JSON data must be in QByteArray"};
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray data = value.toByteArray();
|
||||
return parseGeoJSON(std::string(data.constData(), data.size()), error);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static GeoJSON featureCollectionToGeoJSON(const T& features) {
|
||||
mapbox::feature::feature_collection<double> collection;
|
||||
collection.reserve(static_cast<std::size_t>(features.size()));
|
||||
for (const auto& feature : features) {
|
||||
collection.push_back(QMapLibreGL::GeoJSON::asFeature(feature));
|
||||
}
|
||||
return GeoJSON{std::move(collection)};
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
std::optional<T> convert(const QVariant& value, Error& error, Args&&... args) {
|
||||
return convert<T>(Convertible(value), error, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
inline std::string convertColor(const QColor& color) {
|
||||
return QString::asprintf("rgba(%d,%d,%d,%lf)", color.red(), color.green(), color.blue(), color.alphaF())
|
||||
.toStdString();
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
@@ -1,162 +0,0 @@
|
||||
#include "geojson.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace QMapLibreGL::GeoJSON {
|
||||
|
||||
mbgl::Point<double> asPoint(const Coordinate &coordinate) {
|
||||
return mbgl::Point<double>{coordinate.second, coordinate.first};
|
||||
}
|
||||
|
||||
mbgl::MultiPoint<double> asMultiPoint(const Coordinates &multiPoint) {
|
||||
mbgl::MultiPoint<double> mbglMultiPoint;
|
||||
mbglMultiPoint.reserve(multiPoint.size());
|
||||
for (const auto &point : multiPoint) {
|
||||
mbglMultiPoint.emplace_back(asPoint(point));
|
||||
}
|
||||
return mbglMultiPoint;
|
||||
};
|
||||
|
||||
mbgl::LineString<double> asLineString(const Coordinates &lineString) {
|
||||
mbgl::LineString<double> mbglLineString;
|
||||
mbglLineString.reserve(lineString.size());
|
||||
for (const auto &coordinate : lineString) {
|
||||
mbglLineString.emplace_back(asPoint(coordinate));
|
||||
}
|
||||
return mbglLineString;
|
||||
};
|
||||
|
||||
mbgl::MultiLineString<double> asMultiLineString(const CoordinatesCollection &multiLineString) {
|
||||
mbgl::MultiLineString<double> mbglMultiLineString;
|
||||
mbglMultiLineString.reserve(multiLineString.size());
|
||||
for (const auto &lineString : multiLineString) {
|
||||
mbglMultiLineString.emplace_back(std::forward<mbgl::LineString<double>>(asLineString(lineString)));
|
||||
}
|
||||
return mbglMultiLineString;
|
||||
};
|
||||
|
||||
mbgl::Polygon<double> asPolygon(const CoordinatesCollection &polygon) {
|
||||
mbgl::Polygon<double> mbglPolygon;
|
||||
mbglPolygon.reserve(polygon.size());
|
||||
for (const auto &linearRing : polygon) {
|
||||
mbgl::LinearRing<double> mbglLinearRing;
|
||||
mbglLinearRing.reserve(linearRing.size());
|
||||
for (const auto &coordinate : linearRing) {
|
||||
mbglLinearRing.emplace_back(asPoint(coordinate));
|
||||
}
|
||||
mbglPolygon.emplace_back(std::move(mbglLinearRing));
|
||||
}
|
||||
return mbglPolygon;
|
||||
};
|
||||
|
||||
mbgl::MultiPolygon<double> asMultiPolygon(const CoordinatesCollections &multiPolygon) {
|
||||
mbgl::MultiPolygon<double> mbglMultiPolygon;
|
||||
mbglMultiPolygon.reserve(multiPolygon.size());
|
||||
for (const auto &polygon : multiPolygon) {
|
||||
mbglMultiPolygon.emplace_back(std::forward<mbgl::Polygon<double>>(asPolygon(polygon)));
|
||||
}
|
||||
return mbglMultiPolygon;
|
||||
};
|
||||
|
||||
mbgl::Value asPropertyValue(const QVariant &value) {
|
||||
auto valueList = [](const QVariantList &list) {
|
||||
std::vector<mbgl::Value> mbglList;
|
||||
mbglList.reserve(list.size());
|
||||
for (const auto &listValue : list) {
|
||||
mbglList.emplace_back(asPropertyValue(listValue));
|
||||
}
|
||||
return mbglList;
|
||||
};
|
||||
|
||||
auto valueMap = [](const QVariantMap &map) {
|
||||
std::unordered_map<std::string, mbgl::Value> mbglMap;
|
||||
mbglMap.reserve(map.size());
|
||||
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
|
||||
mbglMap.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value())));
|
||||
}
|
||||
return mbglMap;
|
||||
};
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
switch (value.typeId()) {
|
||||
#else
|
||||
switch (static_cast<QMetaType::Type>(value.type())) {
|
||||
#endif
|
||||
case QMetaType::UnknownType:
|
||||
return mbgl::NullValue{};
|
||||
case QMetaType::Bool:
|
||||
return {value.toBool()};
|
||||
case QMetaType::ULongLong:
|
||||
return {uint64_t(value.toULongLong())};
|
||||
case QMetaType::LongLong:
|
||||
return {int64_t(value.toLongLong())};
|
||||
case QMetaType::Double:
|
||||
return {value.toDouble()};
|
||||
case QMetaType::QString:
|
||||
return {value.toString().toStdString()};
|
||||
case QMetaType::QVariantList:
|
||||
return valueList(value.toList());
|
||||
case QMetaType::QVariantMap:
|
||||
return valueMap(value.toMap());
|
||||
default:
|
||||
qWarning() << "Unsupported feature property value:" << value;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
switch (id.typeId()) {
|
||||
#else
|
||||
switch (static_cast<QMetaType::Type>(id.type())) {
|
||||
#endif
|
||||
case QMetaType::UnknownType:
|
||||
return {};
|
||||
case QMetaType::ULongLong:
|
||||
return {uint64_t(id.toULongLong())};
|
||||
case QMetaType::LongLong:
|
||||
return {int64_t(id.toLongLong())};
|
||||
case QMetaType::Double:
|
||||
return {id.toDouble()};
|
||||
case QMetaType::QString:
|
||||
return {id.toString().toStdString()};
|
||||
default:
|
||||
qWarning() << "Unsupported feature identifier:" << id;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
mbgl::GeoJSONFeature asFeature(const Feature &feature) {
|
||||
mbgl::PropertyMap properties;
|
||||
properties.reserve(feature.properties.size());
|
||||
for (auto it = feature.properties.constBegin(); it != feature.properties.constEnd(); ++it) {
|
||||
properties.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value())));
|
||||
}
|
||||
|
||||
mbgl::FeatureIdentifier id = asFeatureIdentifier(feature.id);
|
||||
|
||||
if (feature.type == Feature::PointType) {
|
||||
const Coordinates &points = feature.geometry.first().first();
|
||||
if (points.size() == 1) {
|
||||
return {asPoint(points.first()), std::move(properties), std::move(id)};
|
||||
} else {
|
||||
return {asMultiPoint(points), std::move(properties), std::move(id)};
|
||||
}
|
||||
} else if (feature.type == Feature::LineStringType) {
|
||||
const CoordinatesCollection &lineStrings = feature.geometry.first();
|
||||
if (lineStrings.size() == 1) {
|
||||
return {asLineString(lineStrings.first()), std::move(properties), std::move(id)};
|
||||
} else {
|
||||
return {asMultiLineString(lineStrings), std::move(properties), std::move(id)};
|
||||
}
|
||||
} else { // PolygonType
|
||||
const CoordinatesCollections &polygons = feature.geometry;
|
||||
if (polygons.size() == 1) {
|
||||
return {asPolygon(polygons.first()), std::move(properties), std::move(id)};
|
||||
} else {
|
||||
return {asMultiPolygon(polygons), std::move(properties), std::move(id)};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL::GeoJSON
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/Types>
|
||||
|
||||
#include <mapbox/geojson.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace QMapLibreGL::GeoJSON {
|
||||
|
||||
mbgl::Point<double> asPoint(const Coordinate &coordinate);
|
||||
mbgl::MultiPoint<double> asMultiPoint(const Coordinates &multiPoint);
|
||||
mbgl::LineString<double> asLineString(const Coordinates &lineString);
|
||||
mbgl::MultiLineString<double> asMultiLineString(const CoordinatesCollection &multiLineString);
|
||||
mbgl::Polygon<double> asPolygon(const CoordinatesCollection &polygon);
|
||||
mbgl::MultiPolygon<double> asMultiPolygon(const CoordinatesCollections &multiPolygon);
|
||||
mbgl::Value asPropertyValue(const QVariant &value);
|
||||
mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id);
|
||||
mbgl::GeoJSONFeature asFeature(const Feature &feature);
|
||||
|
||||
} // namespace QMapLibreGL::GeoJSON
|
||||
@@ -1,106 +0,0 @@
|
||||
#include "map_observer.hpp"
|
||||
|
||||
#include "../map_p.hpp"
|
||||
|
||||
#include <mbgl/util/exception.hpp>
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
MapObserver::MapObserver(MapPrivate* d)
|
||||
: d_ptr(d) {}
|
||||
|
||||
MapObserver::~MapObserver() {}
|
||||
|
||||
void MapObserver::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) {
|
||||
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
|
||||
emit mapChanged(Map::MapChangeRegionWillChange);
|
||||
} else {
|
||||
emit mapChanged(Map::MapChangeRegionWillChangeAnimated);
|
||||
}
|
||||
}
|
||||
|
||||
void MapObserver::onCameraIsChanging() {
|
||||
emit mapChanged(Map::MapChangeRegionIsChanging);
|
||||
}
|
||||
|
||||
void MapObserver::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode) {
|
||||
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
|
||||
emit mapChanged(Map::MapChangeRegionDidChange);
|
||||
} else {
|
||||
emit mapChanged(Map::MapChangeRegionDidChangeAnimated);
|
||||
}
|
||||
}
|
||||
|
||||
void MapObserver::onWillStartLoadingMap() {
|
||||
emit mapChanged(Map::MapChangeWillStartLoadingMap);
|
||||
}
|
||||
|
||||
void MapObserver::onDidFinishLoadingMap() {
|
||||
emit mapChanged(Map::MapChangeDidFinishLoadingMap);
|
||||
}
|
||||
|
||||
void MapObserver::onDidFailLoadingMap(mbgl::MapLoadError error, const std::string& what) {
|
||||
emit mapChanged(Map::MapChangeDidFailLoadingMap);
|
||||
|
||||
Map::MapLoadingFailure type;
|
||||
QString description(what.c_str());
|
||||
|
||||
switch (error) {
|
||||
case mbgl::MapLoadError::StyleParseError:
|
||||
type = Map::MapLoadingFailure::StyleParseFailure;
|
||||
break;
|
||||
case mbgl::MapLoadError::StyleLoadError:
|
||||
type = Map::MapLoadingFailure::StyleLoadFailure;
|
||||
break;
|
||||
case mbgl::MapLoadError::NotFoundError:
|
||||
type = Map::MapLoadingFailure::NotFoundFailure;
|
||||
break;
|
||||
default:
|
||||
type = Map::MapLoadingFailure::UnknownFailure;
|
||||
}
|
||||
|
||||
emit mapLoadingFailed(type, description);
|
||||
}
|
||||
|
||||
void MapObserver::onWillStartRenderingFrame() {
|
||||
emit mapChanged(Map::MapChangeWillStartRenderingFrame);
|
||||
}
|
||||
|
||||
void MapObserver::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status) {
|
||||
if (status.mode == mbgl::MapObserver::RenderMode::Partial) {
|
||||
emit mapChanged(Map::MapChangeDidFinishRenderingFrame);
|
||||
} else {
|
||||
emit mapChanged(Map::MapChangeDidFinishRenderingFrameFullyRendered);
|
||||
}
|
||||
}
|
||||
|
||||
void MapObserver::onWillStartRenderingMap() {
|
||||
emit mapChanged(Map::MapChangeWillStartRenderingMap);
|
||||
}
|
||||
|
||||
void MapObserver::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) {
|
||||
if (mode == mbgl::MapObserver::RenderMode::Partial) {
|
||||
emit mapChanged(Map::MapChangeDidFinishRenderingMap);
|
||||
} else {
|
||||
emit mapChanged(Map::MapChangeDidFinishRenderingMapFullyRendered);
|
||||
}
|
||||
}
|
||||
|
||||
void MapObserver::onDidFinishLoadingStyle() {
|
||||
emit mapChanged(Map::MapChangeDidFinishLoadingStyle);
|
||||
}
|
||||
|
||||
void MapObserver::onSourceChanged(mbgl::style::Source&) {
|
||||
std::string attribution;
|
||||
for (const auto& source : d_ptr->mapObj->getStyle().getSources()) {
|
||||
// Avoid duplicates by using the most complete attribution HTML snippet.
|
||||
if (source->getAttribution() && (attribution.size() < source->getAttribution()->size()))
|
||||
attribution = *source->getAttribution();
|
||||
}
|
||||
emit copyrightsChanged(QString::fromStdString(attribution));
|
||||
emit mapChanged(Map::MapChangeSourceDidChange);
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/Map>
|
||||
|
||||
#include <mbgl/map/map_observer.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
class MapPrivate;
|
||||
|
||||
class MapObserver : public QObject, public mbgl::MapObserver {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapObserver(MapPrivate *);
|
||||
virtual ~MapObserver();
|
||||
|
||||
// mbgl::MapObserver implementation.
|
||||
void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final;
|
||||
void onCameraIsChanging() final;
|
||||
void onCameraDidChange(mbgl::MapObserver::CameraChangeMode) final;
|
||||
void onWillStartLoadingMap() final;
|
||||
void onDidFinishLoadingMap() final;
|
||||
void onDidFailLoadingMap(mbgl::MapLoadError, const std::string &) final;
|
||||
void onWillStartRenderingFrame() final;
|
||||
void onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus) final;
|
||||
void onWillStartRenderingMap() final;
|
||||
void onDidFinishRenderingMap(mbgl::MapObserver::RenderMode) final;
|
||||
void onDidFinishLoadingStyle() final;
|
||||
void onSourceChanged(mbgl::style::Source &) final;
|
||||
|
||||
signals:
|
||||
void mapChanged(Map::MapChange);
|
||||
void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason);
|
||||
void copyrightsChanged(const QString ©rightsHtml);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(MapObserver)
|
||||
|
||||
MapPrivate *d_ptr;
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,100 +0,0 @@
|
||||
#include "map_renderer.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include <mbgl/gfx/backend_scope.hpp>
|
||||
|
||||
#include <QThreadStorage>
|
||||
|
||||
namespace {
|
||||
|
||||
static bool needsToForceScheduler() {
|
||||
static QThreadStorage<bool> force;
|
||||
|
||||
if (!force.hasLocalData()) {
|
||||
force.setLocalData(mbgl::Scheduler::GetCurrent() == nullptr);
|
||||
}
|
||||
|
||||
return force.localData();
|
||||
};
|
||||
|
||||
static auto *getScheduler() {
|
||||
static QThreadStorage<std::shared_ptr<QMapLibreGL::Scheduler>> scheduler;
|
||||
|
||||
if (!scheduler.hasLocalData()) {
|
||||
scheduler.setLocalData(std::make_shared<QMapLibreGL::Scheduler>());
|
||||
}
|
||||
|
||||
return scheduler.localData().get();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
MapRenderer::MapRenderer(qreal pixelRatio, Settings::GLContextMode mode, const QString &localFontFamily)
|
||||
: m_backend(static_cast<mbgl::gfx::ContextMode>(mode)),
|
||||
m_renderer(std::make_unique<mbgl::Renderer>(
|
||||
m_backend,
|
||||
pixelRatio,
|
||||
localFontFamily.isEmpty() ? std::nullopt : std::optional<std::string>{localFontFamily.toStdString()})),
|
||||
m_forceScheduler(needsToForceScheduler()) {
|
||||
// If we don't have a Scheduler on this thread, which
|
||||
// is usually the case for render threads, use a shared
|
||||
// dummy scheduler that needs to be explicitly forced to
|
||||
// process events.
|
||||
if (m_forceScheduler) {
|
||||
auto scheduler = getScheduler();
|
||||
|
||||
if (mbgl::Scheduler::GetCurrent() == nullptr) {
|
||||
mbgl::Scheduler::SetCurrent(scheduler);
|
||||
}
|
||||
|
||||
connect(scheduler, &Scheduler::needsProcessing, this, &MapRenderer::needsRendering);
|
||||
}
|
||||
}
|
||||
|
||||
MapRenderer::~MapRenderer() {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
}
|
||||
|
||||
void MapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParameters> newParameters) {
|
||||
std::lock_guard<std::mutex> lock(m_updateMutex);
|
||||
m_updateParameters = std::move(newParameters);
|
||||
}
|
||||
|
||||
void MapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size) {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
|
||||
m_backend.updateFramebuffer(fbo, size);
|
||||
}
|
||||
|
||||
void MapRenderer::render() {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
|
||||
std::shared_ptr<mbgl::UpdateParameters> params;
|
||||
{
|
||||
// Lock on the parameters
|
||||
std::lock_guard<std::mutex> lock(m_updateMutex);
|
||||
|
||||
// UpdateParameters should always be available when rendering.
|
||||
assert(m_updateParameters);
|
||||
|
||||
// Hold on to the update parameters during render
|
||||
params = m_updateParameters;
|
||||
}
|
||||
|
||||
// The OpenGL implementation automatically enables the OpenGL context for us.
|
||||
mbgl::gfx::BackendScope scope(m_backend, mbgl::gfx::BackendScope::ScopeType::Implicit);
|
||||
|
||||
m_renderer->render(params);
|
||||
|
||||
if (m_forceScheduler) {
|
||||
getScheduler()->processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void MapRenderer::setObserver(std::shared_ptr<mbgl::RendererObserver> observer) {
|
||||
m_renderer->setObserver(observer.get());
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/Settings>
|
||||
|
||||
#include "renderer_backend.hpp"
|
||||
|
||||
#include <mbgl/renderer/renderer.hpp>
|
||||
#include <mbgl/renderer/renderer_observer.hpp>
|
||||
#include <mbgl/util/util.hpp>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace mbgl {
|
||||
class Renderer;
|
||||
class UpdateParameters;
|
||||
} // namespace mbgl
|
||||
|
||||
namespace QMapLibreGL {
|
||||
|
||||
class RendererBackend;
|
||||
|
||||
class MapRenderer : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapRenderer(qreal pixelRatio, Settings::GLContextMode, const QString &localFontFamily);
|
||||
virtual ~MapRenderer();
|
||||
|
||||
void render();
|
||||
void updateFramebuffer(quint32 fbo, const mbgl::Size &size);
|
||||
void setObserver(std::shared_ptr<mbgl::RendererObserver>);
|
||||
|
||||
// Thread-safe, called by the Frontend
|
||||
void updateParameters(std::shared_ptr<mbgl::UpdateParameters>);
|
||||
|
||||
signals:
|
||||
void needsRendering();
|
||||
|
||||
private:
|
||||
MBGL_STORE_THREAD(tid)
|
||||
|
||||
Q_DISABLE_COPY(MapRenderer)
|
||||
|
||||
std::mutex m_updateMutex;
|
||||
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters;
|
||||
|
||||
RendererBackend m_backend;
|
||||
std::unique_ptr<mbgl::Renderer> m_renderer{};
|
||||
|
||||
bool m_forceScheduler{};
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/gfx/backend_scope.hpp>
|
||||
#include <mbgl/gl/renderable_resource.hpp>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QOpenGLContext>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace QMapLibre {
|
||||
|
||||
class RenderableResource final : public mbgl::gl::RenderableResource {
|
||||
public:
|
||||
RenderableResource(RendererBackend& backend_)
|
||||
explicit RenderableResource(RendererBackend &backend_)
|
||||
: backend(backend_) {}
|
||||
|
||||
void bind() override {
|
||||
@@ -20,11 +21,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
RendererBackend& backend;
|
||||
RendererBackend &backend;
|
||||
};
|
||||
|
||||
RendererBackend::RendererBackend(const mbgl::gfx::ContextMode contextMode_)
|
||||
: mbgl::gl::RendererBackend(contextMode_),
|
||||
RendererBackend::RendererBackend(const mbgl::gfx::ContextMode mode)
|
||||
: mbgl::gl::RendererBackend(mode),
|
||||
mbgl::gfx::Renderable({0, 0}, std::make_unique<RenderableResource>(*this)) {}
|
||||
|
||||
RendererBackend::~RendererBackend() = default;
|
||||
@@ -38,18 +39,18 @@ void RendererBackend::restoreFramebufferBinding() {
|
||||
setFramebufferBinding(m_fbo);
|
||||
}
|
||||
|
||||
void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size& newSize) {
|
||||
void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size &newSize) {
|
||||
m_fbo = fbo;
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
Initializes an OpenGL extension function such as Vertex Array Objects
|
||||
(VAOs), required by MapLibre Native engine.
|
||||
Initializes an OpenGL extension function such as Vertex Array Objects (VAOs),
|
||||
required by MapLibre Native engine.
|
||||
*/
|
||||
mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char* name) {
|
||||
QOpenGLContext* thisContext = QOpenGLContext::currentContext();
|
||||
mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char *name) {
|
||||
QOpenGLContext *thisContext = QOpenGLContext::currentContext();
|
||||
return thisContext->getProcAddress(name);
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
} // namespace QMapLibre
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
namespace QMapLibre {
|
||||
|
||||
class RendererBackend final : public mbgl::gl::RendererBackend, public mbgl::gfx::Renderable {
|
||||
public:
|
||||
RendererBackend(mbgl::gfx::ContextMode);
|
||||
explicit RendererBackend(mbgl::gfx::ContextMode mode);
|
||||
~RendererBackend() override;
|
||||
|
||||
void updateFramebuffer(quint32 fbo, const mbgl::Size&);
|
||||
void updateFramebuffer(quint32 fbo, const mbgl::Size &newSize);
|
||||
void restoreFramebufferBinding();
|
||||
|
||||
// mbgl::gfx::RendererBackend implementation
|
||||
public:
|
||||
mbgl::gfx::Renderable& getDefaultRenderable() override { return *this; }
|
||||
mbgl::gfx::Renderable &getDefaultRenderable() override { return *this; }
|
||||
|
||||
protected:
|
||||
// No-op, implicit mode.
|
||||
@@ -26,7 +26,7 @@ protected:
|
||||
|
||||
// mbgl::gl::RendererBackend implementation
|
||||
protected:
|
||||
mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) override;
|
||||
mbgl::gl::ProcAddress getExtensionFunctionPointer(const char *name) override;
|
||||
void updateAssumedState() override;
|
||||
|
||||
private:
|
||||
@@ -35,4 +35,4 @@ private:
|
||||
Q_DISABLE_COPY(RendererBackend)
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
} // namespace QMapLibre
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
namespace QMapLibre {
|
||||
|
||||
// Forwards RendererObserver signals to the given
|
||||
// Delegate RendererObserver on the given RunLoop
|
||||
class RendererObserver : public mbgl::RendererObserver {
|
||||
class RendererObserver final : public mbgl::RendererObserver {
|
||||
public:
|
||||
RendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_)
|
||||
RendererObserver(mbgl::util::RunLoop &mapRunLoop, mbgl::RendererObserver &delegate_)
|
||||
: mailbox(std::make_shared<mbgl::Mailbox>(mapRunLoop)),
|
||||
delegate(delegate_, mailbox) {}
|
||||
|
||||
~RendererObserver() { mailbox->close(); }
|
||||
~RendererObserver() final { mailbox->close(); }
|
||||
|
||||
void onInvalidate() final { delegate.invoke(&mbgl::RendererObserver::onInvalidate); }
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
bool repaintNeeded,
|
||||
bool placementChanged,
|
||||
double frameEncodingTime,
|
||||
double frameRenderingTime) override {
|
||||
double frameRenderingTime) final {
|
||||
void (mbgl::RendererObserver::*f)(
|
||||
RenderMode, bool, bool, double, double) = &mbgl::RendererObserver::onDidFinishRenderingFrame;
|
||||
delegate.invoke(f, mode, repaintNeeded, placementChanged, frameEncodingTime, frameRenderingTime);
|
||||
@@ -47,4 +47,4 @@ private:
|
||||
mbgl::ActorRef<mbgl::RendererObserver> delegate;
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
} // namespace QMapLibre
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
namespace QMapLibre {
|
||||
|
||||
Scheduler::Scheduler() {}
|
||||
Scheduler::Scheduler() = default;
|
||||
|
||||
Scheduler::~Scheduler() {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
}
|
||||
|
||||
void Scheduler::schedule(std::function<void()> function) {
|
||||
std::lock_guard<std::mutex> lock(m_taskQueueMutex);
|
||||
const std::lock_guard<std::mutex> lock(m_taskQueueMutex);
|
||||
m_taskQueue.push(std::move(function));
|
||||
|
||||
// Need to force the main thread to wake
|
||||
@@ -24,15 +24,17 @@ void Scheduler::schedule(std::function<void()> function) {
|
||||
void Scheduler::processEvents() {
|
||||
std::queue<std::function<void()>> taskQueue;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_taskQueueMutex);
|
||||
const std::unique_lock<std::mutex> lock(m_taskQueueMutex);
|
||||
std::swap(taskQueue, m_taskQueue);
|
||||
}
|
||||
|
||||
while (!taskQueue.empty()) {
|
||||
auto& function = taskQueue.front();
|
||||
if (function) function();
|
||||
if (function) {
|
||||
function();
|
||||
}
|
||||
taskQueue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
} // namespace QMapLibre
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace QMapLibreGL {
|
||||
namespace QMapLibre {
|
||||
|
||||
class Scheduler : public QObject, public mbgl::Scheduler {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Scheduler();
|
||||
virtual ~Scheduler();
|
||||
~Scheduler() override;
|
||||
|
||||
// mbgl::Scheduler implementation.
|
||||
void schedule(std::function<void()> scheduled) final;
|
||||
void schedule(std::function<void()> function) final;
|
||||
mapbox::base::WeakPtr<mbgl::Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
void processEvents();
|
||||
@@ -35,4 +35,4 @@ private:
|
||||
mapbox::base::WeakPtrFactory<Scheduler> weakFactory{this};
|
||||
};
|
||||
|
||||
} // namespace QMapLibreGL
|
||||
} // namespace QMapLibre
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "qmaplibregl.test.hpp"
|
||||
|
||||
#include <QMapLibreGL/Map>
|
||||
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
QMapLibreGLTest::QMapLibreGLTest()
|
||||
: size(512, 512),
|
||||
fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)),
|
||||
map(nullptr, settings, size) {
|
||||
connect(&map, &QMapLibreGL::mapChanged, this, &QMapLibreGLTest::onMapChanged);
|
||||
connect(&map, &QMapLibreGL::needsRendering, this, &QMapLibreGLTest::onNeedsRendering);
|
||||
map.resize(fbo.size());
|
||||
map.setFramebufferObject(fbo.handle(), fbo.size());
|
||||
map.setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 14);
|
||||
}
|
||||
|
||||
void QMapLibreGLTest::runUntil(QMapLibreGL::MapChange status) {
|
||||
changeCallback = [&](QMapLibreGL::MapChange change) {
|
||||
if (change == status) {
|
||||
qApp->exit();
|
||||
changeCallback = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
void QMapLibreGLTest::onMapChanged(QMapLibreGL::MapChange change) {
|
||||
if (changeCallback) {
|
||||
changeCallback(change);
|
||||
}
|
||||
}
|
||||
|
||||
void QMapLibreGLTest::onNeedsRendering() {
|
||||
widget.makeCurrent();
|
||||
fbo.bind();
|
||||
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo.width(), fbo.height());
|
||||
map.render();
|
||||
}
|
||||
|
||||
TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleJson)) {
|
||||
QFile f("test/fixtures/resources/style_vector.json");
|
||||
|
||||
ASSERT_TRUE(f.open(QFile::ReadOnly | QFile::Text));
|
||||
|
||||
QTextStream in(&f);
|
||||
QString json = in.readAll();
|
||||
|
||||
map.setStyleJson(json);
|
||||
ASSERT_EQ(map.styleJson(), json);
|
||||
runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap);
|
||||
|
||||
map.setStyleJson("invalid json");
|
||||
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
|
||||
|
||||
map.setStyleJson("\"\"");
|
||||
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
|
||||
|
||||
map.setStyleJson(QString());
|
||||
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
|
||||
}
|
||||
|
||||
TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleUrl)) {
|
||||
QString url(QMapLibreGL::defaultStyles()[0].first);
|
||||
|
||||
map.setStyleUrl(url);
|
||||
ASSERT_EQ(map.styleUrl(), url);
|
||||
runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap);
|
||||
|
||||
map.setStyleUrl("invalid://url");
|
||||
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
|
||||
|
||||
map.setStyleUrl(QString());
|
||||
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#include <QMapLibreGL/Map>
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QGLFramebufferObject>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class QMapLibreGLTest : public QObject, public ::testing::Test {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMapLibreGLTest();
|
||||
|
||||
void runUntil(QMapLibreGL::MapChange);
|
||||
|
||||
private:
|
||||
QGLWidget widget;
|
||||
const QSize size;
|
||||
QGLFramebufferObject fbo;
|
||||
|
||||
protected:
|
||||
Settings settings;
|
||||
Map map;
|
||||
|
||||
std::function<void(QMapLibreGL::MapChange)> changeCallback;
|
||||
|
||||
private slots:
|
||||
void onMapChanged(QMapLibreGL::MapChange);
|
||||
void onNeedsRendering();
|
||||
};
|
||||
@@ -78,11 +78,13 @@ TEST(Image, JPEGTile) {
|
||||
EXPECT_EQ(256u, image.size.height);
|
||||
}
|
||||
|
||||
#if !defined(__QT__) // WebP support is not enabled in Qt by default
|
||||
TEST(Image, WebPTile) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.webp"));
|
||||
EXPECT_EQ(256u, image.size.width);
|
||||
EXPECT_EQ(256u, image.size.height);
|
||||
}
|
||||
#endif // !defined(__QT__)
|
||||
|
||||
TEST(Image, Resize) {
|
||||
AlphaImage image({0, 0});
|
||||
|
||||
Reference in New Issue
Block a user