10#include "VectorTileLayer.h" 
   15#include "GeoDataDocument.h" 
   16#include "GeoDataLatLonAltBox.h" 
   17#include "GeoPainter.h" 
   18#include "GeoSceneAbstractTileProjection.h" 
   19#include "GeoSceneGroup.h" 
   20#include "GeoSceneTypes.h" 
   21#include "GeoSceneVectorTileDataset.h" 
   22#include "HttpDownloadManager.h" 
   23#include "MarbleDebug.h" 
   24#include "RenderState.h" 
   25#include "TileLoader.h" 
   26#include "TileLoaderHelper.h" 
   27#include "VectorTileModel.h" 
   33class Q_DECL_HIDDEN VectorTileLayer::Private
 
   36    Private(HttpDownloadManager *downloadManager, 
const PluginManager *pluginManager, VectorTileLayer *parent, GeoDataTreeModel *treeModel);
 
   40    void updateTile(
const TileId &tileId, GeoDataDocument *document);
 
   41    void updateLayerSettings();
 
   43    QList<const GeoSceneVectorTileDataset *> findRelevantVectorLayers(
const TileId &stackedTileId) 
const;
 
   46    VectorTileLayer *
const m_parent;
 
   48    QList<VectorTileModel *> m_tileModels;
 
   49    QList<VectorTileModel *> m_activeTileModels;
 
   50    const GeoSceneGroup *m_layerSettings;
 
   53    GeoDataTreeModel *
