Skip to content

Commit

Permalink
Add basic support for hit test without calling getMap
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Apr 9, 2019
1 parent f482ddf commit ba14e14
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/server/services/wms/qgswmsgetlegendgraphics.cpp
Expand Up @@ -127,13 +127,33 @@ namespace QgsWms
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
}

if ( ! parameters.bbox().isEmpty() && parameters.bboxAsRectangle().isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
parameters[QgsWmsParameter::BBOX] );
}
}

QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree )
{
const QgsWmsParameters parameters = context.parameters();

std::unique_ptr<QgsLayerTreeModel> model( new QgsLayerTreeModel( &tree ) );

if ( context.scaleDenominator() > 0 )
{
model->setLegendFilterByScale( context.scaleDenominator() );
}

// content based legend
if ( ! parameters.bbox().isEmpty() )
{
QgsRenderer renderer( context );
const QgsRenderer::HitTest symbols = renderer.symbols();

// TODO
}

return model.release();
}

Expand Down
34 changes: 32 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -249,6 +249,36 @@ namespace QgsWms
r->stopRender( context );
}

QgsRenderer::HitTest QgsRenderer::symbols()
{
// check size
checkMaximumWidthHeight();

// init layer restorer before doing anything
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// configure layers
QgsMapSettings mapSettings;
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers, &mapSettings );

// create the output image and the painter
std::unique_ptr<QPainter> painter;
std::unique_ptr<QImage> image( createImage() );

// configure map settings (background, DPI, ...)
configureMapSettings( image.get(), mapSettings );

// add layers to map settings
mapSettings.setLayers( layers );

// run hit tests
HitTest symbols;
runHitTest( mapSettings, symbols );

return symbols;
}

QByteArray QgsRenderer::getPrint()
{
Expand Down Expand Up @@ -385,7 +415,7 @@ namespace QgsWms
std::unique_ptr<QImage> image( new QImage() );
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
// add layers to map settings
mapSettings.setLayers( layers );

// configure layout
Expand Down Expand Up @@ -751,7 +781,7 @@ namespace QgsWms
// configure map settings (background, DPI, ...)
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
// add layers to map settings
mapSettings.setLayers( layers );

// rendering step for layers
Expand Down
2 changes: 2 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -83,6 +83,8 @@ namespace QgsWms
typedef QSet<QString> SymbolSet;
typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;

HitTest symbols();

/**
* Returns the map as an image (or NULLPTR in case of error). The caller takes ownership
of the image object). If an instance to existing hit test structure is passed, instead of rendering
Expand Down

0 comments on commit ba14e14

Please sign in to comment.