mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-12 00:06:43 -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 "qgsmapserviceexception.h"
|
||||
#include "qgspallabeling.h"
|
||||
#include "qgsproject.h"
|
||||
#include "qgsrenderer.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
|
||||
|
@ -847,8 +847,6 @@ QImage* QgsWmsServer::getLegendGraphics()
|
||||
}
|
||||
QgsLayerTreeModel legendModel( &rootGroup );
|
||||
|
||||
QList<QgsLayerTreeNode*> rootChildren = rootGroup.children();
|
||||
|
||||
if ( scaleDenominator > 0 )
|
||||
legendModel.setLegendFilterByScale( scaleDenominator );
|
||||
|
||||
@ -889,7 +887,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
||||
}
|
||||
|
||||
// find out DPI
|
||||
QImage* tmpImage = createImage( 1, 1 );
|
||||
QImage* tmpImage = createImage( 1, 1, false );
|
||||
if ( !tmpImage )
|
||||
return nullptr;
|
||||
qreal dpmm = tmpImage->dotsPerMeterX() / 1000.0;
|
||||
@ -917,7 +915,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
||||
if ( !rule.isEmpty() )
|
||||
{
|
||||
//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
|
||||
QPainter p( paintImage );
|
||||
@ -939,6 +937,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
||||
return paintImage;
|
||||
}
|
||||
|
||||
QList<QgsLayerTreeNode*> rootChildren = rootGroup.children();
|
||||
Q_FOREACH ( QgsLayerTreeNode* node, rootChildren )
|
||||
{
|
||||
if ( QgsLayerTree::isLayer( node ) )
|
||||
@ -978,7 +977,7 @@ QImage* QgsWmsServer::getLegendGraphics()
|
||||
QSizeF minSize = legendRenderer.minimumSize();
|
||||
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 );
|
||||
p.setRenderHint( QPainter::Antialiasing, true );
|
||||
@ -1422,7 +1421,7 @@ QImage* QgsWmsServer::getMap( QgsMapSettings& mapSettings, HitTest* hitTest )
|
||||
QStringList highlightLayersId = QgsWmsConfigParser::addHighlightLayers( mParameters, layerSetIds );
|
||||
|
||||
QList<QgsMapLayer *> layerSet;
|
||||
Q_FOREACH( QString layerSetId, layerSetIds )
|
||||
Q_FOREACH ( QString layerSetId, layerSetIds )
|
||||
{
|
||||
layerSet.append( QgsProject::instance()->mapLayer( layerSetId ) );
|
||||
}
|
||||
@ -1967,7 +1966,7 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
|
||||
#endif
|
||||
|
||||
QList<QgsMapLayer *> layers;
|
||||
Q_FOREACH( QString layerId, layerIdList )
|
||||
Q_FOREACH ( QString layerId, layerIdList )
|
||||
{
|
||||
layers.append( QgsProject::instance()->mapLayer( layerId ) );
|
||||
}
|
||||
@ -1979,7 +1978,7 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
|
||||
return theImage;
|
||||
}
|
||||
|
||||
QImage* QgsWmsServer::createImage( int width, int height ) const
|
||||
QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const
|
||||
{
|
||||
bool conversionSuccess;
|
||||
|
||||
@ -2001,23 +2000,26 @@ QImage* QgsWmsServer::createImage( int width, int height ) const
|
||||
|
||||
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
|
||||
//Required by WMS spec. 1.3.
|
||||
bool bboxOk;
|
||||
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
|
||||
if ( bboxOk )
|
||||
if ( useBbox )
|
||||
{
|
||||
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
|
||||
double imageWidthHeightRatio = ( double )width / ( double )height;
|
||||
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
|
||||
bool bboxOk;
|
||||
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
|
||||
if ( bboxOk )
|
||||
{
|
||||
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
|
||||
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
|
||||
double imageWidthHeightRatio = ( double )width / ( double )height;
|
||||
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
|
||||
{
|
||||
//decrease image height
|
||||
height = width / mapWidthHeightRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
//decrease image width
|
||||
width = height * mapWidthHeightRatio;
|
||||
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
|
||||
{
|
||||
//decrease image height
|
||||
height = width / mapWidthHeightRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
//decrease image width
|
||||
width = height * mapWidthHeightRatio;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,8 +136,9 @@ class QgsWmsServer: public QgsOWSServer
|
||||
/** 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 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*/
|
||||
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
|
||||
HEIGHT, WIDTH, BBOX, CRS.
|
||||
|
@ -781,40 +781,41 @@ class TestQgsServer(unittest.TestCase):
|
||||
r, h = self._result(self.server.handleRequest(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_SymbolSize")
|
||||
|
||||
#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",
|
||||
# "HEIGHT": "500",
|
||||
# "WIDTH": "500",
|
||||
# "BBOX": "-151.7,-38.9,51.0,78.0",
|
||||
# "CRS": "EPSG:4326"
|
||||
# }.items())])
|
||||
# r, h = self._result(self.server.handleRequest(qs))
|
||||
# self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
||||
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",
|
||||
"HEIGHT": "500",
|
||||
"WIDTH": "500",
|
||||
"BBOX": "-151.7,-38.9,51.0,78.0",
|
||||
"CRS": "EPSG:4326"
|
||||
}.items())])
|
||||
|
||||
#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",
|
||||
# "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))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
|
||||
|
||||
# r, h = self._result(self.server.handleRequest(qs))
|
||||
# self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
|
||||
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",
|
||||
"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):
|
||||
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