Skip to content

Commit bf73e2c

Browse files
committed
[BUGFIX][Server] Re-enable Transparent and Bgcolor parameter for GetMap
Fixed #15990 wms png transparency not honoured And add tests for transparent and bgcolor in GetMap and GetLegendGraphic
1 parent 3e2b4fc commit bf73e2c

11 files changed

Lines changed: 159 additions & 0 deletions

File tree

‎src/server/services/wms/qgswmsservertransitional.cpp‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ namespace QgsWms
16291629

16301630
QImage* theImage = nullptr;
16311631

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

17591760
mapSettings.setExtent( mapExtent );
1761+
1762+
/* Define the background color
1763+
* Transparent or colored
1764+
*/
1765+
//is format jpeg?
1766+
QString format = mParameters.value( QStringLiteral( "FORMAT" ) );
1767+
bool jpeg = format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0
1768+
|| format.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0
1769+
|| format.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0;
1770+
1771+
//transparent parameter
1772+
bool transparent = mParameters.value( QStringLiteral( "TRANSPARENT" ) ).compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
1773+
1774+
//background color
1775+
QString bgColorString = mParameters.value( "BGCOLOR" );
1776+
if ( bgColorString.startsWith( "0x", Qt::CaseInsensitive ) )
1777+
{
1778+
bgColorString.replace( 0, 2, "#" );
1779+
}
1780+
QColor backgroundColor;
1781+
backgroundColor.setNamedColor( bgColorString );
1782+
1783+
//set background color
1784+
if ( transparent && !jpeg )
1785+
{
1786+
mapSettings.setBackgroundColor( QColor( 0, 0, 0, 0 ) );
1787+
}
1788+
else if ( backgroundColor.isValid() )
1789+
{
1790+
mapSettings.setBackgroundColor( backgroundColor );
1791+
}
17601792
}
17611793

17621794
void QgsWmsServer::readLayersAndStyles( QStringList& layersList, QStringList& stylesList ) const

‎tests/src/python/test_qgsserver.py‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,80 @@ def test_getfeature_post(self):
409409
for id, req in tests:
410410
self.wfs_getfeature_post_compare(id, req)
411411

