Skip to content

Commit

Permalink
Fix #9306 and getStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 7, 2014
1 parent 25cdea1 commit bd77ecc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/mapserver/qgis_map_serv.cpp
Expand Up @@ -712,7 +712,7 @@ int main( int argc, char * argv[] )
{
// GetStyles is only defined for WMS1.1.1/SLD1.0
if ( version != "1.1.1") {
theRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "GetStyles is only available in WMS version 1.1.1" ) );
theRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "GetStyles method is only available in WMS version 1.1.1" ) );
} else {
try
{
Expand Down Expand Up @@ -795,3 +795,4 @@ int main( int argc, char * argv[] )
QgsDebugMsg( "************* all done ***************" );
return 0;
}

48 changes: 46 additions & 2 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -1926,8 +1926,52 @@ QDomDocument QgsProjectParser::getStyle( const QString& styleName, const QString

QDomDocument QgsProjectParser::getStyles( QStringList& layerList ) const
{
QDomDocument myDocument = QDomDocument();
return myDocument;
QDomDocument myDocument = QDomDocument();

QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
myDocument.appendChild( header );

// Create the root element
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
root.setAttribute( "version", "1.1.0" );
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
root.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" );
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
myDocument.appendChild( root );

for ( int i = 0; i < layerList.size(); i++)
{
QString layerName;
QString typeName;
layerName = layerList.at( i );
typeName = layerName.replace(" ", "_");
QList<QgsMapLayer*> currentLayerList = mapLayerFromTypeName( typeName );
if ( currentLayerList.size() < 1 )
{
throw QgsMapServiceException( "Error", QString( "The layer for the TypeName '%1' is not found" ).arg( layerName ) );
}
for ( int j = 0; j < currentLayerList.size(); j++)
{
QgsMapLayer* currentLayer = currentLayerList.at( j );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( !layer )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( "Non-vector layers not supported yet" ) );
}
// Create the NamedLayer element
QDomElement namedLayerNode = myDocument.createElement( "NamedLayer" );
root.appendChild( namedLayerNode );

QString errorMsg;
if ( !layer->writeSld( namedLayerNode, myDocument, errorMsg ) )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( errorMsg ) );
}
}
}
return myDocument;
}


Expand Down
39 changes: 16 additions & 23 deletions src/mapserver/qgssldparser.cpp
Expand Up @@ -1412,33 +1412,26 @@ QDomDocument QgsSLDParser::getStyle( const QString& styleName, const QString& la
return styleDoc;
}

// TODO: support multiple layers
QDomDocument QgsSLDParser::getStyles( QStringList& layerList ) const
{
if ( layerList.size() < 1)
{
throw QgsMapServiceException( "LayerNotDefined", "Layer list is empty." );
}

// TODO: loop
QString layerName = layerList.at(0);

QDomElement userLayerElement = findUserLayerElement( layerName );

if ( userLayerElement.isNull() )
{
throw QgsMapServiceException( "LayerNotDefined", "Operation request is for a Layer not offered by the server." );
}

QDomElement userStyleElement = findUserStyleElement( userLayerElement, "" );

if ( userStyleElement.isNull() )
QDomDocument styleDoc;
for ( int i = 0; i < layerList.size(); i++)
{
throw QgsMapServiceException( "StyleNotDefined", "Operation request references a Style not offered by the server." );
QString layerName;
QString typeName;
layerName = layerList.at( i );
QDomElement userLayerElement = findUserLayerElement( layerName );
if ( userLayerElement.isNull() )
{
throw QgsMapServiceException( "LayerNotDefined", "Operation request is for a Layer not offered by the server." );
}
QDomNodeList userStyleList = userLayerElement.elementsByTagName( "UserStyle" );
for ( int j = 0; j < userStyleList.size(); j++)
{
QDomElement userStyleElement = userStyleList.item( i ).toElement();
styleDoc.appendChild( styleDoc.importNode( userStyleElement, true ) );
}
}

QDomDocument styleDoc;
styleDoc.appendChild( styleDoc.importNode( userStyleElement, true ) );
return styleDoc;
}

Expand Down
8 changes: 3 additions & 5 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -603,10 +603,8 @@ QDomDocument QgsWMSServer::getStyle()

// GetStyles is only defined for WMS1.1.1/SLD1.0
QDomDocument QgsWMSServer::getStyles()
{

QDomDocument doc;

{
QDomDocument doc;
if ( !mParameterMap.contains( "LAYERS" ) )
{
throw QgsMapServiceException( "LayerNotSpecified", "Layers is mandatory for GetStyles operation" );
Expand Down Expand Up @@ -2194,7 +2192,7 @@ void QgsWMSServer::applyOpacities( const QStringList& layerList, QList< QPair< Q
QList< QPair< QgsMapLayer*, int > > layerOpacityList;
QStringList::const_iterator oIt = opacityList.constBegin();
QStringList::const_iterator lIt = layerList.constBegin();
for ( ; oIt != opacityList.constEnd(); ++oIt, ++lIt )
for ( ; oIt != opacityList.constEnd() && lIt != layerList.constEnd(); ++oIt, ++lIt )
{
//get layer list for
int opacity = oIt->toInt();
Expand Down

0 comments on commit bd77ecc

Please sign in to comment.