mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-09 00:08:52 -04:00
Merge pull request #9545 from signedav/getlegendgraphics_HEIGHTWIDTH
SRCHEIGHT/SRCWIDTH for GetLegendGraphic request
This commit is contained in:
commit
51ab846d8e
@ -363,6 +363,16 @@ namespace QgsWms
|
|||||||
QVariant( 0 ) );
|
QVariant( 0 ) );
|
||||||
save( pWidth );
|
save( pWidth );
|
||||||
|
|
||||||
|
const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT,
|
||||||
|
QVariant::Int,
|
||||||
|
QVariant( 0 ) );
|
||||||
|
save( pSrcHeight );
|
||||||
|
|
||||||
|
const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH,
|
||||||
|
QVariant::Int,
|
||||||
|
QVariant( 0 ) );
|
||||||
|
save( pSrcWidth );
|
||||||
|
|
||||||
const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
|
const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
|
||||||
save( pBbox );
|
save( pBbox );
|
||||||
|
|
||||||
@ -686,6 +696,26 @@ namespace QgsWms
|
|||||||
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
|
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsWmsParameters::srcHeight() const
|
||||||
|
{
|
||||||
|
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QgsWmsParameters::srcWidth() const
|
||||||
|
{
|
||||||
|
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QgsWmsParameters::srcHeightAsInt() const
|
||||||
|
{
|
||||||
|
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QgsWmsParameters::srcWidthAsInt() const
|
||||||
|
{
|
||||||
|
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
QString QgsWmsParameters::dpi() const
|
QString QgsWmsParameters::dpi() const
|
||||||
{
|
{
|
||||||
return mWmsParameters[ QgsWmsParameter::DPI ].toString();
|
return mWmsParameters[ QgsWmsParameter::DPI ].toString();
|
||||||
|
@ -176,7 +176,9 @@ namespace QgsWms
|
|||||||
WITH_MAPTIP,
|
WITH_MAPTIP,
|
||||||
WMTVER,
|
WMTVER,
|
||||||
ATLAS_PK,
|
ATLAS_PK,
|
||||||
FORMAT_OPTIONS
|
FORMAT_OPTIONS,
|
||||||
|
SRCWIDTH,
|
||||||
|
SRCHEIGHT
|
||||||
};
|
};
|
||||||
Q_ENUM( Name )
|
Q_ENUM( Name )
|
||||||
|
|
||||||
@ -390,6 +392,40 @@ namespace QgsWms
|
|||||||
*/
|
*/
|
||||||
int heightAsInt() const;
|
int heightAsInt() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SRCWIDTH parameter or an empty string if not defined.
|
||||||
|
* \returns srcWidth parameter
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
QString srcWidth() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SRCWIDTH parameter as an int or its default value if not
|
||||||
|
* defined. An exception is raised if SRCWIDTH is defined and cannot be
|
||||||
|
* converted.
|
||||||
|
* \returns srcWidth parameter
|
||||||
|
* \throws QgsBadRequestException
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
int srcWidthAsInt() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SRCHEIGHT parameter or an empty string if not defined.
|
||||||
|
* \returns srcHeight parameter
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
QString srcHeight() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns SRCHEIGHT parameter as an int or its default value if not
|
||||||
|
* defined. An exception is raised if SRCHEIGHT is defined and cannot be
|
||||||
|
* converted.
|
||||||
|
* \returns srcHeight parameter
|
||||||
|
* \throws QgsBadRequestException
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
int srcHeightAsInt() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns VERSION parameter if defined or its default value.
|
* Returns VERSION parameter if defined or its default value.
|
||||||
* \returns version
|
* \returns version
|
||||||
|
@ -187,7 +187,7 @@ namespace QgsWms
|
|||||||
if ( !mWmsParameters.bbox().isEmpty() )
|
if ( !mWmsParameters.bbox().isEmpty() )
|
||||||
{
|
{
|
||||||
QgsMapSettings mapSettings;
|
QgsMapSettings mapSettings;
|
||||||
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
|
image.reset( createImage( width(), height(), false ) );
|
||||||
configureMapSettings( image.get(), mapSettings );
|
configureMapSettings( image.get(), mapSettings );
|
||||||
legendSettings.setMapScale( mapSettings.scale() );
|
legendSettings.setMapScale( mapSettings.scale() );
|
||||||
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
|
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
|
||||||
@ -1123,10 +1123,10 @@ namespace QgsWms
|
|||||||
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
|
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
|
||||||
{
|
{
|
||||||
if ( width < 0 )
|
if ( width < 0 )
|
||||||
width = mWmsParameters.widthAsInt();
|
width = this->width();
|
||||||
|
|
||||||
if ( height < 0 )
|
if ( height < 0 )
|
||||||
height = mWmsParameters.heightAsInt();
|
height = this->height();
|
||||||
|
|
||||||
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
|
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
|
||||||
//Required by WMS spec. 1.3.
|
//Required by WMS spec. 1.3.
|
||||||
@ -1994,14 +1994,14 @@ namespace QgsWms
|
|||||||
{
|
{
|
||||||
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
|
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
|
||||||
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
|
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
|
||||||
int width = mWmsParameters.widthAsInt();
|
int width = this->width();
|
||||||
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
|
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
|
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
|
||||||
int height = mWmsParameters.heightAsInt();
|
int height = this->height();
|
||||||
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
|
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -3206,8 +3206,8 @@ namespace QgsWms
|
|||||||
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
|
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
|
||||||
// by WMS spec)
|
// by WMS spec)
|
||||||
QImage *scaledImage = nullptr;
|
QImage *scaledImage = nullptr;
|
||||||
int width = mWmsParameters.widthAsInt();
|
int width = this->width();
|
||||||
int height = mWmsParameters.heightAsInt();
|
int height = this->height();
|
||||||
if ( width != image->width() || height != image->height() )
|
if ( width != image->width() || height != image->height() )
|
||||||
{
|
{
|
||||||
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
||||||
@ -3418,4 +3418,22 @@ namespace QgsWms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int QgsRenderer::height() const
|
||||||
|
{
|
||||||
|
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
|
||||||
|
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
|
||||||
|
mWmsParameters.srcHeightAsInt() > 0 )
|
||||||
|
return mWmsParameters.srcHeightAsInt();
|
||||||
|
return mWmsParameters.heightAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QgsRenderer::width() const
|
||||||
|
{
|
||||||
|
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
|
||||||
|
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
|
||||||
|
mWmsParameters.srcWidthAsInt() > 0 )
|
||||||
|
return mWmsParameters.srcWidthAsInt();
|
||||||
|
return mWmsParameters.widthAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QgsWms
|
} // namespace QgsWms
|
||||||
|
@ -297,6 +297,20 @@ namespace QgsWms
|
|||||||
|
|
||||||
void handlePrintErrors( const QgsLayout *layout ) const;
|
void handlePrintErrors( const QgsLayout *layout ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns QgsWmsParameter SRCWIDTH if it's a GetLegendGraphics request and otherwise HEIGHT parameter
|
||||||
|
* \returns height parameter
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
int height() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns QgsWmsParameter SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
|
||||||
|
* \returns width parameter
|
||||||
|
* \since QGIS 3.8
|
||||||
|
*/
|
||||||
|
int width() const;
|
||||||
|
|
||||||
const QgsWmsParameters &mWmsParameters;
|
const QgsWmsParameters &mWmsParameters;
|
||||||
|
|
||||||
#ifdef HAVE_SERVER_PYTHON_PLUGINS
|
#ifdef HAVE_SERVER_PYTHON_PLUGINS
|
||||||
|
@ -460,6 +460,42 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ItemFont", max_size_diff=QSize(1, 1))
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ItemFont", max_size_diff=QSize(1, 1))
|
||||||
|
|
||||||
def test_wms_GetLegendGraphic_BBox(self):
|
def test_wms_GetLegendGraphic_BBox(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,db_point",
|
||||||
|
"LAYERTITLE": "FALSE",
|
||||||
|
"FORMAT": "image/png",
|
||||||
|
"SRCHEIGHT": "500",
|
||||||
|
"SRCWIDTH": "500",
|
||||||
|
"BBOX": "-151.7,-38.9,51.0,78.0",
|
||||||
|
"CRS": "EPSG:4326"
|
||||||
|
}.items())])
|
||||||
|
|
||||||
|
r, h = self._result(self._execute_request(qs))
|
||||||
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
||||||
|
|
||||||
|
def test_wms_GetLegendGraphic_BBox2(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,db_point",
|
||||||
|
"LAYERTITLE": "FALSE",
|
||||||
|
"FORMAT": "image/png",
|
||||||
|
"SRCHEIGHT": "500",
|
||||||
|
"SRCWIDTH": "500",
|
||||||
|
"BBOX": "-76.08,-6.4,-19.38,38.04",
|
||||||
|
"SRS": "EPSG:4326"
|
||||||
|
}.items())])
|
||||||
|
|
||||||
|
r, h = self._result(self._execute_request(qs))
|
||||||
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
|
||||||
|
|
||||||
|
def test_wms_GetLegendGraphic_BBox_Fallback(self):
|
||||||
qs = "?" + "&".join(["%s=%s" % i for i in list({
|
qs = "?" + "&".join(["%s=%s" % i for i in list({
|
||||||
"MAP": urllib.parse.quote(self.projectPath),
|
"MAP": urllib.parse.quote(self.projectPath),
|
||||||
"SERVICE": "WMS",
|
"SERVICE": "WMS",
|
||||||
@ -477,7 +513,7 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
r, h = self._result(self._execute_request(qs))
|
r, h = self._result(self._execute_request(qs))
|
||||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
||||||
|
|
||||||
def test_wms_GetLegendGraphic_BBox2(self):
|
def test_wms_GetLegendGraphic_BBox2_Fallback(self):
|
||||||
qs = "?" + "&".join(["%s=%s" % i for i in list({
|
qs = "?" + "&".join(["%s=%s" % i for i in list({
|
||||||
"MAP": urllib.parse.quote(self.projectPath),
|
"MAP": urllib.parse.quote(self.projectPath),
|
||||||
"SERVICE": "WMS",
|
"SERVICE": "WMS",
|
||||||
@ -503,8 +539,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "QGIS%20Server%20Hello%20World",
|
"LAYER": "QGIS%20Server%20Hello%20World",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "840",
|
"SRCHEIGHT": "840",
|
||||||
"WIDTH": "1226",
|
"SRCWIDTH": "1226",
|
||||||
"BBOX": "10.38450,-49.6370,73.8183,42.9461",
|
"BBOX": "10.38450,-49.6370,73.8183,42.9461",
|
||||||
"SRS": "EPSG:4326",
|
"SRS": "EPSG:4326",
|
||||||
"SCALE": "15466642"
|
"SCALE": "15466642"
|
||||||
@ -525,8 +561,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "QGIS%20Server%20-%20Grouped%20Layer",
|
"LAYER": "QGIS%20Server%20-%20Grouped%20Layer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "840",
|
"SRCHEIGHT": "840",
|
||||||
"WIDTH": "1226",
|
"SRCWIDTH": "1226",
|
||||||
"BBOX": "609152,5808188,625492,5814318",
|
"BBOX": "609152,5808188,625492,5814318",
|
||||||
"SRS": "EPSG:25832",
|
"SRS": "EPSG:25832",
|
||||||
"SCALE": "38976"
|
"SCALE": "38976"
|
||||||
@ -544,8 +580,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "All_grouped_layers",
|
"LAYER": "All_grouped_layers",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "840",
|
"SRCHEIGHT": "840",
|
||||||
"WIDTH": "1226",
|
"SRCWIDTH": "1226",
|
||||||
"BBOX": "609152,5808188,625492,5814318",
|
"BBOX": "609152,5808188,625492,5814318",
|
||||||
"SRS": "EPSG:25832",
|
"SRS": "EPSG:25832",
|
||||||
"SCALE": "38976"
|
"SCALE": "38976"
|
||||||
@ -563,8 +599,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "-608.4,-1002.6,698.2,1019.0",
|
"BBOX": "-608.4,-1002.6,698.2,1019.0",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
@ -579,8 +615,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "-1261.7,-2013.5,1351.5,2029.9",
|
"BBOX": "-1261.7,-2013.5,1351.5,2029.9",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
@ -596,8 +632,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "31.8,-12.0,58.0,28.4",
|
"BBOX": "31.8,-12.0,58.0,28.4",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
@ -613,8 +649,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "25.3,-22.1,64.5,38.5",
|
"BBOX": "25.3,-22.1,64.5,38.5",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
@ -630,8 +666,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "44.8,8.0,45.0,8.4",
|
"BBOX": "44.8,8.0,45.0,8.4",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
@ -646,8 +682,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
|||||||
"REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
"LAYER": "testlayer",
|
"LAYER": "testlayer",
|
||||||
"FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
"HEIGHT": "550",
|
"SRCHEIGHT": "550",
|
||||||
"WIDTH": "850",
|
"SRCWIDTH": "850",
|
||||||
"BBOX": "43.6,6.2,46.2,10.2",
|
"BBOX": "43.6,6.2,46.2,10.2",
|
||||||
"CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
}.items())])
|
}.items())])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user