Skip to content
Permalink
Browse files

Fix #9306 and getStyles

  • Loading branch information
elpaso committed Jan 7, 2014
1 parent 25cdea1 commit bd77ecc26c81132eecc30d2635bbc84786a184f6
@@ -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
{
@@ -795,3 +795,4 @@ int main( int argc, char * argv[] )
QgsDebugMsg( "************* all done ***************" );
return 0;
}

@@ -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;
}


@@ -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;
}

@@ -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" );
@@ -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();

0 comments on commit bd77ecc

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