Skip to content

Commit

Permalink
[BUGFIX][Server] Re-enable Transparent and Bgcolor parameter for GetMap
Browse files Browse the repository at this point in the history
Fixed #15990 wms png transparency not honoured

And add tests for transparent and bgcolor in GetMap and GetLegendGraphic
  • Loading branch information
rldhont committed Jan 11, 2017
1 parent 3e2b4fc commit bf73e2c
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/server/services/wms/qgswmsservertransitional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ namespace QgsWms

QImage* theImage = nullptr;

//Define the image background color in case of map settings is not used
//is format jpeg?
QString format = mParameters.value( QStringLiteral( "FORMAT" ) );
bool jpeg = format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0
Expand Down Expand Up @@ -1757,6 +1758,37 @@ namespace QgsWms
}

mapSettings.setExtent( mapExtent );

/* Define the background color
* Transparent or colored
*/
//is format jpeg?
QString format = mParameters.value( QStringLiteral( "FORMAT" ) );
bool jpeg = format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0
|| format.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0
|| format.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0;

//transparent parameter
bool transparent = mParameters.value( QStringLiteral( "TRANSPARENT" ) ).compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;

//background color
QString bgColorString = mParameters.value( "BGCOLOR" );
if ( bgColorString.startsWith( "0x", Qt::CaseInsensitive ) )
{
bgColorString.replace( 0, 2, "#" );
}
QColor backgroundColor;
backgroundColor.setNamedColor( bgColorString );

//set background color
if ( transparent && !jpeg )
{
mapSettings.setBackgroundColor( QColor( 0, 0, 0, 0 ) );
}
else if ( backgroundColor.isValid() )
{
mapSettings.setBackgroundColor( backgroundColor );
}
}

void QgsWmsServer::readLayersAndStyles( QStringList& layersList, QStringList& stylesList ) const
Expand Down
127 changes: 127 additions & 0 deletions tests/src/python/test_qgsserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,80 @@ def test_getfeature_post(self):
for id, req in tests:
self.wfs_getfeature_post_compare(id, req)

def test_wms_getmap_basic(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetMap_Basic")

def test_wms_getmap_transparent(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"TRANSPARENT": "TRUE"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetMap_Transparent")

def test_wms_getmap_background(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"BGCOLOR": "green"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetMap_Background")

qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"BGCOLOR": "0x008000"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetMap_Background_Hex")

def test_wms_getmap_order(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Expand Down Expand Up @@ -699,6 +773,59 @@ def test_wms_GetLegendGraphic_Basic(self):
r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Basic")

def test_wms_GetLegendGraphic_Transparent(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello",
"LAYERTITLE": "FALSE",
"FORMAT": "image/png",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"TRANSPARENT": "TRUE"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Transparent")

def test_wms_GetLegendGraphic_Background(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello",
"LAYERTITLE": "FALSE",
"FORMAT": "image/png",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"BGCOLOR": "green"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background")

qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello",
"LAYERTITLE": "FALSE",
"FORMAT": "image/png",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"BGCOLOR": "0x008000"
}.items())])

r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background_Hex")

def test_wms_GetLegendGraphic_BoxSpace(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bf73e2c

Please sign in to comment.