const m_treeModel;
 
   55    QThreadPool m_threadPool; 
 
   60                                  VectorTileLayer *parent,
 
   63    , m_loader(downloadManager, pluginManager)
 
   65    , m_activeTileModels()
 
   66    , m_layerSettings(nullptr)
 
   67    , m_treeModel(treeModel)
 
   69    m_threadPool.setMaxThreadCount(1);
 
   72VectorTileLayer::Private::~Private()
 
   74    qDeleteAll(m_activeTileModels);
 
   77void VectorTileLayer::Private::updateTile(
const TileId &tileId, GeoDataDocument *document)
 
   79    for (VectorTileModel *mapper : std::as_const(m_activeTileModels)) {
 
   80        mapper->updateTile(tileId, document);
 
   84void VectorTileLayer::Private::updateLayerSettings()
 
   86    m_activeTileModels.clear();
 
   88    for (VectorTileModel *candidate : std::as_const(m_tileModels)) {
 
   90        if (m_layerSettings) {
 
   91            const bool propertyExists = m_layerSettings->propertyValue(candidate->name(), enabled);
 
   92            enabled |= !propertyExists; 
 
   95            m_activeTileModels.append(candidate);
 
   96            mDebug() << 
"enabling vector layer" << candidate->name();
 
   99            mDebug() << 
"disabling vector layer" << candidate->name();
 
  104VectorTileLayer::VectorTileLayer(HttpDownloadManager *downloadManager, 
const PluginManager *pluginManager, GeoDataTreeModel *treeModel)
 
  106    , d(new Private(downloadManager, pluginManager, this, treeModel))
 
  108    qRegisterMetaType<TileId>(
"TileId");
 
  109    qRegisterMetaType<GeoDataDocument *>(
"GeoDataDocument*");
 
  111    connect(&d->m_loader, SIGNAL(tileCompleted(TileId, GeoDataDocument *)), 
this, SLOT(updateTile(TileId, GeoDataDocument *)));
 
  114VectorTileLayer::~VectorTileLayer()
 
  119RenderState VectorTileLayer::renderState()
 const 
  121    return RenderState(QStringLiteral(
"Vector Tiles"));
 
  124int VectorTileLayer::tileZoomLevel()
 const 
  127    for (
const auto mapper : std::as_const(d->m_activeTileModels)) {
 
  128        level = qMax(level, mapper->tileZoomLevel());
 
  133QString VectorTileLayer::runtimeTrace()
 const 
  136    for (
const auto mapper : std::as_const(d->m_activeTileModels)) {
 
  137        tiles += mapper->cachedDocuments();
 
  139    int const layers = d->m_activeTileModels.
size();
 
  140    return QStringLiteral(
"Vector Tiles: %1 tiles in %2 layers").arg(tiles).arg(layers);
 
  143bool VectorTileLayer::render(GeoPainter *painter, ViewportParams *viewport, 
const QString &renderPos, GeoSceneLayer *layer)
 
  149    int const oldLevel = tileZoomLevel();
 
  151    for (VectorTileModel *mapper : std::as_const(d->m_activeTileModels)) {
 
  152        mapper->setViewport(viewport->viewLatLonAltBox());
 
  153        level = qMax(level, mapper->tileZoomLevel());
 
  155    if (oldLevel != level && level >= 0) {
 
  156        Q_EMIT tileLevelChanged(level);
 
  162void VectorTileLayer::reload()
 
  164    for (
auto mapper : std::as_const(d->m_activeTileModels)) {
 
  169QSize VectorTileLayer::tileSize()
 const 
  174const GeoSceneAbstractTileProjection *VectorTileLayer::tileProjection()
 const 
  176    if (!d->m_activeTileModels.isEmpty())
 
  177        return d->m_activeTileModels.first()->layer()->tileProjection();
 
  181int VectorTileLayer::tileColumnCount(
int level)
 const 
  184    return TileLoaderHelper::levelToColumn(1, level);
 
  187int VectorTileLayer::tileRowCount(
int level)
 const 
  190    return TileLoaderHelper::levelToRow(1, level);
 
  193int VectorTileLayer::layerCount()
 const 
  199void VectorTileLayer::downloadTile(
const TileId &
id)
 
  203    for (
const GeoSceneVectorTileDataset *vectorLayer : vectorLayers) {
 
  204        if (vectorLayer->tileLevels().isEmpty() || vectorLayer->tileLevels().contains(
id.zoomLevel())) {
 
  205            if (TileLoader::tileStatus(vectorLayer, 
id) != TileLoader::Available) {
 
  206                d->m_loader.downloadTile(vectorLayer, 
id, DownloadBulk);
 
  212void VectorTileLayer::reset()
 
  214    for (VectorTileModel *mapper : std::as_const(d->m_tileModels)) {
 
  221    qDeleteAll(d->m_tileModels);
 
  222    d->m_tileModels.clear();
 
  223    d->m_activeTileModels.clear();
 
  225    for (
const GeoSceneVectorTileDataset *layer : textures) {
 
  226        d->m_tileModels << 
new VectorTileModel(&d->m_loader, layer, d->m_treeModel, &d->m_threadPool);
 
  229    d->m_layerSettings = textureLayerSettings;
 
  231    if (d->m_layerSettings) {
 
  232        connect(d->m_layerSettings, SIGNAL(valueChanged(
QString, 
bool)), 
this, SLOT(updateLayerSettings()));
 
  235    d->updateLayerSettings();
 
  236    auto const level = tileZoomLevel();
 
  238        Q_EMIT tileLevelChanged(level);
 
  246    for (VectorTileModel *candidate : m_activeTileModels) {
 
  248        const GeoSceneVectorTileDataset *vectorTileDataset = candidate->layer();
 
  250        if (!vectorTileDataset->hasMaximumTileLevel() || vectorTileDataset->maximumTileLevel() >= tileId.zoomLevel()) {
 
  252            if (vectorTileDataset->latLonBox().isNull()) {
 
  253                result.
append(vectorTileDataset);
 
  255                const GeoDataLatLonBox bbox = vectorTileDataset->tileProjection()->geoCoordinates(tileId);
 
  257                if (vectorTileDataset->latLonBox().intersects(bbox)) {
 
  258                    result.
append(vectorTileDataset);
 
  269#include "moc_VectorTileLayer.cpp" 
This file contains the headers for ViewportParams.
 
The representation of GeoData in a model This class represents all available data given by kml-data f...
 
This class manages scheduled downloads.
 
The class that handles Marble's plugins.
 
QStringView level(QStringView ifopt)
 
Binds a QML item to a specific geodetic location in screen coordinates.
 
void append(QList< T > &&value)
 
qsizetype size() const const
 
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)