That's the appropriate work around at this point. Typically I'll put a few 
things that I know will always be present at the end. For example the if the 
query is triggered by a point query I prepend the x/y:

'point':{
    'epsg:26915': [[mapx], [mapy]],
    'epsg:4326': [[maplon], [maplat]]
  }

I also tend to use the nodtata attribute of the resultset tag to output a null 
value for the object if it wasn't found. That way each layer would *always* be 
represented in the output. Our devs preferred checking for a null as opposed to 
checking if a property exists. Not sure what the proper convention is but it 
seems to work for us at the expense of slightly larger responses. Here's an 
example from our service we have:

[resultset layer="ama" nodata="  'ama':null,"][feature]
  'ama':{
    'name':'[item name="unit_name"]',
    'id':'[item name="uniqueid" lc="true"]'
  },[/feature][/resultset]
[resultset layer="sna" nodata="  'sna':null,"][feature]
  'sna':{
    'name':'[item name="site_name"]',
    'id':'[item name="bremcode" lc="true"]',
    'url':'http://www.dnr.state.mn.us/snas/detail.html?id=[item name="bremcode" 
lc=true]'
  },[/feature][/resultset]

If the ama and sna layers return no results you'd see:

'sna':null,
'ama':null,

in the JSON response.

Oh, I believe any attribute in a template tag must use no quotes or double 
quotes, same goes for HTML legend templates since they use the same tag parser.

Steve

From: mapserver-users-boun...@lists.osgeo.org 
[mailto:mapserver-users-boun...@lists.osgeo.org] On Behalf Of Richard Greenwood
Sent: Tuesday, March 11, 2014 7:03 PM
To: mapserver
Subject: [mapserver-users] JSON template

The JSON template has [feature trimlast=","] for a single layer that may return 
multiple records, but I don't see that functionality for the whole JSON object. 
For example if I have two layers but only one returns results I end up with a 
trailing comma and invalid JSON.

// MapServer template
{
  [resultset layer=layer1]
  {
    [feature trimlast=","]
    { ... }
    [/feature]
  },   // might need to trim this comma if layer below doesn't return result
  [/resultset]

  [resultset layer=layer2]
  {
    [feature trimlast=","]
    { ... }
    [/feature]
  }   // no comma here because we think it's last result object
  [/resultset]
}
I can work around it by putting a comma and empty object at the end:
   ,{}
which is the way I've done it when writing JSON with standard templates, but 
that's sort of inconsistent with the [feature trimlast=","] option.
Am I missing anything? Should I file a feature enhancement request?
And trimlast="," does seem to need to require double, not single quotes.
Thanks,
Rich

--
Richard Greenwood
richard.greenw...@gmail.com<mailto:richard.greenw...@gmail.com>
www.greenwoodmap.com<http://www.greenwoodmap.com>
_______________________________________________
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

Reply via email to