Skip to content

Commit e88939a

Browse files
committed
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.
1 parent 8f2de5b commit e88939a

6 files changed

Lines changed: 25 additions & 8 deletions

File tree

mapwmslayer.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static char *msBuildURLFromWMSParams(wmsParamsObj *wmsparams)
216216
* by the caller.
217217
**********************************************************************/
218218
static int msBuildWMSLayerURLBase(mapObj *map, layerObj *lp,
219-
wmsParamsObj *psWMSParams)
219+
wmsParamsObj *psWMSParams, int nRequestType)
220220
{
221221
const char *pszOnlineResource, *pszVersion, *pszName, *pszFormat;
222222
const char *pszFormatList, *pszStyle, /* *pszStyleList,*/ *pszTime;
@@ -337,11 +337,14 @@ static int msBuildWMSLayerURLBase(mapObj *map, layerObj *lp,
337337
}
338338
}
339339

340-
/* set STYLES no matter what, even if it's empty (i.e. "STYLES=")
341-
* styles is a required param of WMS
340+
/* set STYLE parameter no matter what, even if it's empty (i.e. "STYLES=")
341+
* GetLegendGraphic doesn't support multiple styles and is named STYLE
342342
*/
343-
344-
msSetWMSParamString(psWMSParams, "STYLES", pszStyle, MS_TRUE, nVersion);
343+
if (nRequestType == WMS_GETLEGENDGRAPHIC) {
344+
msSetWMSParamString(psWMSParams, "STYLE", pszStyle, MS_TRUE, nVersion);
345+
} else {
346+
msSetWMSParamString(psWMSParams, "STYLES", pszStyle, MS_TRUE, nVersion);
347+
}
345348

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

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

865+
if (nVersion >= OWS_1_3_0) {
866+
msSetWMSParamString(psWMSParams, "SLD_VERSION", "1.1.0", MS_FALSE, nVersion);
867+
}
868+
862869
} else { /* if (nRequestType == WMS_GETMAP) */
863870
char szBuf[100] = "";
864871

msautotest/pymod/mstestlib.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ def demime_file( filename ):
159159
if version_info >= (3,0,0):
160160
data = str(data, 'iso-8859-1')
161161

162+
offset = -1
162163
for i in range(len(data)-1):
163164
if data[i] == '\r' and data[i+1] == '\n' and data[i+2] == '\r' and data[i+3] == '\n':
165+
offset = 4
166+
elif data[i] == '\n' and data[i+1] == '\n':
167+
offset = 2
168+
169+
if offset != -1:
164170
if version_info >= (3,0,0):
165-
open(filename,'wb').write(bytes(data[i+4:], 'iso-8859-1'))
171+
open(filename,'wb').write(bytes(data[i+offset:], 'iso-8859-1'))
166172
else:
167-
open(filename,'wb').write(data[i+4:])
173+
open(filename,'wb').write(data[i+offset:])
168174
return
169175
return
170176

3.36 KB
Loading
3.36 KB
Loading

msautotest/wxs/wms_client_111.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#
1010
# GetFeatureInfo
1111
# 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]
12+
# GetLegendGraphic
13+
# 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]
1214

1315

1416
MAP

msautotest/wxs/wms_client_130.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#
1010
# GetFeatureInfo
1111
# 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]
12+
# GetLegendGraphic
13+
# 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]
1214

1315

1416
MAP

0 commit comments

Comments
 (0)