Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable relative URL on SLD ExternalGraphic
  • Loading branch information
github-actions[bot] committed Jun 4, 2020
1 parent 9919ed8 commit 015bfc5
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
1 change: 1 addition & 0 deletions mapcopy.c
Expand Up @@ -1217,6 +1217,7 @@ int msCopyMap(mapObj *dst, mapObj *src)
MS_COPYSTELEM(resolution);
MS_COPYSTRING(dst->shapepath, src->shapepath);
MS_COPYSTRING(dst->mappath, src->mappath);
MS_COPYSTELEM(sldurl);

MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor));

Expand Down
1 change: 1 addition & 0 deletions mapfile.c
Expand Up @@ -5890,6 +5890,7 @@ int initMap(mapObj *map)
map->cellsize = 0;
map->shapepath = NULL;
map->mappath = NULL;
map->sldurl = NULL;

MS_INIT_COLOR(map->imagecolor, 255,255,255,255); /* white */

Expand Down
51 changes: 49 additions & 2 deletions mapogcsld.c
Expand Up @@ -72,6 +72,7 @@ int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer,
int nStatus = MS_FAILURE;

if (map && szURL) {
map->sldurl = (char*)szURL;
pszSLDTmpFile = msTmpFile(map, map->mappath, NULL, "sld.xml");
if (pszSLDTmpFile == NULL) {
pszSLDTmpFile = msTmpFile(map, NULL, NULL, "sld.xml" );
Expand Down Expand Up @@ -110,6 +111,7 @@ int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer,
if (pszSLDbuf)
nStatus = msSLDApplySLD(map, pszSLDbuf, iLayer, pszStyleLayerName, ppszLayerNames);
}
map->sldurl = NULL;
}

