mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
fix getLegendGraphics when BBox parameter is used
This commit is contained in:
parent
f3a5c98178
commit
8cda1bbb79
@ -24,7 +24,6 @@
|
|||||||
#include "qgsmaplayerstylemanager.h"
|
#include "qgsmaplayerstylemanager.h"
|
||||||
#include "qgsmapserviceexception.h"
|
#include "qgsmapserviceexception.h"
|
||||||
#include "qgspallabeling.h"
|
#include "qgspallabeling.h"
|
||||||
#include "qgsproject.h"
|
|
||||||
#include "qgsrenderer.h"
|
#include "qgsrenderer.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
|
|
||||||
|
@ -847,8 +847,6 @@ QImage* QgsWmsServer::getLegendGraphics()
|
|||||||
}
|
}
|
||||||
QgsLayerTreeModel legendModel( &rootGroup );
|
QgsLayerTreeModel legendModel( &rootGroup );
|
||||||
|
|
||||||
QList<QgsLayerTreeNode*> rootChildren = rootGroup.children();
|
|
||||||
|
|
||||||
if ( scaleDenominator > 0 )
|
if ( scaleDenominator > 0 )
|
||||||
legendModel.setLegendFilterByScale( scaleDenominator );
|
legendModel.setLegendFilterByScale( scaleDenominator );
|
||||||
|
|
||||||
@ -889,7 +887,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find out DPI
|
// find out DPI
|
||||||
QImage* tmpImage = createImage( 1, 1 );
|
QImage* tmpImage = createImage( 1, 1, false );
|
||||||
if ( !tmpImage )
|
if ( !tmpImage )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
qreal dpmm = tmpImage->dotsPerMeterX() / 1000.0;
|
qreal dpmm = tmpImage->dotsPerMeterX() / 1000.0;
|
||||||
@ -917,7 +915,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
|||||||
if ( !rule.isEmpty() )
|
if ( !rule.isEmpty() )
|
||||||
{
|
{
|
||||||
//create second image with the right dimensions
|
//create second image with the right dimensions
|
||||||
QImage* paintImage = createImage( ruleSymbolWidth, ruleSymbolHeight );
|
QImage* paintImage = createImage( ruleSymbolWidth, ruleSymbolHeight, false );
|
||||||
|
|
||||||
//go through the items a second time for painting
|
//go through the items a second time for painting
|
||||||
QPainter p( paintImage );
|
QPainter p( paintImage );
|
||||||
@ -939,6 +937,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
|||||||
return paintImage;
|
return paintImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QgsLayerTreeNode*> rootChildren = rootGroup.children();
|
||||||
Q_FOREACH ( QgsLayerTreeNode* node, rootChildren )
|
Q_FOREACH ( QgsLayerTreeNode* node, rootChildren )
|
||||||
{
|
{
|
||||||
if ( QgsLayerTree::isLayer( node ) )
|
if ( QgsLayerTree::isLayer( node ) )
|
||||||
@ -978,7 +977,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
|||||||
QSizeF minSize = legendRenderer.minimumSize();
|
QSizeF minSize = legendRenderer.minimumSize();
|
||||||
QSize s( minSize.width() * dpmm, minSize.height() * dpmm );
|
QSize s( minSize.width() * dpmm, minSize.height() * dpmm );
|
||||||
|
|
||||||
QImage* paintImage = createImage( s.width(), s.height() );
|
QImage* paintImage = createImage( s.width(), s.height(), false );
|
||||||
|
|
||||||
QPainter p( paintImage );
|
QPainter p( paintImage );
|
||||||
p.setRenderHint( QPainter::Antialiasing, true );
|
p.setRenderHint( QPainter::Antialiasing, true );
|
||||||
@ -1979,7 +1978,7 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
|
|||||||
return theImage;
|
return theImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage* QgsWmsServer::createImage( int width, int height ) const
|
QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const
|
||||||
{
|
{
|
||||||
bool conversionSuccess;
|
bool conversionSuccess;
|
||||||
|
|
||||||
@ -2001,6 +2000,8 @@ QImage* QgsWmsServer::createImage( int width, int height ) const
|
|||||||
|
|
||||||
//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.
|
||||||
|
if ( useBbox )
|
||||||
|
{
|
||||||
bool bboxOk;
|
bool bboxOk;
|
||||||
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
|
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
|
||||||
if ( bboxOk )
|
if ( bboxOk )
|
||||||
@ -2021,6 +2022,7 @@ QImage* QgsWmsServer::createImage( int width, int height ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( width < 0 || height < 0 )
|
if ( width < 0 || height < 0 )
|
||||||
{
|
{
|
||||||
|
@ -136,8 +136,9 @@ class QgsWmsServer: public QgsOWSServer
|
|||||||
/** Creates a QImage from the HEIGHT and WIDTH parameters
|
/** Creates a QImage from the HEIGHT and WIDTH parameters
|
||||||
@param width image width (or -1 if width should be taken from WIDTH wms parameter)
|
@param width image width (or -1 if width should be taken from WIDTH wms parameter)
|
||||||
@param height image height (or -1 if height should be taken from HEIGHT wms parameter)
|
@param height image height (or -1 if height should be taken from HEIGHT wms parameter)
|
||||||
|
@param useBbox flag to indicate if the BBOX has to be used to adapt aspect ratio
|
||||||
@return 0 in case of error*/
|
@return 0 in case of error*/
|
||||||
QImage* createImage( int width = -1, int height = -1 ) const;
|
QImage* createImage( int width = -1, int height = -1, bool useBbox = true ) const;
|
||||||
|
|
||||||
/** Configures mapSettings to the parameters
|
/** Configures mapSettings to the parameters
|
||||||
HEIGHT, WIDTH, BBOX, CRS.
|
HEIGHT, WIDTH, BBOX, CRS.
|
||||||
|
@ -781,40 +781,41 @@ class TestQgsServer(unittest.TestCase):
|
|||||||
r, h = self._result(self.server.handleRequest(qs))
|
r, h = self._result(self.server.handleRequest(qs))
|
||||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_SymbolSize")
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_SymbolSize")
|
||||||
|
|
||||||
#def test_wms_GetLegendGraphic_BBox(self):
|
def test_wms_GetLegendGraphic_BBox(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",
|
||||||
# "VERSION": "1.1.1",
|
"VERSION": "1.1.1",
|
||||||
# "REQUEST": "GetLegendGraphic",
|
"REQUEST": "GetLegendGraphic",
|
||||||
# "LAYER": "Country,Hello,db_point",
|
"LAYER": "Country,Hello,db_point",
|
||||||
# "LAYERTITLE": "FALSE",
|
"LAYERTITLE": "FALSE",
|
||||||
# "FORMAT": "image/png",
|
"FORMAT": "image/png",
|
||||||
# "HEIGHT": "500",
|
"HEIGHT": "500",
|
||||||
# "WIDTH": "500",
|
"WIDTH": "500",
|
||||||
# "BBOX": "-151.7,-38.9,51.0,78.0",
|
"BBOX": "-151.7,-38.9,51.0,78.0",
|
||||||
# "CRS": "EPSG:4326"
|
"CRS": "EPSG:4326"
|
||||||
# }.items())])
|
}.items())])
|
||||||
# r, h = self._result(self.server.handleRequest(qs))
|
|
||||||
# self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
|
||||||
|
|
||||||
#def test_wms_GetLegendGraphic_BBox2(self):
|
r, h = self._result(self.server.handleRequest(qs))
|
||||||
# qs = "&".join(["%s=%s" % i for i in list({
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
||||||
# "MAP": urllib.parse.quote(self.projectPath),
|
|
||||||
# "SERVICE": "WMS",
|
|
||||||
# "VERSION": "1.1.1",
|
|
||||||
# "REQUEST": "GetLegendGraphic",
|
|
||||||
# "LAYER": "Country,Hello,db_point",
|
|
||||||
# "LAYERTITLE": "FALSE",
|
|
||||||
# "FORMAT": "image/png",
|
|
||||||
# "HEIGHT": "500",
|
|
||||||
# "WIDTH": "500",
|
|
||||||
# #"BBOX": "-76.08,38.04,109.95,-6.4",
|
|
||||||
# "SRS": "EPSG:4326"
|
|
||||||
# }.items())])
|
|
||||||
|
|
||||||
# r, h = self._result(self.server.handleRequest(qs))
|
def test_wms_GetLegendGraphic_BBox2(self):
|
||||||
# self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
|
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",
|
||||||
|
"HEIGHT": "500",
|
||||||
|
"WIDTH": "500",
|
||||||
|
"BBOX": "-76.08,-6.4,-19.38,38.04",
|
||||||
|
"SRS": "EPSG:4326"
|
||||||
|
}.items())])
|
||||||
|
|
||||||
|
r, h = self._result(self.server.handleRequest(qs))
|
||||||
|
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
|
||||||
|
|
||||||
def _result(self, data):
|
def _result(self, data):
|
||||||
headers = {}
|
headers = {}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 625 B After Width: | Height: | Size: 862 B |
Binary file not shown.
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 625 B |
Loading…
x
Reference in New Issue
Block a user