QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgswmsgetprint.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswmsgetprint.h
3 -------------------------
4 begin : December 20 , 2016
5 copyright : (C) 2007 by Marco Hugentobler (original code)
6 (C) 2014 by Alessandro Pasotti (original code)
7 (C) 2016 by David Marteau
8 email : marco dot hugentobler at karto dot baug dot ethz dot ch
9 a dot pasotti at itopen dot it
10 david dot marteau at 3liz dot com
11 ***************************************************************************/
12
13/***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 ***************************************************************************/
21#include "qgswmsutils.h"
22#include "qgswmsrequest.h"
23#include "qgswmsgetprint.h"
24#include "qgswmsrenderer.h"
26
27namespace QgsWms
28{
29 void writeGetPrint( QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response )
30 {
31 const QgsWmsParameters parameters = request.wmsParameters();
32
33 // GetPrint supports svg/png/pdf
34 const QgsWmsParameters::Format format = parameters.format();
35 QString contentType;
36 switch ( format )
37 {
39 contentType = QStringLiteral( "image/png" );
40 break;
42 contentType = QStringLiteral( "image/jpeg" );
43 break;
45 contentType = QStringLiteral( "image/svg+xml" );
46 break;
48 contentType = QStringLiteral( "application/pdf" );
49 break;
50 default:
52 break;
53 }
54
55 // prepare render context
56 QgsWmsRenderContext context( project, serverIface );
65 context.setParameters( parameters );
66 context.setSocketFeedback( response.feedback() );
67
68 // rendering
69 QgsRenderer renderer( context );
70 response.setHeader( QStringLiteral( "Content-Type" ), contentType );
71 response.write( renderer.getPrint() );
72 }
73} // namespace QgsWms
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual QgsFeedback * feedback() const
Returns the socket feedback if any.
Exception thrown in case of malformed request.
Map renderer for WMS requests.
QByteArray getPrint()
Returns printed page as binary.
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Format format() const
Returns format.
Format
Output format for the response.
Rendering context for the WMS renderer.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
void setSocketFeedback(QgsFeedback *feedback)
Sets the response feedback.
@ AddAllLayers
For GetPrint: add layers from LAYER(S) parameter.
Class defining request interface passed to WMS service.
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
Median cut implementation.
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetPrint response.