msFree(pszSLDbuf);
Expand Down Expand Up @@ -2255,19 +2257,64 @@ int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic,
if (psTmp && psTmp->psChild) {
pszURL = (char*)psTmp->psChild->pszValue;

char *symbolurl = NULL;
// Handle relative URL for ExternalGraphic
if (map->sldurl && !strstr(pszURL,"://"))
{
char *baseurl = NULL;
char *relpath = NULL;
symbolurl = malloc(sizeof(char)*MS_MAXPATHLEN);
if (pszURL[0] != '/') {
// Symbol file is relative to SLD file
// e.g. SLD : http://example.com/path/to/sld.xml
// and symbol: assets/symbol.svg
// lead to: http://example.com/path/to/assets/symbol.svg
baseurl = msGetPath(map->sldurl);
relpath = pszURL;
}
else
{
// Symbol file is relative to the root of SLD server
// e.g. SLD : http://example.com/path/to/sld.xml
// and symbol: /path/to/assets/symbol.svg
// lead to: http://example.com/path/to/assets/symbol.svg
baseurl = msStrdup(map->sldurl);
relpath = pszURL+1;
char * sep = strstr(baseurl,"://");
if (sep)
sep += 3;
else
sep = baseurl;
sep = strchr(sep,'/');
if (!sep)
sep = baseurl + strlen(baseurl);
sep[1] = '\0';
}
msBuildPath(symbolurl,baseurl,relpath);
msFree(baseurl);
}
else
{
// Absolute URL
// e.g. symbol: http://example.com/path/to/assets/symbol.svg
symbolurl = msStrdup(pszURL);
}

/* validate the ExternalGraphic parameter */
if(msValidateParameter(pszURL, msLookupHashTable(&(map->web.validation), "sld_external_graphic"),
if(msValidateParameter(symbolurl, msLookupHashTable(&(map->web.validation), "sld_external_graphic"),
NULL, NULL, NULL) != MS_SUCCESS) {
msSetError(MS_WEBERR, "SLD ExternalGraphic OnlineResource value fails to validate against sld_external_graphic VALIDATION", "mapserv()");
msFree(symbolurl);
return MS_FAILURE;
}


/*external symbols using http will be automaticallly downloaded. The file should be
saved in a temporary directory (msAddImageSymbol) #2305*/
psStyle->symbol = msGetSymbolIndex(&map->symbolset,
pszURL,
symbolurl,
MS_TRUE);
msFree(symbolurl);

if (psStyle->symbol > 0 && psStyle->symbol < map->symbolset.numsymbols)
psStyle->symbolname = msStrdup(map->symbolset.symbol[psStyle->symbol]->name);
Expand Down
4 changes: 4 additions & 0 deletions mapserver.h
Expand Up @@ -1902,6 +1902,10 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char

char *shapepath; /* where are the shape files located */
char *mappath; /* path of the mapfile, all path are relative to this path */
char *sldurl; // URL of SLD document as specified with "&SLD=..."
// WMS parameter. Currently this reference is used
// only in mapogcsld.c and has a NULL value
// outside that context.

#ifndef SWIG
paletteObj palette; /* holds a map palette */
Expand Down
55 changes: 55 additions & 0 deletions msautotest/sld/data/danube.sld
@@ -0,0 +1,55 @@
<StyledLayerDescriptor version="1.1.0">
<NamedLayer>
<Name>danube</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<LineSymbolizer>
<Stroke>
<SvgParameter name="stroke-width">5</SvgParameter>
<SvgParameter name="stroke">#0000FF</SvgParameter>
</Stroke>
</LineSymbolizer>
<LineSymbolizer>
<Stroke>
<GraphicStroke>
<Graphic>
<Size>10</Size>
<Mark>
<WellKnownName>circle</WellKnownName>
<Stroke>
<SvgParameter name="stroke">#FFFF00</SvgParameter>
<SvgParameter name="stroke-width">2</SvgParameter>
</Stroke>
</Mark>
</Graphic>
<Gap>80</Gap>
<InitialGap>40</InitialGap>
</GraphicStroke>
</Stroke>
</LineSymbolizer>
<LineSymbolizer>
<Stroke>
<GraphicStroke>
<Graphic>
<Size>30</Size>
<ExternalGraphic>
<OnlineResource xlink:type="simple" xlink:href="/sld/data/ship.svg" />
<!--
<OnlineResource xlink:type="simple" xlink:href="ship.svg" />
<OnlineResource xlink:type="simple" xlink:href="http://localhost:8000/sld/data/ship.svg" />
<OnlineResource xlink:type="simple" xlink:href="/sld/data/ship.svg" />
-->
<Format>image/svg+xml</Format>
</ExternalGraphic>
</Graphic>
<Gap>80</Gap>
<InitialGap>0</InitialGap>
</GraphicStroke>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Binary file added msautotest/sld/expected/sld_url_linemark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion msautotest/sld/linemark.map
Expand Up @@ -9,10 +9,14 @@
# RUN_PARMS: map_linemark.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=40,7,50,31&FORMAT=image/png&WIDTH=720&HEIGHT=300&LAYERS=bg,danube" > [RESULT_DEMIME]
#
#
# --- Reference output rendered with SLD
# --- Reference output rendered with SLD body
#
# RUN_PARMS: sld_linemark.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=40,7,50,31&FORMAT=image/png&WIDTH=720&HEIGHT=300&LAYERS=bg,danube&SLD_BODY=<StyledLayerDescriptor version=%221.1.0%22><NamedLayer><Name>danube</Name><UserStyle><FeatureTypeStyle><Rule><LineSymbolizer><Stroke><SvgParameter name=%22stroke-width%22>5</SvgParameter><SvgParameter name=%22stroke%22>#0000FF</SvgParameter></Stroke></LineSymbolizer><LineSymbolizer><Stroke><GraphicStroke><Graphic><Size>10</Size><Mark><WellKnownName>circle</WellKnownName><Stroke><SvgParameter name=%22stroke%22>#FFFF00</SvgParameter><SvgParameter name=%22stroke-width%22>2</SvgParameter></Stroke></Mark></Graphic><Gap>80</Gap><InitialGap>40</InitialGap></GraphicStroke></Stroke></LineSymbolizer><LineSymbolizer><Stroke><GraphicStroke><Graphic><Size>30</Size><ExternalGraphic><OnlineResource xlink:type=%22simple%22 xlink:href=%22http://localhost:8000/sld/data/ship.svg%22 /><Format>image/svg%2Bxml</Format></ExternalGraphic></Graphic><Gap>80</Gap><InitialGap>0</InitialGap></GraphicStroke></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>" > [RESULT_DEMIME]
#
# --- Reference output rendered with SLD URL
#
# RUN_PARMS: sld_url_linemark.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=40,7,50,31&FORMAT=image/png&WIDTH=720&HEIGHT=300&LAYERS=bg,danube&SLD=http://localhost:8000/sld/data/danube.sld" > [RESULT_DEMIME]
#



Expand Down

0 comments on commit 015bfc5

Please sign in to comment.