Skip to content

Commit

Permalink
Allow adding AMS layers even if project has no CRS
Browse files Browse the repository at this point in the history
Fixes #38892
  • Loading branch information
m-kuhn committed Sep 20, 2020
1 parent 640f046 commit 7152e55
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5343,26 +5343,28 @@ QString QgisApp::crsAndFormatAdjustedLayerUri( const QString &uri, const QString

// Adjust layer CRS to project CRS
QgsCoordinateReferenceSystem testCrs;
const auto constSupportedCrs = supportedCrs;
for ( const QString &c : constSupportedCrs )

QRegularExpression crsRe( QStringLiteral( "crs=[^& ]+" ) );
for ( const QString &c : supportedCrs )
{
testCrs.createFromOgcWmsCrs( c );
if ( testCrs == mMapCanvas->mapSettings().destinationCrs() )
{
newuri.replace( QRegExp( "crs=[^&]+" ), "crs=" + c );
newuri.replace( crsRe, QStringLiteral( "crs=" ) + c );
QgsDebugMsg( QStringLiteral( "Changing layer crs to %1, new uri: %2" ).arg( c, uri ) );
break;
}
}

// Use the last used image format
QString lastImageEncoding = QgsSettings().value( QStringLiteral( "/qgis/lastWmsImageEncoding" ), "image/png" ).toString();
const auto constSupportedFormats = supportedFormats;
for ( const QString &fmt : constSupportedFormats )

QRegularExpression formatRe( QStringLiteral( "format=[^& ]+" ) );
for ( const QString &fmt : supportedFormats )
{
if ( fmt == lastImageEncoding )
{
newuri.replace( QRegExp( "format=[^&]+" ), "format=" + fmt );
newuri.replace( formatRe, QStringLiteral( "format=" ) + fmt );
QgsDebugMsg( QStringLiteral( "Changing layer format to %1, new uri: %2" ).arg( fmt, uri ) );
break;
}
Expand Down

0 comments on commit 7152e55

Please sign in to comment.