Skip to content
Permalink
Browse files

[FEATURE]: Add legend url to wms capabilities. Patch from mlechner

  • Loading branch information
mhugent committed Apr 22, 2014
1 parent 60dc15e commit d6535a82bacafb5fcf601ff93154592ed043ac10
@@ -737,6 +737,7 @@ void QgsRasterLayerProperties::sync()
mRasterLayer->dataUrlFormat()
)
);

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

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

/*
@@ -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 );
@@ -248,6 +248,12 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
layer->metadataUrlFormat()
)
);
mLayerLegendUrlLineEdit->setText( layer->legendUrl() );
mLayerLegendUrlFormatComboBox->setCurrentIndex(
mLayerLegendUrlFormatComboBox->findText(
layer->legendUrlFormat()
)
);
}

QSettings settings;
@@ -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;
@@ -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() )
@@ -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() )
@@ -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 */
@@ -508,6 +514,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
QString mMetadataUrlType;
QString mMetadataUrlFormat;

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

/** \brief Error */
QgsError mError;

@@ -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
@@ -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;
}
@@ -146,6 +146,8 @@ class QgsWMSProjectParser: public QgsWMSConfigParser
void createSvgAnnotationItems();
void cleanupSvgAnnotationItems();
void cleanupTextAnnotationItems();

QString getCapaServiceUrl( QDomDocument& doc ) const;
};

#endif // QGSWMSPROJECTPARSER_H

0 comments on commit d6535a8

Please sign in to comment.
You can’t perform that action at this time.