Re: [mapserver-users] JSON template dependencies

2014-04-17 Thread Richard Greenwood
I've been struggling with the JSON template errors described in my April 3
email below. Initially I was blaming it on different computers. Now I think
it is related to the MIMETYPE in the OUTPUTFORMAT block. This block fails
with Malformed template name (dummy)

OUTPUTFORMAT
  NAME geojson
  DRIVER TEMPLATE
  MIMETYPE 'application/json; subtype=geojson'
  FORMATOPTION FILE=templates/json.js
END

this block works (mimetype is removed)

OUTPUTFORMAT
  NAME geojson
  DRIVER TEMPLATE
  FORMATOPTION FILE=templates/json.js
END

I'm still not 100% sure that I have this backed into a corner yet.

So is
   MIMETYPE 'application/json; subtype=geojson'
incorrect? I've tried various other mimetypes to specify JSON output and
all fail, however text/html works.

I don't understand the relationship between mimetype and a Malformed
template name. Why do I get that error for an invalid mimetype?

Thanks,
Rich





On Thu, Apr 3, 2014 at 8:33 AM, Richard Greenwood 
richard.greenw...@gmail.com wrote:

 I have two very similar computers. On one JSON templates work, the other
 not. The not-working one displays Malformed template name (dummy) where
 dummy is a non-existent file and the non-working version seems to ignore
 the OUTPUTFORMAT block. For example I can put invalid parameters in the
 block and they don't throw errors whereas on my working computer they do.

 So I'm wondering if there are any dependencies at either compile or run
 time that I'm missing. My working computer is Fedora with MapServer
 installed from a repo, my non-working computer is Amazon Linux (at Redhat
 derivative) with MapServer 6.0 and 6.2 built from source.

 Thanks,
 Rich

 --
 Richard Greenwood
 richard.greenw...@gmail.com
 www.greenwoodmap.com




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

Re: [mapserver-users] JSON template dependencies

2014-04-17 Thread Lime, Steve D (MNIT)
Hi Rich: Crap, I had meant to connect with your on this back when you first 
posted it.

I don’t think this is related to the MIMETYPE. I use an output format very 
similar to the you do. I think what’s happening is that MapServer doesn’t know 
to use the geojson output format and falls back to a template as defined in a 
layer in your mapfile. I’m guessing that at least one layer in your mapfile has 
“TEMPLATE ‘dummy’”.

There are at least two ways to set the query format. One is to set a default:

WEB
  QUERYFORMAT ‘geojson’
END

The other is dynamically via your service call or using a cgi parameter. What 
I’d recommend is setting a default in the web object and see if that fixes 
things.

Steve


From: mapserver-users-boun...@lists.osgeo.org 
[mailto:mapserver-users-boun...@lists.osgeo.org] On Behalf Of Richard Greenwood
Sent: Thursday, April 17, 2014 9:49 AM
To: mapserver
Subject: Re: [mapserver-users] JSON template dependencies

I've been struggling with the JSON template errors described in my April 3 
email below. Initially I was blaming it on different computers. Now I think it 
is related to the MIMETYPE in the OUTPUTFORMAT block. This block fails with 
Malformed template name (dummy)

OUTPUTFORMAT
  NAME geojson
  DRIVER TEMPLATE
  MIMETYPE 'application/json; subtype=geojson'
  FORMATOPTION FILE=templates/json.js
END
this block works (mimetype is removed)

OUTPUTFORMAT
  NAME geojson
  DRIVER TEMPLATE
  FORMATOPTION FILE=templates/json.js
END
I'm still not 100% sure that I have this backed into a corner yet.

So is
   MIMETYPE 'application/json; subtype=geojson'
incorrect? I've tried various other mimetypes to specify JSON output and all 
fail, however text/html works.
I don't understand the relationship between mimetype and a Malformed template 
name. Why do I get that error for an invalid mimetype?
Thanks,
Rich



On Thu, Apr 3, 2014 at 8:33 AM, Richard Greenwood 
richard.greenw...@gmail.commailto:richard.greenw...@gmail.com wrote:
I have two very similar computers. On one JSON templates work, the other not. 
The not-working one displays Malformed template name (dummy) where dummy is 
a non-existent file and the non-working version seems to ignore the 
OUTPUTFORMAT block. For example I can put invalid parameters in the block and 
they don't throw errors whereas on my working computer they do.
So I'm wondering if there are any dependencies at either compile or run time 
that I'm missing. My working computer is Fedora with MapServer installed from a 
repo, my non-working computer is Amazon Linux (at Redhat derivative) with 
MapServer 6.0 and 6.2 built from source.
Thanks,
Rich

--
Richard Greenwood
richard.greenw...@gmail.commailto:richard.greenw...@gmail.com
www.greenwoodmap.comhttp://www.greenwoodmap.com



--
Richard Greenwood
richard.greenw...@gmail.commailto:richard.greenw...@gmail.com
www.greenwoodmap.comhttp://www.greenwoodmap.com
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

Re: [mapserver-users] JSON template dependencies

2014-04-17 Thread Richard Greenwood
Steve,

Adding

  WEB

QUERYFORMAT ‘geojson’
  END
Seems to do the trick although I need to test a little more. I've really
been chasing my tail around on this one.

And yes, all of my layers have a TEMPLATE dummy. That seems to be
required based on both the documentation and my experience.

