Skip to content

Commit

Permalink
[FEATURE]: Add legend url to wms capabilities. Patch from mlechner
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 22, 2014
1 parent 60dc15e commit d6535a8
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 67 deletions.
5 changes: 5 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ void QgsRasterLayerProperties::sync()
mRasterLayer->dataUrlFormat()
)
);

//layer attribution and metadataUrl
mLayerAttributionLineEdit->setText( mRasterLayer->attribution() );
mLayerAttributionUrlLineEdit->setText( mRasterLayer->attributionUrl() );
Expand All @@ -752,6 +753,8 @@ void QgsRasterLayerProperties::sync()
)
);

mLayerLegendUrlLineEdit->setText( mRasterLayer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex( mLayerLegendUrlFormatComboBox->findText( mRasterLayer->legendUrlFormat() ) );
} // QgsRasterLayerProperties::sync()

/*
Expand Down Expand Up @@ -925,6 +928,8 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setMetadataUrl( mLayerMetadataUrlLineEdit->text() );
mRasterLayer->setMetadataUrlType( mLayerMetadataUrlTypeComboBox->currentText() );
mRasterLayer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );
mRasterLayer->setLegendUrl( mLayerLegendUrlLineEdit->text() );
mRasterLayer->setLegendUrlFormat( mLayerLegendUrlFormatComboBox->currentText() );

// update symbology
emit refreshLegend( mRasterLayer->id(), false );
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
layer->metadataUrlFormat()
)
);
mLayerLegendUrlLineEdit->setText( layer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex(
mLayerLegendUrlFormatComboBox->findText(
layer->legendUrlFormat()
)
);
}

QSettings settings;
Expand Down Expand Up @@ -556,6 +562,8 @@ void QgsVectorLayerProperties::apply()
layer->setMetadataUrl( mLayerMetadataUrlLineEdit->text() );
layer->setMetadataUrlType( mLayerMetadataUrlTypeComboBox->currentText() );
layer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );
layer->setLegendUrl( mLayerLegendUrlLineEdit->text() );
layer->setLegendUrlFormat( mLayerLegendUrlFormatComboBox->currentText() );

//layer simplify drawing configuration
QgsVectorSimplifyMethod::SimplifyHints simplifyHints = QgsVectorSimplifyMethod::NoSimplification;
Expand Down
19 changes: 19 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
mDataUrlFormat = dataUrlElem.attribute( "format", "" );
}

//legendUrl
QDomElement legendUrlElem = layerElement.firstChildElement( "legendUrl" );
if ( !legendUrlElem.isNull() )
{
mLegendUrl = legendUrlElem.text();
mLegendUrlFormat = legendUrlElem.attribute( "format", "" );
}

//attribution
QDomElement attribElem = layerElement.firstChildElement( "attribution" );
if ( !attribElem.isNull() )
Expand Down Expand Up @@ -518,6 +526,17 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
layerElement.appendChild( layerDataUrl );
}

// layer legendUrl
QString aLegendUrl = legendUrl();
if ( !aLegendUrl.isEmpty() )
{
QDomElement layerLegendUrl = document.createElement( "legendUrl" ) ;
QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
layerLegendUrl.appendChild( layerLegendUrlText );
layerLegendUrl.setAttribute( "format", legendUrlFormat() );
layerElement.appendChild( layerLegendUrl );
}

// layer attribution
QString aAttribution = attribution();
if ( !aAttribution.isEmpty() )
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Return pointer to layer's undo stack */
QUndoStack *undoStack();

/* Layer legendUrl information */
void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
const QString& legendUrl() const { return mLegendUrl; }
void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
const QString& legendUrlFormat() const { return mLegendUrlFormat; }

/** @deprecated since 2.4 - returns NULL */
Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
/** @deprecated since 2.4 - caches listen to repaintRequested() signal to invalidate the cached image */
Expand Down Expand Up @@ -508,6 +514,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
QString mMetadataUrlType;
QString mMetadataUrlFormat;

/**WMS legend*/
QString mLegendUrl;
QString mLegendUrlFormat;

/** \brief Error */
QgsError mError;

