Skip to content

Commit

Permalink
Handle on-the-fly reprojection correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 27, 2020
1 parent 9e80f59 commit 4744777
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/core/vectortile/qgsvectortilelayerrenderer.cpp
Expand Up @@ -149,9 +149,11 @@ void QgsVectorTileLayerRenderer::decodeAndDrawTile( const QgsVectorTileRawData &
if ( ctx.renderingStopped() )
return;

QgsCoordinateTransform ct = ctx.coordinateTransform();

QgsVectorTileRendererData tile( rawTile.id );
tile.setFeatures( decoder.layerFeatures( mPerLayerFields ) );
tile.setTilePolygon( QgsVectorTileUtils::tilePolygon( rawTile.id, mTileMatrix, ctx.mapToPixel() ) );
tile.setFeatures( decoder.layerFeatures( mPerLayerFields, ct ) );
tile.setTilePolygon( QgsVectorTileUtils::tilePolygon( rawTile.id, ct, mTileMatrix, ctx.mapToPixel() ) );

mTotalDecodeTime += tLoad.elapsed();

Expand Down
3 changes: 2 additions & 1 deletion src/core/vectortile/qgsvectortilemvtdecoder.cpp
Expand Up @@ -92,7 +92,7 @@ QStringList QgsVectorTileMVTDecoder::layerFieldNames( const QString &layerName )
return fieldNames;
}

QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString, QgsFields> &perLayerFields ) const
QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString, QgsFields> &perLayerFields, const QgsCoordinateTransform &ct ) const
{
QgsVectorTileFeatures features;

Expand Down Expand Up @@ -307,6 +307,7 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
}

f.setAttribute( "_geom_type", geomType );
f.geometry().transform( ct );

layerFeatures.append( f );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortilemvtdecoder.h
Expand Up @@ -47,7 +47,7 @@ class QgsVectorTileMVTDecoder
QStringList layerFieldNames( const QString &layerName ) const;

//! Returns decoded features grouped by sub-layers. It can only be called after a successful decode()
QgsVectorTileFeatures layerFeatures( const QMap<QString, QgsFields> &perLayerFields ) const;
QgsVectorTileFeatures layerFeatures( const QMap<QString, QgsFields> &perLayerFields, const QgsCoordinateTransform &ct ) const;

private:
vector_tile::Tile tile;
Expand Down
12 changes: 6 additions & 6 deletions src/core/vectortile/qgsvectortileutils.cpp
Expand Up @@ -33,13 +33,13 @@



QPolygon QgsVectorTileUtils::tilePolygon( QgsTileXYZ id, const QgsTileMatrix &tm, const QgsMapToPixel &mtp )
QPolygon QgsVectorTileUtils::tilePolygon( QgsTileXYZ id, const QgsCoordinateTransform &ct, const QgsTileMatrix &tm, const QgsMapToPixel &mtp )
{
QgsRectangle r = tm.tileExtent( id );
QgsPointXY p00a = mtp.transform( r.xMinimum(), r.yMinimum() );
QgsPointXY p11a = mtp.transform( r.xMaximum(), r.yMaximum() );
QgsPointXY p01a = mtp.transform( r.xMinimum(), r.yMaximum() );
QgsPointXY p10a = mtp.transform( r.xMaximum(), r.yMinimum() );
QgsPointXY p00a = mtp.transform( ct.transform( r.xMinimum(), r.yMinimum() ) );
QgsPointXY p11a = mtp.transform( ct.transform( r.xMaximum(), r.yMaximum() ) );
QgsPointXY p01a = mtp.transform( ct.transform( r.xMinimum(), r.yMaximum() ) );
QgsPointXY p10a = mtp.transform( ct.transform( r.xMaximum(), r.yMinimum() ) );
QPolygon path;
path << p00a.toQPointF().toPoint();
path << p01a.toQPointF().toPoint();
Expand Down Expand Up @@ -86,7 +86,7 @@ QgsVectorLayer *QgsVectorTileUtils::makeVectorLayerForTile( QgsVectorTileLayer *
QMap<QString, QgsFields> perLayerFields;
QgsFields fields = QgsVectorTileUtils::makeQgisFields( fieldNames );
perLayerFields[layerName] = fields;
QgsVectorTileFeatures data = decoder.layerFeatures( perLayerFields );
QgsVectorTileFeatures data = decoder.layerFeatures( perLayerFields, QgsCoordinateTransform() );
QgsFeatureList featuresList = data[layerName].toList();

// turn all geometries to geom. collections (otherwise they won't be accepted by memory provider)
Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortileutils.h
Expand Up @@ -50,7 +50,7 @@ class QgsVectorTileUtils
static void sortTilesByDistanceFromCenter( QVector<QgsTileXYZ> &tiles, const QPointF &center );

//! Returns polygon (made by four corners of the tile) in screen coordinates
static QPolygon tilePolygon( QgsTileXYZ id, const QgsTileMatrix &tm, const QgsMapToPixel &mtp );
static QPolygon tilePolygon( QgsTileXYZ id, const QgsCoordinateTransform &ct, const QgsTileMatrix &tm, const QgsMapToPixel &mtp );
//! Returns QgsFields instance based on the set of field names
static QgsFields makeQgisFields( QSet<QString> flds );
//! Finds best fitting zoom level (assuming GoogleCRS84Quad tile matrix set) given map scale denominator and allowed zoom level range
Expand Down

0 comments on commit 4744777

Please sign in to comment.