Skip to content
Permalink
Browse files
Add a new 'padding' template format option (#5890)
  • Loading branch information
geographika authored and rouault committed Oct 9, 2019
1 parent 7506203 commit 84e0ce8e4e8a5e97111a69966f1fc11eddfb3c0a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
@@ -1209,6 +1209,7 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
const char *name=NULL, *pattern=NULL;
const char *format=NULL, *nullFormat=NULL;
int precision;
int padding;
int uc, lc, commify;
int escape;

@@ -1224,7 +1225,8 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
while (tagStart) {
format = "$value"; /* initialize the tag arguments */
nullFormat = "";
precision=-1;
precision = -1;
padding = -1;
name = pattern = NULL;
uc = lc = commify = MS_FALSE;
escape=ESCAPE_HTML;
@@ -1241,6 +1243,9 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
argValue = msLookupHashTable(tagArgs, "precision");
if(argValue) precision = atoi(argValue);

argValue = msLookupHashTable(tagArgs, "padding");
if (argValue) padding = atoi(argValue);

argValue = msLookupHashTable(tagArgs, "format");
if(argValue) format = argValue;

@@ -1310,6 +1315,15 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
tagValue = msReplaceSubstring(tagValue, "$value", itemValue);
msFree(itemValue);

if (padding > 0 && padding < 1000) {
int paddedSize = strlen(tagValue) + padding + 1;
char *paddedValue = NULL;
paddedValue = (char *) msSmallMalloc(paddedSize);
snprintf(paddedValue, paddedSize, "%-*s", padding, tagValue);
msFree(tagValue);
tagValue = paddedValue;
}

if(!tagValue) {
msSetError(MS_WEBERR, "Error applying item format.", "processItemTag()");
return(MS_FAILURE); /* todo leaking... */
@@ -0,0 +1,2 @@
ST. LOUIS :stlo

@@ -39,6 +39,9 @@
# Test 12: simple mode=indexquery, one layer, index query
# RUN_PARMS: query_test012.txt [MAPSERV] QUERY_STRING='map=[MAPFILE]&mode=indexquery&mapext=420000+5120000+582000+5200000&qlayer=bdry_counpy2&shapeindex=5' > [RESULT_DEMIME]
#
# Test 13: simple mode=indexquery, one layer, index query, with formatting
# RUN_PARMS: query_test013.txt [MAPSERV] QUERY_STRING='map=[MAPFILE]&mode=indexquery&mapext=420000+5120000+582000+5200000&qlayer=bdry_counpy2&shapeindex=5&qformat=formattmpl' > [RESULT_DEMIME]
#

MAP
NAME 'query'
@@ -56,6 +59,13 @@ MAP
FORMATOPTION "FILE=template/query.tmpl"
END

OUTPUTFORMAT
NAME 'formattmpl'
DRIVER 'TEMPLATE'
MIMETYPE 'text/html'
FORMATOPTION "FILE=template/query_formatted.tmpl"
END

LAYER
NAME 'bdry_counpy2'
VALIDATION
@@ -0,0 +1,3 @@
<!-- MapServer Template -->
[resultset layer="bdry_counpy2"][feature][item name="cty_name" padding="20" uc="true"]:[item name="cty_abbr" lc="true" padding="10"][/feature][/resultset]

0 comments on commit 84e0ce8

Please sign in to comment.