25using namespace Qt::StringLiterals;
38 const QVariantMap tileInfo = json.value( u
"tileInfo"_s ).toMap();
40 const QVariantMap origin = tileInfo.value( u
"origin"_s ).toMap();
41 const double originX = origin.value( u
"x"_s ).toDouble();
42 const double originY = origin.value( u
"y"_s ).toDouble();
44 const int rows = tileInfo.value( u
"rows"_s, u
"512"_s ).toInt();
45 const int cols = tileInfo.value( u
"cols"_s, u
"512"_s ).toInt();
48 QgsDebugError( u
"row/col size mismatch: %1 vs %2 - tile misalignment may occur"_s.arg( rows ).arg( cols ) );
53 const QVariantList lodList = tileInfo.value( u
"lods"_s ).toList();
54 bool foundLevel0 =
false;
55 double z0Dimension = 0;
57 for (
const QVariant &lod : lodList )
59 const QVariantMap lodMap = lod.toMap();
60 const int level = lodMap.value( u
"level"_s ).toInt();
63 z0Dimension = lodMap.value( u
"resolution"_s ).toDouble() * rows;
72 for (
const QVariant &lod : lodList )
74 const QVariantMap lodMap = lod.toMap();
75 const int level = lodMap.value( u
"level"_s ).toInt();
84 tm.
setScale( lodMap.value( u
"scale"_s ).toDouble() );
90 const QVariantList tileMap = rootTileMap.value( u
"index"_s ).toList();
91 if ( !tileMap.isEmpty() )
131 std::vector< QgsTileXYZ > bottomToTopQueue;
132 bottomToTopQueue.reserve(
id.zoomLevel() );
138 for (
int zoomLevel =
id.zoomLevel(); zoomLevel > 0; zoomLevel-- )
140 bottomToTopQueue.emplace_back(
QgsTileXYZ( column, row, zoomLevel ) );
147 QVariantList node = tileMap;
148 for (
int index =
static_cast<int>( bottomToTopQueue.size() ) - 1; index >= 0; --index )
150 const QgsTileXYZ &tile = bottomToTopQueue[ index ];
151 int childColumn = tile.
column() - column;
152 int childRow = tile.
row() - row;
154 if ( childColumn == 1 && childRow == 0 )
156 else if ( childColumn == 0 && childRow == 1 )
158 else if ( childColumn == 1 && childRow == 1 )
161 const QVariant childNode = node.at( childIndex );
162 if ( childNode.userType() == QMetaType::Type::QVariantList )
164 node = childNode.toList();
165 column = tile.
column() * 2;
166 row = tile.
row() * 2;
172 const long long nodeInt = childNode.toLongLong( &ok );
176 QgsDebugError( u
"Found tile index node with unsupported value: %1"_s.arg( childNode.toString() ) );
178 else if ( nodeInt == 0 )
183 else if ( nodeInt == 1 )
189 else if ( nodeInt == 2 )
205 const QMap< int, QgsTileMatrix > tileMatrices =
mTileMatrices;
209 const auto it = tileMatrices.constFind(
id.zoomLevel() );
210 if ( it == tileMatrices.constEnd() )
214 if (
id.column() >= it->matrixWidth() ||
id.row() >= it->matrixHeight() )
@ Critical
Critical/error message.
@ Esri
No scale doubling, always rounds down when matching to available tile levels.
TileAvailability
Possible availability states for a tile within a tile matrix.
@ UseLowerZoomLevelTile
Tile is not available at the requested zoom level, it should be replaced by a tile from a lower zoom ...
@ NotAvailable
Tile is not available within the matrix, e.g. there is no content for the tile.
@ AvailableNoChildren
Tile is available within the matrix, and is known to have no children (ie no higher zoom level tiles ...
@ Available
Tile is available within the matrix.
static QgsCoordinateReferenceSystem convertSpatialReference(const QVariantMap &spatialReferenceMap)
Converts a spatial reference JSON definition to a QgsCoordinateReferenceSystem value.
Represents a coordinate reference system (CRS).
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
void addGoogleCrs84QuadTiles(int minimumZoom=0, int maximumZoom=14)
Adds tile matrices corresponding to the standard web mercator/GoogleCRS84Quad setup.
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system associated with the tiles.
std::function< Qgis::TileAvailability(QgsTileXYZ id) > mTileAvailabilityFunction
int minimumZoom() const
Returns the minimum zoom level for tiles present in the set.
QMap< int, QgsTileMatrix > mTileMatrices
int maximumZoom() const
Returns the maximum zoom level for tiles present in the set.
void addMatrix(const QgsTileMatrix &matrix)
Adds a matrix to the set.
void setRootMatrix(const QgsTileMatrix &matrix)
Sets the root tile matrix (usually corresponding to zoom level 0).
void setScaleToTileZoomMethod(Qgis::ScaleToTileZoomLevelMethod method)
Sets the scale to tile zoom method.
std::function< Qgis::TileAvailability(QgsTileXYZ id, QgsTileXYZ &replacement) > mTileReplacementFunction
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
void setScale(double scale)
Sets the scale denominator of the tile matrix.
static QgsTileMatrix fromCustomDef(int zoomLevel, const QgsCoordinateReferenceSystem &crs, const QgsPointXY &z0TopLeftPoint, double z0Dimension, int z0MatrixWidth=1, int z0MatrixHeight=1)
Returns a tile matrix for a specific CRS, top left point, zoom level 0 dimension in CRS units.
Stores coordinates of a tile in a tile matrix set.
int zoomLevel() const
Returns tile's zoom level (Z).
int column() const
Returns tile's column index (X).
int row() const
Returns tile's row index (Y).
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
bool fromEsriJson(const QVariantMap &json, const QVariantMap &rootTileMap=QVariantMap())
Initializes the tile structure settings from an ESRI REST VectorTileService json map.
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
#define QgsDebugError(str)