Skip to content

Commit 8a93d2c

Browse files
author
mhugent
committedJan 31, 2011
Change getPrint syntax to use several parameters for composer maps, e.g. map0:extent=xmin,ymin,xmax,ymax or map0:rotation=45
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15111 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+53
-39
lines changed

1 file changed

+53
-39
lines changed
 

‎src/mapserver/qgsconfigparser.cpp

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -302,69 +302,83 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
302302
continue;
303303
}
304304

305-
//search composer map title in parameter map-> string
306-
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "MAP" + QString::number( currentMap->id() ) );
307-
if ( titleIt == parameterMap.constEnd() )
305+
QString mapId = "MAP" + QString::number( currentMap->id() );
306+
QMap< QString, QString >::const_iterator extentIt = parameterMap.find( mapId + ":EXTENT" );
307+
if ( extentIt == parameterMap.constEnd() ) //map extent is mandatory
308308
{
309309
//remove map from composition if not referenced by the request
310-
c->removeItem( *mapIt );
311-
delete( *mapIt );
312-
continue;
310+
c->removeItem( *mapIt ); delete( *mapIt ); continue;
311+
}
312+
313+
QStringList coordList = extentIt.value().split( "," );
314+
if ( coordList.size() < 4 )
315+
{
316+
c->removeItem( *mapIt ); delete( *mapIt ); continue; //need at least four coordinates
313317
}
314-
QString replaceString = titleIt.value();
315-
QStringList replacementList = replaceString.split( "/" );
316318

317-
//get map extent from string
318-
if ( replacementList.size() > 0 )
319+
bool xMinOk, yMinOk, xMaxOk, yMaxOk;
320+
double xmin = coordList.at( 0 ).toDouble( &xMinOk );
321+
double ymin = coordList.at( 1 ).toDouble( &yMinOk );
322+
double xmax = coordList.at( 2 ).toDouble( &xMaxOk );
323+
double ymax = coordList.at( 3 ).toDouble( &yMaxOk );
324+
if ( !xMinOk || !yMinOk || !xMaxOk || !yMaxOk )
319325
{
320-
QStringList coordList = replacementList.at( 0 ).split( "," );
321-
if ( coordList.size() > 3 )
326+
c->removeItem( *mapIt ); delete( *mapIt ); continue;
327+
}
328+
329+
//Change x- and y- of extent for WMS 1.3.0 and geographic coordinate systems
330+
QMap<QString, QString>::const_iterator versionIt = parameterMap.find( "VERSION" );
331+
if ( versionIt != parameterMap.end() )
332+
{
333+
if ( mapRenderer && versionIt.value() == "1.3.0" && mapRenderer->destinationSrs().geographicFlag() )
322334
{
323-
bool xMinOk, yMinOk, xMaxOk, yMaxOk;
324-
double xmin = coordList.at( 0 ).toDouble( &xMinOk );
325-
double ymin = coordList.at( 1 ).toDouble( &yMinOk );
326-
double xmax = coordList.at( 2 ).toDouble( &xMaxOk );
327-
double ymax = coordList.at( 3 ).toDouble( &yMaxOk );
328-
if ( xMinOk && yMinOk && xMaxOk && yMaxOk )
329-
{
330-
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
331-
}
335+
//switch coordinates of extent
336+
double tmp;
337+
tmp = xmin;
338+
xmin = ymin; ymin = tmp;
339+
tmp = xmax;
340+
xmax = ymax; ymax = tmp;
332341
}
333342
}
343+
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
334344

335-
//get rotation from string
336-
if ( replacementList.size() > 1 )
345+
//scale
346+
QMap< QString, QString >::const_iterator scaleIt = parameterMap.find( mapId + ":SCALE" );
347+
if ( scaleIt != parameterMap.constEnd() )
337348
{
338-
bool rotationOk;
339-
double rotation = replacementList.at( 1 ).toDouble( &rotationOk );
340-
if ( rotationOk )
349+
bool scaleOk;
350+
double scale = scaleIt->toDouble( &scaleOk );
351+
if ( scaleOk )
341352
{
342-
currentMap->setMapRotation( rotation );
353+
currentMap->setNewScale( scale );
343354
}
344355
}
345356

346-
//get forced scale from string
347-
if ( replacementList.size() > 2 )
357+
//rotation
358+
QMap< QString, QString >::const_iterator rotationIt = parameterMap.find( mapId + ":ROTATION" );
359+
if ( rotationIt != parameterMap.constEnd() )
348360
{
349-
bool conversionOk;
350-
double scale = replacementList.at( 2 ).toDouble( &conversionOk );
351-
if ( conversionOk )
361+
bool rotationOk;
362+
double rotation = rotationIt->toDouble( &rotationOk );
363+
if ( rotationOk )
352364
{
353-
currentMap->setNewScale( scale );
365+
currentMap->setMapRotation( rotation );
354366
}
355367
}
356368

357-
//get layer list from string
358-
if ( replacementList.size() > 3 )
369+
//layers / styles
370+
QMap< QString, QString >::const_iterator layersIt = parameterMap.find( mapId + ":LAYERS" );
371+
QMap< QString, QString >::const_iterator stylesIt = parameterMap.find( mapId + ":STYLES" );
372+
if ( layersIt != parameterMap.constEnd() )
359373
{
360374
QStringList layerSet;
361-
QStringList wmsLayerList = replacementList.at( 3 ).split( "," );
375+
QStringList wmsLayerList = layersIt->split( "," );
362376
QStringList wmsStyleList;
363-
if ( replacementList.size() > 4 )
377+
378+
if ( stylesIt != parameterMap.constEnd() )
364379
{
365-
wmsStyleList = replacementList.at( 4 ).split( "," );
380+
wmsStyleList = stylesIt->split( "," );
366381
}
367-
368382
for ( int i = 0; i < wmsLayerList.size(); ++i )
369383
{
370384
QString styleName;

0 commit comments

Comments
 (0)
Please sign in to comment.