Expand Down
82 changes: 82 additions & 0 deletions src/mapserver/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,70 @@ void QgsWMSProjectParser::addLayers( QDomDocument &doc,
styleTitleElem.appendChild( styleTitleText );
styleElem.appendChild( styleNameElem );
styleElem.appendChild( styleTitleElem );

// QString LegendURL for explicit layerbased GetLegendGraphic request
QDomElement getLayerLegendGraphicElem = doc.createElement( "LegendURL" );
QString hrefString = currentLayer->legendUrl();
bool customHrefString;
if ( !hrefString.isEmpty() )
{
customHrefString = true;
}
else
{
customHrefString = false;
hrefString = serviceUrl();
}
if ( hrefString.isEmpty() )
{
hrefString = getCapaServiceUrl( doc );
}
if ( !hrefString.isEmpty() )
{
QStringList getLayerLegendGraphicFormats;
if ( customHrefString == false )
{
getLayerLegendGraphicFormats << "image/png"; // << "jpeg" << "image/jpeg"

}
else
{
getLayerLegendGraphicFormats << currentLayer->legendUrlFormat();
}

for ( int i = 0; i < getLayerLegendGraphicFormats.size(); ++i )
{
QDomElement getLayerLegendGraphicFormatElem = doc.createElement( "Format" );
QString getLayerLegendGraphicFormat = getLayerLegendGraphicFormats[i];
QDomText getLayerLegendGraphicFormatText = doc.createTextNode( getLayerLegendGraphicFormat );
getLayerLegendGraphicFormatElem.appendChild( getLayerLegendGraphicFormatText );
getLayerLegendGraphicElem.appendChild( getLayerLegendGraphicFormatElem );
}

// no parameters on custom hrefUrl, because should link directly to graphic
if ( customHrefString == false )
{
QUrl mapUrl( hrefString );
mapUrl.addQueryItem( "SERVICE", "WMS" );
mapUrl.addQueryItem( "VERSION", version );
mapUrl.addQueryItem( "REQUEST", "GetLegendGraphic" );
mapUrl.addQueryItem( "LAYER", currentLayer->name() );
mapUrl.addQueryItem( "FORMAT", "image/png" );
mapUrl.addQueryItem( "STYLE", styleNameText.data() );
if ( version == "1.3.0" )
{
mapUrl.addQueryItem( "SLD_VERSION", "1.1.0" );
}
hrefString = mapUrl.toString();
}

QDomElement getLayerLegendGraphicORElem = doc.createElement( "OnlineResource" );
getLayerLegendGraphicORElem.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
getLayerLegendGraphicORElem.setAttribute( "xlink:type", "simple" );
getLayerLegendGraphicORElem.setAttribute( "xlink:href", hrefString );
getLayerLegendGraphicElem.appendChild( getLayerLegendGraphicORElem );
styleElem.appendChild( getLayerLegendGraphicElem );
}
layerElem.appendChild( styleElem );

//min/max scale denominatormScaleBasedVisibility
Expand Down Expand Up @@ -1802,3 +1866,21 @@ void QgsWMSProjectParser::cleanupTextAnnotationItems()
}
mTextAnnotationItems.clear();
}

QString QgsWMSProjectParser::getCapaServiceUrl( QDomDocument& doc ) const
{
QString url;
QDomNodeList getCapNodeList = doc.elementsByTagName( "GetCapabilities" );
if ( getCapNodeList.count() > 0 )
{
QDomElement getCapElem = getCapNodeList.at( 0 ).toElement();
QDomNodeList getCapORNodeList = getCapElem.elementsByTagName( "OnlineResource" );
if ( getCapORNodeList.count() > 0 )
{
url = getCapORNodeList.at( 0 ).toElement().attribute( "xlink:href", "" );
}

}

return url;
}
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class QgsWMSProjectParser: public QgsWMSConfigParser
void createSvgAnnotationItems();
void cleanupSvgAnnotationItems();
void cleanupTextAnnotationItems();

QString getCapaServiceUrl( QDomDocument& doc ) const;
};

#endif // QGSWMSPROJECTPARSER_H
Loading

0 comments on commit d6535a8

Please sign in to comment.