I don't see any mention of QUERYFORMAT ‘geojson’ in the documentation at
http://mapserver.org/output/template_output.html
should I file a ticket, or am I just looking in the wrong place?

Thanks Steve!

Rich



On Thu, Apr 17, 2014 at 9:29 AM, Lime, Steve D (MNIT) 
steve.l...@state.mn.us wrote:

  Hi Rich: Crap, I had meant to connect with your on this back when you
 first posted it.



 I don’t think this is related to the MIMETYPE. I use an output format very
 similar to the you do. I think what’s happening is that MapServer doesn’t
 know to use the geojson output format and falls back to a template as
 defined in a layer in your mapfile. I’m guessing that at least one layer in
 your mapfile has “TEMPLATE ‘dummy’”.



 There are at least two ways to set the query format. One is to set a
 default:



 WEB

   QUERYFORMAT ‘geojson’

 END



 The other is dynamically via your service call or using a cgi parameter.
 What I’d recommend is setting a default in the web object and see if that
 fixes things.



 Steve





 *From:* mapserver-users-boun...@lists.osgeo.org [mailto:
 mapserver-users-boun...@lists.osgeo.org] *On Behalf Of *Richard Greenwood
 *Sent:* Thursday, April 17, 2014 9:49 AM
 *To:* mapserver
 *Subject:* Re: [mapserver-users] JSON template dependencies



 I've been struggling with the JSON template errors described in my April 3
 email below. Initially I was blaming it on different computers. Now I think
 it is related to the MIMETYPE in the OUTPUTFORMAT block. This block fails
 with Malformed template name (dummy)

 OUTPUTFORMAT
   NAME geojson
   DRIVER TEMPLATE
   MIMETYPE 'application/json; subtype=geojson'
   FORMATOPTION FILE=templates/json.js
 END

 this block works (mimetype is removed)


 OUTPUTFORMAT
   NAME geojson
   DRIVER TEMPLATE
   FORMATOPTION FILE=templates/json.js
 END

 I'm still not 100% sure that I have this backed into a corner yet.

 So is
MIMETYPE 'application/json; subtype=geojson'

 incorrect? I've tried various other mimetypes to specify JSON output and
 all fail, however text/html works.

 I don't understand the relationship between mimetype and a Malformed
 template name. Why do I get that error for an invalid mimetype?

 Thanks,
 Rich







 On Thu, Apr 3, 2014 at 8:33 AM, Richard Greenwood 
 richard.greenw...@gmail.com wrote:

 I have two very similar computers. On one JSON templates work, the other
 not. The not-working one displays Malformed template name (dummy) where
 dummy is a non-existent file and the non-working version seems to ignore
 the OUTPUTFORMAT block. For example I can put invalid parameters in the
 block and they don't throw errors whereas on my working computer they do.

 So I'm wondering if there are any dependencies at either compile or run
 time that I'm missing. My working computer is Fedora with MapServer
 installed from a repo, my non-working computer is Amazon Linux (at Redhat
 derivative) with MapServer 6.0 and 6.2 built from source.

 Thanks,
 Rich


 --
 Richard Greenwood
 richard.greenw...@gmail.com
 www.greenwoodmap.com




 --
 Richard Greenwood
 richard.greenw...@gmail.com
 www.greenwoodmap.com




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

[mapserver-users] JSON template dependencies

2014-04-03 Thread Richard Greenwood
I have two very similar computers. On one JSON templates work, the other
not. The not-working one displays Malformed template name (dummy) where
dummy is a non-existent file and the non-working version seems to ignore
the OUTPUTFORMAT block. For example I can put invalid parameters in the
block and they don't throw errors whereas on my working computer they do.

So I'm wondering if there are any dependencies at either compile or run
time that I'm missing. My working computer is Fedora with MapServer
installed from a repo, my non-working computer is Amazon Linux (at Redhat
derivative) with MapServer 6.0 and 6.2 built from source.

Thanks,
Rich

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

Re: [mapserver-users] JSON template

2014-03-12 Thread Lime, Steve D (MNIT)
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.commailto:richard.greenw...@gmail.com
www.greenwoodmap.comhttp://www.greenwoodmap.com
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

[mapserver-users] JSON template

2014-03-11 Thread Richard Greenwood
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
www.greenwoodmap.com
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

[mapserver-users] JSON template fail

2011-09-10 Thread Mr. Puneet Kishor
I was unable to achieve success with the suggestion for template at 
[http://mapserver.org/output/template_output.html]. So, I simplified my 
template like so --

// mapserver template
{
  gid: [gid],
  attrib1: [attrib1],
  attrib2: [attrib2],
  attrib3: [attrib3]
}

In my map file I have an output format declared like so

OUTPUTFORMAT
  NAME json
  DRIVER TEMPLATE
  MIMETYPE application/json
  FORMATOPTION FILE=/Users/punkish/Documents/www/gmap/lib/template.html
END

Note: MapServer croaks if I name the template template.json

The output from MapServer is 

1: {
2:  gid: 2676,
3:  attrib1: foo,
4:  attrib2: bar,
5:  attrib3: baz
6: }

gmap:-1 Resource interpreted as Script but transferred with MIME type text/html.
gmap:2 SyntaxError: Parse error

So, in spite of declaring the MIMETYPE as application/json, the result is 
sent back with a text/html mime type (could that be because the template ends 
in .html?). And, what on earth is the SyntaxError? I don't see any. Does 
anyone?


___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users