412+
def test_wms_getmap_basic(self):
413+
qs = "&".join(["%s=%s" % i for i in list({
414+
"MAP": urllib.parse.quote(self.projectPath),
415+
"SERVICE": "WMS",
416+
"VERSION": "1.1.1",
417+
"REQUEST": "GetMap",
418+
"LAYERS": "Country",
419+
"STYLES": "",
420+
"FORMAT": "image/png",
421+
"BBOX": "-16817707,-4710778,5696513,14587125",
422+
"HEIGHT": "500",
423+
"WIDTH": "500",
424+
"CRS": "EPSG:3857"
425+
}.items())])
426+
427+
r, h = self._result(self.server.handleRequest(qs))
428+
self._img_diff_error(r, h, "WMS_GetMap_Basic")
429+
430+
def test_wms_getmap_transparent(self):
431+
qs = "&".join(["%s=%s" % i for i in list({
432+
"MAP": urllib.parse.quote(self.projectPath),
433+
"SERVICE": "WMS",
434+
"VERSION": "1.1.1",
435+
"REQUEST": "GetMap",
436+
"LAYERS": "Country",
437+
"STYLES": "",
438+
"FORMAT": "image/png",
439+
"BBOX": "-16817707,-4710778,5696513,14587125",
440+
"HEIGHT": "500",
441+
"WIDTH": "500",
442+
"CRS": "EPSG:3857",
443+
"TRANSPARENT": "TRUE"
444+
}.items())])
445+
446+
r, h = self._result(self.server.handleRequest(qs))
447+
self._img_diff_error(r, h, "WMS_GetMap_Transparent")
448+
449+
def test_wms_getmap_background(self):
450+
qs = "&".join(["%s=%s" % i for i in list({
451+
"MAP": urllib.parse.quote(self.projectPath),
452+
"SERVICE": "WMS",
453+
"VERSION": "1.1.1",
454+
"REQUEST": "GetMap",
455+
"LAYERS": "Country",
456+
"STYLES": "",
457+
"FORMAT": "image/png",
458+
"BBOX": "-16817707,-4710778,5696513,14587125",
459+
"HEIGHT": "500",
460+
"WIDTH": "500",
461+
"CRS": "EPSG:3857",
462+
"BGCOLOR": "green"
463+
}.items())])
464+
465+
r, h = self._result(self.server.handleRequest(qs))
466+
self._img_diff_error(r, h, "WMS_GetMap_Background")
467+
468+
qs = "&".join(["%s=%s" % i for i in list({
469+
"MAP": urllib.parse.quote(self.projectPath),
470+
"SERVICE": "WMS",
471+
"VERSION": "1.1.1",
472+
"REQUEST": "GetMap",
473+
"LAYERS": "Country",
474+
"STYLES": "",
475+
"FORMAT": "image/png",
476+
"BBOX": "-16817707,-4710778,5696513,14587125",
477+
"HEIGHT": "500",
478+
"WIDTH": "500",
479+
"CRS": "EPSG:3857",
480+
"BGCOLOR": "0x008000"
481+
}.items())])
482+
483+
r, h = self._result(self.server.handleRequest(qs))
484+
self._img_diff_error(r, h, "WMS_GetMap_Background_Hex")
485+
412486
def test_wms_getmap_order(self):
413487
qs = "&".join(["%s=%s" % i for i in list({
414488
"MAP": urllib.parse.quote(self.projectPath),
@@ -699,6 +773,59 @@ def test_wms_GetLegendGraphic_Basic(self):
699773
r, h = self._result(self.server.handleRequest(qs))
700774
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Basic")
701775

776+
def test_wms_GetLegendGraphic_Transparent(self):
777+
qs = "&".join(["%s=%s" % i for i in list({
778+
"MAP": urllib.parse.quote(self.projectPath),
779+
"SERVICE": "WMS",
780+
"VERSION": "1.1.1",
781+
"REQUEST": "GetLegendGraphic",
782+
"LAYER": "Country,Hello",
783+
"LAYERTITLE": "FALSE",
784+
"FORMAT": "image/png",
785+
"HEIGHT": "500",
786+
"WIDTH": "500",
787+
"CRS": "EPSG:3857",
788+
"TRANSPARENT": "TRUE"
789+
}.items())])
790+
791+
r, h = self._result(self.server.handleRequest(qs))
792+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Transparent")
793+
794+
def test_wms_GetLegendGraphic_Background(self):
795+
qs = "&".join(["%s=%s" % i for i in list({
796+
"MAP": urllib.parse.quote(self.projectPath),
797+
"SERVICE": "WMS",
798+
"VERSION": "1.1.1",
799+
"REQUEST": "GetLegendGraphic",
800+
"LAYER": "Country,Hello",
801+
"LAYERTITLE": "FALSE",
802+
"FORMAT": "image/png",
803+
"HEIGHT": "500",
804+
"WIDTH": "500",
805+
"CRS": "EPSG:3857",
806+
"BGCOLOR": "green"
807+
}.items())])
808+
809+
r, h = self._result(self.server.handleRequest(qs))
810+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background")
811+
812+
qs = "&".join(["%s=%s" % i for i in list({
813+
"MAP": urllib.parse.quote(self.projectPath),
814+
"SERVICE": "WMS",
815+
"VERSION": "1.1.1",
816+
"REQUEST": "GetLegendGraphic",
817+
"LAYER": "Country,Hello",
818+
"LAYERTITLE": "FALSE",
819+
"FORMAT": "image/png",
820+
"HEIGHT": "500",
821+
"WIDTH": "500",
822+
"CRS": "EPSG:3857",
823+
"BGCOLOR": "0x008000"
824+
}.items())])
825+
826+
r, h = self._result(self.server.handleRequest(qs))
827+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background_Hex")
828+
702829
def test_wms_GetLegendGraphic_BoxSpace(self):
703830
qs = "&".join(["%s=%s" % i for i in list({
704831
"MAP": urllib.parse.quote(self.projectPath),
590 Bytes
Loading
590 Bytes
Loading
685 Bytes
Loading
190 Bytes
Loading
28.9 KB
Loading
28.9 KB
Loading
30.6 KB
Loading
32.3 KB
Loading

0 commit comments

Comments
 (0)