[mapserver-users] mimic geonames.org JSON server

Mark Volz volzmark at yahoo.com
Thu Dec 8 20:11:28 PST 2011


Steve,

Thank you for your assistance.  The code is starting to work.  I just have a couple more questions.

1)  How can I change the query on the html call to use regular expressions, or more particularly make the search a "begins with" search. Using qlayer=myLayer&qitem=MyField&qstring='myValue' obliviously returns only one result, however I would like to search for n items

2) In the JSON template, I have a comma separating each result.  I thought that I could remove the final comma by adding [feature trimlast=','].  The final comment was not removed.  how do I correctly use [feature trimlast=',']

3)  for JSON templates is a variable for "total results"?  If not is there another way to get a record count?

Thanks



________________________________
 From: "Lime, Steve D (DNR)" <Steve.Lime at state.mn.us>
To: Mark Volz <volzmark at yahoo.com>; "mapserver-users at lists.osgeo.org" <mapserver-users at lists.osgeo.org> 
Sent: Thursday, December 8, 2011 10:26 AM
Subject: RE: [mapserver-users] mimic geonames.org JSON server
 

 
1)      Correct. Templates are just a means of presenting the results of a query operation. I’ve used templates to return json successfully. 
2)      Again, you need to issue a query. So to find a record in a layer you might do something like:
 
http://localhost/cgi-bin/mapserv?map=mapfile&mode=itemquery&qlayer=layer&qitem=item&qstring=value&qformat=jsonformat
 
This assumes that: for the layer in question you’ve setup a validation pattern for qstring and you’ve defined a output format called ‘jsonformat’.
 
The one limitation I’ve found (and would like to fix) is that there’s no easy way to handle exceptions relative to the output format. For example, if you’re outputting json it would be nice to return errors (if possible, certain ones like mapfile not found can’t be dealt with other than in the default way) as json too.
 
Let me know if you have questions.
 
Steve
 
From:mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Mark Volz
Sent: Wednesday, December 07, 2011 10:06 PM
To: mapserver-users at lists.osgeo.org; volzmark at yahoo.com
Subject: [mapserver-users] mimic geonames.org JSON server
 
Hello,
 
I recently came across an interesting openlayers application that uses geonames.org for a search functionality.  I would like to be able to use my own gis data on the searches.   I came across http://mapserver.org/trunk/output/template_output.html, which starts to describe how to make a template.  I just have a couple questions.
 
1)  My understanding is I can use any .map files that have a layer with appropriate fields.  I just need to add another output format so that my .map file references a JSON template, and I can keep the standard image output formats.  Is this correct?
 
2) How would the html request need to be formatted to search a specific value in a specific layer and return JSON?
 
 
Any help and / or examples would be greatly appreciated.
 
Thanks
 
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20111208/dbd61523/attachment.htm>


More information about the MapServer-users mailing list