Skip to content

Commit

Permalink
[FEATURE]: Fetch geometry and maptip in feature info only if requeste…
Browse files Browse the repository at this point in the history
…d by the client
  • Loading branch information
mhugent committed Oct 26, 2017
1 parent 5261a9a commit 5bd63b7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -462,6 +462,20 @@ namespace QgsWms
QVariant()
};
save( pGridY );

const Parameter pWithGeometry = { ParameterName::WITH_GEOMETRY,
QVariant::Bool,
QVariant( false ),
QVariant()
};
save( pWithGeometry );

const Parameter pWithMapTip = { ParameterName::WITH_MAPTIP,
QVariant::Bool,
QVariant( false ),
QVariant()
};
save( pWithMapTip );
}

QgsWmsParameters::QgsWmsParameters( const QgsServerRequest::Parameters &parameters )
Expand Down Expand Up @@ -1908,6 +1922,16 @@ namespace QgsWms
return wmsUri.encodedUri();
}

bool QgsWmsParameters::withGeometry() const
{
return toBool( ParameterName::WITH_GEOMETRY );
}

bool QgsWmsParameters::withMapTip() const
{
return toBool( ParameterName::WITH_MAPTIP );
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
Expand Down
16 changes: 15 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Expand Up @@ -141,7 +141,9 @@ namespace QgsWms
EXTENT,
ROTATION,
GRID_INTERVAL_X,
GRID_INTERVAL_Y
GRID_INTERVAL_Y,
WITH_GEOMETRY,
WITH_MAPTIP
};
Q_ENUM( ParameterName )

Expand Down Expand Up @@ -916,6 +918,18 @@ namespace QgsWms
*/
QString externalWMSUri( const QString &id ) const;

/**
* @brief Returns if the client wants the feature info response with geometry information
* @return true if geometry information is requested for feature info response
*/
bool withGeometry() const;

/**
* @brief withMapTip
* @return true if maptip information is requested for feature info response
*/
bool withMapTip() const;

private:
QString name( ParameterName name ) const;
void raiseError( ParameterName name ) const;
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1426,7 +1426,7 @@ namespace QgsWms
int featureCounter = 0;
layer->updateFields();
const QgsFields &fields = layer->pendingFields();
bool addWktGeometry = QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject );
bool addWktGeometry = ( QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject ) && mWmsParameters.withGeometry() );
bool segmentizeWktGeometry = QgsServerProjectUtils::wmsFeatureInfoSegmentizeWktGeometry( *mProject );
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();

Expand Down Expand Up @@ -1578,7 +1578,7 @@ namespace QgsWms

//add maptip attribute based on html/expression (in case there is no maptip attribute)
QString mapTip = layer->mapTipTemplate();
if ( !mapTip.isEmpty() )
if ( !mapTip.isEmpty() && mWmsParameters.withMapTip() )
{
QDomElement maptipElem = infoDocument.createElement( QStringLiteral( "Attribute" ) );
maptipElem.setAttribute( QStringLiteral( "name" ), QStringLiteral( "maptip" ) );
Expand Down Expand Up @@ -2226,7 +2226,7 @@ namespace QgsWms
{
QString mapTip = layer->mapTipTemplate();

if ( !mapTip.isEmpty() )
if ( !mapTip.isEmpty() && mWmsParameters.withMapTip() )
{
QString fieldTextString = QgsExpression::replaceExpressionText( mapTip, &expressionContext );
QDomElement fieldElem = doc.createElement( QStringLiteral( "qgs:maptip" ) );
Expand Down

0 comments on commit 5bd63b7

Please sign in to comment.