Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Lutra's vector tile layer for background map #2696

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/projectwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "coreutils.h"

#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsvectortilelayer.h"
#include "qgsvectorlayer.h"
#include "qgsvectorfilewriter.h"
#include "qgsdatetimefieldformatter.h"
Expand All @@ -25,6 +25,8 @@
#include "inpututils.h"
#include "coreutils.h"

const QString TILES_URL = QStringLiteral( "https://vtiles.merginmaps.com" );

ProjectWizard::ProjectWizard( const QString &dataDir, QObject *parent )
: QObject( parent )
, mDataDir( dataDir )
Expand Down Expand Up @@ -102,8 +104,18 @@ void ProjectWizard::createProject( QString const &projectName, FieldsModel *fiel
QgsProject project;

// add layers
QString urlWithParams( BG_MAPS_CONFIG );
QgsRasterLayer *bgLayer = new QgsRasterLayer( BG_MAPS_CONFIG, QStringLiteral( "OpenStreetMap" ), QStringLiteral( "wms" ) );
QgsDataSourceUri dsUri;
dsUri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) );
dsUri.setParam( QStringLiteral( "url" ), QStringLiteral( "%1/data/v3/{z}/{x}/{y}.pbf" ).arg( TILES_URL ) );
dsUri.setParam( QStringLiteral( "styleUrl" ), QStringLiteral( "%1/styles/basic-preview-global/style.json" ).arg( TILES_URL ) );
dsUri.setParam( QStringLiteral( "zmin" ), QStringLiteral( "0" ) );
dsUri.setParam( QStringLiteral( "zmax" ), QStringLiteral( "14" ) );
QgsVectorTileLayer *bgLayer = new QgsVectorTileLayer( dsUri.encodedUri(), QStringLiteral( "OpenMapTiles(OSM)" ) );
bool ok;
QString error = bgLayer->loadDefaultStyle( ok );
QgsLayerMetadata metadata;
metadata.setRights( QStringList() << QStringLiteral( "© OpenMapTiles © OpenStreetMap contributors" ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wonder-sk @alexbruy are there any attributions ? (openmaptiles or styling?)

bgLayer->setMetadata( metadata );
QgsVectorLayer *layer = createGpkgLayer( projectDir, fieldsModel->fields() );
QList<QgsMapLayer *> layers;
layers << layer << bgLayer;
Expand Down
1 change: 0 additions & 1 deletion app/projectwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class ProjectWizard : public QObject
QString mDataDir;
std::unique_ptr<QgsMapSettings> mSettings = nullptr;

const QString BG_MAPS_CONFIG = QStringLiteral( "tilePixelRatio=1&type=xyz&url=https://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0" );
const QString PROJECT_CRS_ID = QStringLiteral( "EPSG:3857" );
const QString LAYER_CRS_ID = QStringLiteral( "EPSG:4326" );
};
Expand Down