Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*************************************************************************** | ||
testqgsvectortilelayer.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 "qgstest.h" | ||
#include <QObject> | ||
#include <QString> | ||
|
||
//qgis includes... | ||
#include "qgsapplication.h" | ||
#include "qgsproject.h" | ||
#include "qgstiles.h" | ||
#include "qgsvectortilelayer.h" | ||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for a vector tile layer | ||
*/ | ||
class TestQgsVectorTileLayer : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TestQgsVectorTileLayer() = default; | ||
|
||
private: | ||
QString mDataDir; | ||
QgsVectorTileLayer *mLayer = nullptr; | ||
|
||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase();// will be called after the last testfunction was executed. | ||
void init() {} // will be called before each testfunction is executed. | ||
void cleanup() {} // will be called after every testfunction. | ||
|
||
void test_basic(); | ||
}; | ||
|
||
|
||
void TestQgsVectorTileLayer::initTestCase() | ||
{ | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
QgsApplication::showSettings(); | ||
mDataDir = QString( TEST_DATA_DIR ); //defined in CmakeLists.txt | ||
mDataDir += "/vector_tile"; | ||
|
||
QgsDataSourceUri ds; | ||
ds.setParam( "type", "xyz" ); | ||
ds.setParam( "url", QString( "file://%1/{z}-{x}-{y}.pbf" ).arg( mDataDir ) ); | ||
ds.setParam( "zmax", "1" ); | ||
mLayer = new QgsVectorTileLayer( ds.encodedUri(), "Vector Tiles Test" ); | ||
QVERIFY( mLayer->isValid() ); | ||
|
||
QgsProject::instance()->addMapLayer( mLayer ); | ||
|
||
} | ||
|
||
void TestQgsVectorTileLayer::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsVectorTileLayer::test_basic() | ||
{ | ||
// tile fetch test | ||
QByteArray tile0rawData = mLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) ); | ||
QCOMPARE( tile0rawData.length(), 64822 ); | ||
|
||
QByteArray invalidTileRawData = mLayer->getRawTile( QgsTileXYZ( 0, 0, 99 ) ); | ||
QCOMPARE( invalidTileRawData.length(), 0 ); | ||
} | ||
|
||
|
||
QGSTEST_MAIN( TestQgsVectorTileLayer ) | ||
#include "testqgsvectortilelayer.moc" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
# Vector Tiles Test Data | ||
|
||
Downloaded from https://api.maptiler.com/tiles/v3/{z}/{x}/{y}.pbf?key=XXX | ||
(where XXX stands for a key that can be obtained when registered at MapTiler: https://www.maptiler.com/) | ||
|
||
## License | ||
|
||
These tiles are coming from OpenMapTiles project, under the "Free data" terms of use: https://openmaptiles.com/terms/ | ||
|
||
The FREE tiles are legally usable for: | ||
|
||
- open-source and open-data community project websites | ||
- non-commercial personal projects | ||
- evaluation and education purposes |