10 #include "VectorTileLayer.h"
13 #include <QThreadPool>
15 #include "VectorTileModel.h"
16 #include "GeoPainter.h"
17 #include "GeoSceneGroup.h"
18 #include "GeoSceneTypes.h"
19 #include "GeoSceneVectorTileDataset.h"
20 #include "GeoSceneAbstractTileProjection.h"
21 #include "MarbleDebug.h"
22 #include "TileLoader.h"
24 #include "RenderState.h"
25 #include "GeoDataDocument.h"
26 #include "GeoDataLatLonAltBox.h"
27 #include "HttpDownloadManager.h"
28 #include "TileLoaderHelper.h"
33 class Q_DECL_HIDDEN VectorTileLayer::Private
36 Private(HttpDownloadManager *downloadManager,
37 const PluginManager *pluginManager,
38 VectorTileLayer *parent,
39 GeoDataTreeModel *treeModel);
43 void updateTile(
const TileId &tileId, GeoDataDocument* document);
44 void updateLayerSettings();
49 VectorTileLayer *
const m_parent;
53 const GeoSceneGroup *m_layerSettings;
56 GeoDataTreeModel *
const m_treeModel;
61 VectorTileLayer::Private::Private(HttpDownloadManager *downloadManager,
62 const PluginManager *pluginManager,
63 VectorTileLayer *parent,
64 GeoDataTreeModel *treeModel) :
66 m_loader(downloadManager, pluginManager),
69 m_layerSettings(nullptr),
70 m_treeModel(treeModel)
72 m_threadPool.setMaxThreadCount(1);
75 VectorTileLayer::Private::~Private()
77 qDeleteAll(m_activeTileModels);
80 void VectorTileLayer::Private::updateTile(
const TileId &tileId, GeoDataDocument* document)
82 for (VectorTileModel *mapper: m_activeTileModels) {
83 mapper->updateTile(tileId, document);
87 void VectorTileLayer::Private::updateLayerSettings()
89 m_activeTileModels.clear();
91 for (VectorTileModel *candidate: m_tileModels) {
93 if (m_layerSettings) {
94 const bool propertyExists = m_layerSettings->propertyValue(candidate->name(), enabled);
95 enabled |= !propertyExists;
98 m_activeTileModels.append(candidate);
99 mDebug() <<
"enabling vector layer" << candidate->name();
102 mDebug() <<
"disabling vector layer" << candidate->name();
107 VectorTileLayer::VectorTileLayer(HttpDownloadManager *downloadManager,
108 const PluginManager *pluginManager,
109 GeoDataTreeModel *treeModel)
111 , d(new Private(downloadManager, pluginManager, this, treeModel))
113 qRegisterMetaType<TileId>(
"TileId");
114 qRegisterMetaType<GeoDataDocument*>(
"GeoDataDocument*");
116 connect(&d->m_loader, SIGNAL(tileCompleted(TileId,GeoDataDocument*)),
this, SLOT(updateTile(TileId,GeoDataDocument*)));
119 VectorTileLayer::~VectorTileLayer()
124 RenderState VectorTileLayer::renderState()
const
126 return RenderState(QStringLiteral(
"Vector Tiles"));
129 int VectorTileLayer::tileZoomLevel()
const
132 for (
const auto *mapper: d->m_activeTileModels) {
133 level = qMax(level, mapper->tileZoomLevel());
138 QString VectorTileLayer::runtimeTrace()
const
141 for (
const auto *mapper: d->m_activeTileModels) {
142 tiles += mapper->cachedDocuments();
144 int const layers = d->m_activeTileModels.
size();
145 return QStringLiteral(
"Vector Tiles: %1 tiles in %2 layers").arg(tiles).arg(layers);
148 bool VectorTileLayer::render(GeoPainter *painter, ViewportParams *viewport,
149 const QString &renderPos, GeoSceneLayer *layer)
155 int const oldLevel = tileZoomLevel();
157 for (VectorTileModel *mapper: d->m_activeTileModels) {
158 mapper->setViewport(viewport->viewLatLonAltBox());
159 level = qMax(level, mapper->tileZoomLevel());
161 if (oldLevel != level && level >= 0) {
162 emit tileLevelChanged(level);
168 void VectorTileLayer::reload()
170 for (
auto mapper : d->m_activeTileModels) {
175 QSize VectorTileLayer::tileSize()
const
177 return QSize(256, 256);
180 const GeoSceneAbstractTileProjection *VectorTileLayer::tileProjection()
const
182 if (!d->m_activeTileModels.isEmpty())
183 return d->m_activeTileModels.first()->layer()->tileProjection();
187 int VectorTileLayer::tileColumnCount(
int level)
const
190 return TileLoaderHelper::levelToColumn( 1, level );
193 int VectorTileLayer::tileRowCount(
int level)
const
196 return TileLoaderHelper::levelToRow( 1, level );
199 int VectorTileLayer::layerCount()
const
205 void VectorTileLayer::downloadTile(
const TileId &
id)
209 for (
const GeoSceneVectorTileDataset *vectorLayer: vectorLayers ) {
210 if (vectorLayer->tileLevels().isEmpty() || vectorLayer->tileLevels().contains(
id.zoomLevel())) {
211 if ( TileLoader::tileStatus( vectorLayer,
id ) != TileLoader::Available ) {
212 d->m_loader.downloadTile( vectorLayer,
id,
DownloadBulk );
218 void VectorTileLayer::reset()
220 for (VectorTileModel *mapper: d->m_tileModels) {
227 qDeleteAll(d->m_tileModels);
228 d->m_tileModels.clear();
229 d->m_activeTileModels.clear();
231 for (
const GeoSceneVectorTileDataset *layer: textures) {
232 d->m_tileModels <<
new VectorTileModel(&d->m_loader, layer, d->m_treeModel, &d->m_threadPool);
235 d->m_layerSettings = textureLayerSettings;
237 if (d->m_layerSettings) {
238 connect(d->m_layerSettings, SIGNAL(valueChanged(
QString,
bool)),
239 this, SLOT(updateLayerSettings()));
242 d->updateLayerSettings();
243 auto const level = tileZoomLevel();
245 emit tileLevelChanged(level);
253 for (VectorTileModel * candidate: m_activeTileModels) {
254 Q_ASSERT( candidate );
255 const GeoSceneVectorTileDataset * vectorTileDataset = candidate->layer();
257 if ( !vectorTileDataset->hasMaximumTileLevel() ||
258 vectorTileDataset->maximumTileLevel() >= tileId.zoomLevel() ) {
260 if (vectorTileDataset->latLonBox().isNull()) {
261 result.
append(vectorTileDataset);
264 const GeoDataLatLonBox bbox = vectorTileDataset->tileProjection()->geoCoordinates(tileId);
266 if (vectorTileDataset->latLonBox().intersects(bbox)) {
267 result.
append( vectorTileDataset );
279 #include "moc_VectorTileLayer.cpp"