Skip to content
Permalink
Browse files
WMS Client - Fixes GetLegendGraphic in WMS 1.3.0
SLD_VERSION parameter is mandatory in GetLegendGraphic as specified by SLD version 1.1.0. This commit adds this parameter when requesting WMS services with version 1.3.0 or higher.

In addition to this it also fixes style parameter: in GetLegendGraphic it should be named STYLE and not STYLES.

Two new testcases has been added for the WMS client which will test GetLegendGraphic functionality for both WMS 1.1.1 and WMS 1.3.0.
  • Loading branch information
ravhed committed Nov 19, 2019
1 parent 8f2de5b commit e88939a0b844e7c9e70520eb3e69a99acbdb719b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
@@ -216,7 +216,7 @@ static char *msBuildURLFromWMSParams(wmsParamsObj *wmsparams)
* by the caller.
**********************************************************************/
static int msBuildWMSLayerURLBase(mapObj *map, layerObj *lp,
wmsParamsObj *psWMSParams)
wmsParamsObj *psWMSParams, int nRequestType)
{
const char *pszOnlineResource, *pszVersion, *pszName, *pszFormat;
const char *pszFormatList, *pszStyle, /* *pszStyleList,*/ *pszTime;
@@ -337,11 +337,14 @@ static int msBuildWMSLayerURLBase(mapObj *map, layerObj *lp,
}
}

/* set STYLES no matter what, even if it's empty (i.e. "STYLES=")
* styles is a required param of WMS
/* set STYLE parameter no matter what, even if it's empty (i.e. "STYLES=")
* GetLegendGraphic doesn't support multiple styles and is named STYLE
*/

msSetWMSParamString(psWMSParams, "STYLES", pszStyle, MS_TRUE, nVersion);
if (nRequestType == WMS_GETLEGENDGRAPHIC) {
msSetWMSParamString(psWMSParams, "STYLE", pszStyle, MS_TRUE, nVersion);
} else {
msSetWMSParamString(psWMSParams, "STYLES", pszStyle, MS_TRUE, nVersion);
}

if (pszSLD != NULL) {
/* Only SLD is set */
@@ -443,7 +446,7 @@ msBuildWMSLayerURL(mapObj *map, layerObj *lp, int nRequestType,
(pszVersion = strstr(lp->connection, "WMTVER=")) == NULL &&
(pszVersion = strstr(lp->connection, "wmtver=")) == NULL ) ) {
/* CONNECTION missing or seems incomplete... try to build from metadata */
if (msBuildWMSLayerURLBase(map, lp, psWMSParams) != MS_SUCCESS)
if (msBuildWMSLayerURLBase(map, lp, psWMSParams, nRequestType) != MS_SUCCESS)
return MS_FAILURE; /* An error already produced. */

/* If we received MS_SUCCESS then version must have been set */
@@ -859,6 +862,10 @@ msBuildWMSLayerURL(mapObj *map, layerObj *lp, int nRequestType,
msSetWMSParamString(psWMSParams, "REQUEST", pszRequestParam, MS_FALSE, nVersion);
msSetWMSParamString(psWMSParams, pszSrsParamName, pszEPSG, MS_FALSE, nVersion);

if (nVersion >= OWS_1_3_0) {
msSetWMSParamString(psWMSParams, "SLD_VERSION", "1.1.0", MS_FALSE, nVersion);
}

} else { /* if (nRequestType == WMS_GETMAP) */
char szBuf[100] = "";

@@ -159,12 +159,18 @@ def demime_file( filename ):
if version_info >= (3,0,0):
data = str(data, 'iso-8859-1')

offset = -1
for i in range(len(data)-1):
if data[i] == '\r' and data[i+1] == '\n' and data[i+2] == '\r' and data[i+3] == '\n':
offset = 4
elif data[i] == '\n' and data[i+1] == '\n':
offset = 2

if offset != -1:
if version_info >= (3,0,0):
open(filename,'wb').write(bytes(data[i+4:], 'iso-8859-1'))
open(filename,'wb').write(bytes(data[i+offset:], 'iso-8859-1'))
else:
open(filename,'wb').write(data[i+4:])
open(filename,'wb').write(data[i+offset:])
return
return

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -9,6 +9,8 @@
#
# GetFeatureInfo
# RUN_PARMS: wms_client_111.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=client&STYLES=&WIDTH=300&HEIGHT=200&FORMAT=image/png&SRS=EPSG:4326&BBOX=-180,-90,180,90&QUERY_LAYERS=client&I=100&J=150&INFO_FORMAT=text/html&FEATURE_COUNT=5" > [RESULT]
# GetLegendGraphic
# RUN_PARMS: wms_client_111_legendgraphic.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=client&FORMAT=image/png" > [RESULT_DEMIME]


MAP
@@ -9,6 +9,8 @@
#
# GetFeatureInfo
# RUN_PARMS: wms_client_130.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=client&STYLES=&WIDTH=300&HEIGHT=200&FORMAT=image/png&SRS=EPSG:4326&BBOX=-180,-90,180,90&QUERY_LAYERS=client&I=100&J=150&INFO_FORMAT=text/html&FEATURE_COUNT=5" > [RESULT]
# GetLegendGraphic
# RUN_PARMS: wms_client_130_legendgraphic.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&LAYER=client&FORMAT=image/png&TRANSPARENT=FALSE&SLD_VERSION=1.1.0" > [RESULT_DEMIME]


MAP

0 comments on commit e88939a

Please sign in to comment.