/
qgsvectortilelayer.cpp
632 lines (528 loc) · 22.6 KB
/
qgsvectortilelayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/***************************************************************************
qgsvectortilelayer.cpp
--------------------------------------
Date : March 2020
Copyright : (C) 2020 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsvectortilelayer.h"
#include "qgslogger.h"
#include "qgsvectortilelayerrenderer.h"
#include "qgsmbtiles.h"
#include "qgsvectortilebasiclabeling.h"
#include "qgsvectortilebasicrenderer.h"
#include "qgsvectortilelabeling.h"
#include "qgsvectortileloader.h"
#include "qgsvectortileutils.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsdatasourceuri.h"
#include "qgslayermetadataformatter.h"
#include "qgsblockingnetworkrequest.h"
#include "qgsmapboxglstyleconverter.h"
#include "qgsjsonutils.h"
QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
{
mDataSource = uri;
setValid( loadDataSource() );
// set a default renderer
QgsVectorTileBasicRenderer *renderer = new QgsVectorTileBasicRenderer;
renderer->setStyles( QgsVectorTileBasicRenderer::simpleStyleWithRandomColors() );
setRenderer( renderer );
}
bool QgsVectorTileLayer::loadDataSource()
{
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( mDataSource );
mSourceType = dsUri.param( QStringLiteral( "type" ) );
mSourcePath = dsUri.param( QStringLiteral( "url" ) );
if ( mSourceType == QStringLiteral( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
{
if ( !setupArcgisVectorTileServiceConnection( mSourcePath, dsUri ) )
return false;
}
else if ( mSourceType == QStringLiteral( "xyz" ) )
{
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( mSourcePath ) )
{
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + mSourcePath );
return false;
}
// online tiles
mSourceMinZoom = 0;
mSourceMaxZoom = 14;
if ( dsUri.hasParam( QStringLiteral( "zmin" ) ) )
mSourceMinZoom = dsUri.param( QStringLiteral( "zmin" ) ).toInt();
if ( dsUri.hasParam( QStringLiteral( "zmax" ) ) )
mSourceMaxZoom = dsUri.param( QStringLiteral( "zmax" ) ).toInt();
setExtent( QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
}
else if ( mSourceType == QStringLiteral( "mbtiles" ) )
{
QgsMbTiles reader( mSourcePath );
if ( !reader.open() )
{
QgsDebugMsg( QStringLiteral( "failed to open MBTiles file: " ) + mSourcePath );
return false;
}
QString format = reader.metadataValue( QStringLiteral( "format" ) );
if ( format != QStringLiteral( "pbf" ) )
{
QgsDebugMsg( QStringLiteral( "Cannot open MBTiles for vector tiles. Format = " ) + format );
return false;
}
QgsDebugMsgLevel( QStringLiteral( "name: " ) + reader.metadataValue( QStringLiteral( "name" ) ), 2 );
bool minZoomOk, maxZoomOk;
int minZoom = reader.metadataValue( QStringLiteral( "minzoom" ) ).toInt( &minZoomOk );
int maxZoom = reader.metadataValue( QStringLiteral( "maxzoom" ) ).toInt( &maxZoomOk );
if ( minZoomOk )
mSourceMinZoom = minZoom;
if ( maxZoomOk )
mSourceMaxZoom = maxZoom;
QgsDebugMsgLevel( QStringLiteral( "zoom range: %1 - %2" ).arg( mSourceMinZoom ).arg( mSourceMaxZoom ), 2 );
QgsRectangle r = reader.extent();
QgsCoordinateTransform ct( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ),
QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ), transformContext() );
r = ct.transformBoundingBox( r );
setExtent( r );
}
else
{
QgsDebugMsg( QStringLiteral( "Unknown source type: " ) + mSourceType );
return false;
}
setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );
return true;
}
bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri )
{
QNetworkRequest request = QNetworkRequest( QUrl( uri ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
{
case QgsBlockingNetworkRequest::NoError:
break;
case QgsBlockingNetworkRequest::NetworkError:
case QgsBlockingNetworkRequest::TimeoutError:
case QgsBlockingNetworkRequest::ServerExceptionError:
return false;
}
const QgsNetworkReplyContent content = networkRequest.reply();
const QByteArray raw = content.content();
// Parse data
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson( raw, &err );
if ( doc.isNull() )
{
return false;
}
mArcgisLayerConfiguration = doc.object().toVariantMap();
if ( mArcgisLayerConfiguration.contains( QStringLiteral( "error" ) ) )
{
return false;
}
mArcgisLayerConfiguration.insert( QStringLiteral( "serviceUri" ), uri );
mSourcePath = uri + '/' + mArcgisLayerConfiguration.value( QStringLiteral( "tiles" ) ).toList().value( 0 ).toString();
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( mSourcePath ) )
{
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + mSourcePath );
return false;
}
// if hardcoded zoom limits aren't specified, take them from the server
if ( !dataSourceUri.hasParam( QStringLiteral( "zmin" ) ) )
mSourceMinZoom = 0;
else
mSourceMinZoom = dataSourceUri.param( QStringLiteral( "zmin" ) ).toInt();
if ( !dataSourceUri.hasParam( QStringLiteral( "zmax" ) ) )
mSourceMaxZoom = mArcgisLayerConfiguration.value( QStringLiteral( "maxzoom" ) ).toInt();
else
mSourceMaxZoom = dataSourceUri.param( QStringLiteral( "zmax" ) ).toInt();
setExtent( QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
return true;
}
QgsVectorTileLayer::~QgsVectorTileLayer() = default;
QgsVectorTileLayer *QgsVectorTileLayer::clone() const
{
QgsVectorTileLayer *layer = new QgsVectorTileLayer( source(), name() );
layer->setRenderer( renderer() ? renderer()->clone() : nullptr );
return layer;
}
QgsMapLayerRenderer *QgsVectorTileLayer::createMapRenderer( QgsRenderContext &rendererContext )
{
return new QgsVectorTileLayerRenderer( this, rendererContext );
}
bool QgsVectorTileLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
{
setValid( loadDataSource() );
QString errorMsg;
if ( !readSymbology( layerNode, errorMsg, context ) )
return false;
readStyleManager( layerNode );
return true;
}
bool QgsVectorTileLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement mapLayerNode = layerNode.toElement();
mapLayerNode.setAttribute( QStringLiteral( "type" ), QStringLiteral( "vector-tile" ) );
writeStyleManager( layerNode, doc );
QString errorMsg;
return writeSymbology( layerNode, doc, errorMsg, context );
}
bool QgsVectorTileLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
{
QDomElement elem = node.toElement();
readCommonStyle( elem, context, categories );
const QDomElement elemRenderer = elem.firstChildElement( QStringLiteral( "renderer" ) );
if ( elemRenderer.isNull() )
{
errorMessage = tr( "Missing <renderer> tag" );
return false;
}
const QString rendererType = elemRenderer.attribute( QStringLiteral( "type" ) );
if ( categories.testFlag( Symbology ) )
{
QgsVectorTileRenderer *r = nullptr;
if ( rendererType == QStringLiteral( "basic" ) )
r = new QgsVectorTileBasicRenderer;
else
{
errorMessage = tr( "Unknown renderer type: " ) + rendererType;
return false;
}
r->readXml( elemRenderer, context );
setRenderer( r );
}
if ( categories.testFlag( Labeling ) )
{
setLabeling( nullptr );
const QDomElement elemLabeling = elem.firstChildElement( QStringLiteral( "labeling" ) );
if ( !elemLabeling.isNull() )
{
const QString labelingType = elemLabeling.attribute( QStringLiteral( "type" ) );
QgsVectorTileLabeling *labeling = nullptr;
if ( labelingType == QStringLiteral( "basic" ) )
labeling = new QgsVectorTileBasicLabeling;
else
{
errorMessage = tr( "Unknown labeling type: " ) + rendererType;
}
if ( labeling )
{
labeling->readXml( elemLabeling, context );
setLabeling( labeling );
}
}
}
return true;
}
bool QgsVectorTileLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
{
Q_UNUSED( errorMessage )
QDomElement elem = node.toElement();
writeCommonStyle( elem, doc, context, categories );
if ( mRenderer )
{
QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
elemRenderer.setAttribute( QStringLiteral( "type" ), mRenderer->type() );
if ( categories.testFlag( Symbology ) )
{
mRenderer->writeXml( elemRenderer, context );
}
elem.appendChild( elemRenderer );
}
if ( mLabeling && categories.testFlag( Labeling ) )
{
QDomElement elemLabeling = doc.createElement( QStringLiteral( "labeling" ) );
elemLabeling.setAttribute( QStringLiteral( "type" ), mLabeling->type() );
mLabeling->writeXml( elemLabeling, context );
elem.appendChild( elemLabeling );
}
return true;
}
void QgsVectorTileLayer::setTransformContext( const QgsCoordinateTransformContext &transformContext )
{
Q_UNUSED( transformContext )
}
QString QgsVectorTileLayer::loadDefaultStyle( bool &resultFlag )
{
QString error;
QStringList warnings;
resultFlag = loadDefaultStyle( error, warnings );
return error;
}
bool QgsVectorTileLayer::loadDefaultStyle( QString &error, QStringList &warnings )
{
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( mDataSource );
QString styleUrl;
if ( !dsUri.param( QStringLiteral( "styleUrl" ) ).isEmpty() )
{
styleUrl = dsUri.param( QStringLiteral( "styleUrl" ) );
}
else if ( mSourceType == QStringLiteral( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
{
// for ArcMap VectorTileServices we default to the defaultStyles URL from the layer configuration
styleUrl = mArcgisLayerConfiguration.value( QStringLiteral( "serviceUri" ) ).toString()
+ '/' + mArcgisLayerConfiguration.value( QStringLiteral( "defaultStyles" ) ).toString();
}
if ( !styleUrl.isEmpty() )
{
QNetworkRequest request = QNetworkRequest( QUrl( styleUrl ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
{
case QgsBlockingNetworkRequest::NoError:
break;
case QgsBlockingNetworkRequest::NetworkError:
case QgsBlockingNetworkRequest::TimeoutError:
case QgsBlockingNetworkRequest::ServerExceptionError:
error = QObject::tr( "Error retrieving default style" );
return false;
}
const QgsNetworkReplyContent content = networkRequest.reply();
const QVariantMap styleDefinition = QgsJsonUtils::parseJson( content.content() ).toMap();
QgsMapBoxGlStyleConversionContext context;
// convert automatically from pixel sizes to millimeters, because pixel sizes
// are a VERY edge case in QGIS and don't play nice with hidpi map renders or print layouts
context.setTargetUnit( QgsUnitTypes::RenderMillimeters );
//assume source uses 96 dpi
context.setPixelSizeConversionFactor( 25.4 / 96.0 );
if ( styleDefinition.contains( QStringLiteral( "sprite" ) ) )
{
// retrieve sprite definition
QString spriteUriBase;
if ( styleDefinition.value( QStringLiteral( "sprite" ) ).toString().startsWith( QStringLiteral( "http" ) ) )
{
spriteUriBase = styleDefinition.value( QStringLiteral( "sprite" ) ).toString();
}
else
{
spriteUriBase = styleUrl + '/' + styleDefinition.value( QStringLiteral( "sprite" ) ).toString();
}
for ( int resolution = 2; resolution > 0; resolution-- )
{
QNetworkRequest request = QNetworkRequest( QUrl( spriteUriBase + QStringLiteral( "%1.json" ).arg( resolution > 1 ? QStringLiteral( "@%1x" ).arg( resolution ) : QString() ) ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
{
case QgsBlockingNetworkRequest::NoError:
{
const QgsNetworkReplyContent content = networkRequest.reply();
const QVariantMap spriteDefinition = QgsJsonUtils::parseJson( content.content() ).toMap();
// retrieve sprite images
QNetworkRequest request = QNetworkRequest( QUrl( spriteUriBase + QStringLiteral( "%1.png" ).arg( resolution > 1 ? QStringLiteral( "@%1x" ).arg( resolution ) : QString() ) ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
{
case QgsBlockingNetworkRequest::NoError:
{
const QgsNetworkReplyContent imageContent = networkRequest.reply();
QImage spriteImage( QImage::fromData( imageContent.content() ) );
context.setSprites( spriteImage, spriteDefinition );
break;
}
case QgsBlockingNetworkRequest::NetworkError:
case QgsBlockingNetworkRequest::TimeoutError:
case QgsBlockingNetworkRequest::ServerExceptionError:
break;
}
break;
}
case QgsBlockingNetworkRequest::NetworkError:
case QgsBlockingNetworkRequest::TimeoutError:
case QgsBlockingNetworkRequest::ServerExceptionError:
break;
}
if ( !context.spriteDefinitions().isEmpty() )
break;
}
}
QgsMapBoxGlStyleConverter converter;
if ( converter.convert( styleDefinition, &context ) != QgsMapBoxGlStyleConverter::Success )
{
warnings = converter.warnings();
error = converter.errorMessage();
return false;
}
setRenderer( converter.renderer() );
setLabeling( converter.labeling() );
warnings = converter.warnings();
return true;
}
else
{
bool resultFlag = false;
error = QgsMapLayer::loadDefaultStyle( resultFlag );
return resultFlag;
}
}
QString QgsVectorTileLayer::loadDefaultMetadata( bool &resultFlag )
{
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( mDataSource );
if ( mSourceType == QStringLiteral( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
{
// populate default metadata
QgsLayerMetadata metadata;
metadata.setIdentifier( mArcgisLayerConfiguration.value( QStringLiteral( "serviceUri" ) ).toString() );
const QString parentIdentifier = mArcgisLayerConfiguration.value( QStringLiteral( "serviceItemId" ) ).toString();
if ( !parentIdentifier.isEmpty() )
{
metadata.setParentIdentifier( parentIdentifier );
}
metadata.setType( QStringLiteral( "dataset" ) );
metadata.setTitle( mArcgisLayerConfiguration.value( QStringLiteral( "name" ) ).toString() );
QString copyright = mArcgisLayerConfiguration.value( QStringLiteral( "copyrightText" ) ).toString();
if ( !copyright.isEmpty() )
metadata.setRights( QStringList() << copyright );
metadata.addLink( QgsAbstractMetadataBase::Link( tr( "Source" ), QStringLiteral( "WWW:LINK" ), mArcgisLayerConfiguration.value( QStringLiteral( "serviceUri" ) ).toString() ) );
setMetadata( metadata );
resultFlag = true;
return QString();
}
else
{
QgsMapLayer::loadDefaultMetadata( resultFlag );
resultFlag = true;
return QString();
}
}
QString QgsVectorTileLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
{
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( source );
QString sourceType = dsUri.param( QStringLiteral( "type" ) );
QString sourcePath = dsUri.param( QStringLiteral( "url" ) );
if ( sourceType == QStringLiteral( "xyz" ) )
{
QUrl sourceUrl( sourcePath );
if ( sourceUrl.isLocalFile() )
{
// relative path will become "file:./x.txt"
QString relSrcUrl = context.pathResolver().writePath( sourceUrl.toLocalFile() );
dsUri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
dsUri.setParam( QStringLiteral( "url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
return dsUri.encodedUri();
}
}
else if ( sourceType == QStringLiteral( "mbtiles" ) )
{
sourcePath = context.pathResolver().writePath( sourcePath );
dsUri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
dsUri.setParam( QStringLiteral( "url" ), sourcePath );
return dsUri.encodedUri();
}
return source;
}
QString QgsVectorTileLayer::decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const
{
Q_UNUSED( provider )
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( source );
QString sourceType = dsUri.param( QStringLiteral( "type" ) );
QString sourcePath = dsUri.param( QStringLiteral( "url" ) );
if ( sourceType == QStringLiteral( "xyz" ) )
{
QUrl sourceUrl( sourcePath );
if ( sourceUrl.isLocalFile() ) // file-based URL? convert to relative path
{
QString absSrcUrl = context.pathResolver().readPath( sourceUrl.toLocalFile() );
dsUri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
dsUri.setParam( QStringLiteral( "url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
return dsUri.encodedUri();
}
}
else if ( sourceType == QStringLiteral( "mbtiles" ) )
{
sourcePath = context.pathResolver().readPath( sourcePath );
dsUri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
dsUri.setParam( QStringLiteral( "url" ), sourcePath );
return dsUri.encodedUri();
}
return source;
}
QString QgsVectorTileLayer::htmlMetadata() const
{
QgsLayerMetadataFormatter htmlFormatter( metadata() );
QString info = QStringLiteral( "<html><head></head>\n<body>\n" );
info += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" ) %
QStringLiteral( "<table class=\"list-view\">\n" ) %
// name
QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Name" ) % QStringLiteral( "</td><td>" ) % name() % QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "URI" ) % QStringLiteral( "</td><td>" ) % source() % QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Source type" ) % QStringLiteral( "</td><td>" ) % sourceType() % QStringLiteral( "</td></tr>\n" );
const QString url = sourcePath();
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Source path" ) % QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), sourcePath() ) ) + QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Zoom levels" ) % QStringLiteral( "</td><td>" ) % QStringLiteral( "%1 - %2" ).arg( sourceMinZoom() ).arg( sourceMaxZoom() ) % QStringLiteral( "</td></tr>\n" );
info += QStringLiteral( "</table>" );
// End Provider section
info += QStringLiteral( "</table>\n<br><br>" );
// Identification section
info += QStringLiteral( "<h1>" ) % tr( "Identification" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.identificationSectionHtml() %
QStringLiteral( "<br><br>\n" ) %
// extent section
QStringLiteral( "<h1>" ) % tr( "Extent" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.extentSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %
// Start the Access section
QStringLiteral( "<h1>" ) % tr( "Access" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.accessSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %
// Start the contacts section
QStringLiteral( "<h1>" ) % tr( "Contacts" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.contactsSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %
// Start the links section
QStringLiteral( "<h1>" ) % tr( "References" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.linksSectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %
// Start the history section
QStringLiteral( "<h1>" ) % tr( "History" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
htmlFormatter.historySectionHtml( ) %
QStringLiteral( "<br><br>\n" ) %
QStringLiteral( "\n</body>\n</html>\n" );
return info;
}
QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
{
QgsTileMatrix tileMatrix = QgsTileMatrix::fromWebMercator( tileID.zoomLevel() );
QgsTileRange tileRange( tileID.column(), tileID.column(), tileID.row(), tileID.row() );
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( mDataSource );
const QString authcfg = dsUri.authConfigId();
const QString referer = dsUri.param( QStringLiteral( "referer" ) );
QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData( mSourceType, mSourcePath, tileMatrix, QPointF(), tileRange, authcfg, referer );
if ( rawTiles.isEmpty() )
return QByteArray();
return rawTiles.first().data;
}
void QgsVectorTileLayer::setRenderer( QgsVectorTileRenderer *r )
{
mRenderer.reset( r );
triggerRepaint();
}
QgsVectorTileRenderer *QgsVectorTileLayer::renderer() const
{
return mRenderer.get();
}
void QgsVectorTileLayer::setLabeling( QgsVectorTileLabeling *labeling )
{
mLabeling.reset( labeling );
triggerRepaint();
}
QgsVectorTileLabeling *QgsVectorTileLayer::labeling() const
{
return mLabeling.get();
}