Systeme D

June 3, 2010

The simplest possible OpenStreetMap server

One of the aims of Halcyon, the rendering engine behind Potlatch 2, is to provide a fully stylable map applet for web pages. Just drop in the SWF, give it a stylesheet (in MapCSS), and job done.

The SWF will talk to an OpenStreetMap database server. In theory you could point it at the main OSM API, but that’s primarily there for map editors, not as a free API for all-comers.

It would be friendlier to set up your own server. You can install the whole OSM ‘rails_port’ server stack for this, but it’s fairly complicated and involves a bunch of dependencies, so isn’t an option on your average shared host.

So I’ve written a little read-only API script for Halcyon use. You can get it from the OSM subversion repository in Potlatch 2/Halcyon’s resources directory.

It’s in Perl, comprises only one script, and has no dependencies (other than DBI for database access, obviously). It uses Flash’s AMF transport format, which is compact and fast. It needs only the current_ tables for nodes, ways, relations and tags, plus a nominal user 1 and changeset 1.

You might set it up as follows:

  1. Download some OSM data (e.g. a planet extract)
  2. Use Osmosis on your local machine to convert it to SQL and then upload the SQL dump to your remote host… or do it all on the remote host if you can
  3. Upload tinyamf.cgi somewhere executable
  4. Upload halcyon_viewer.swf, swfobject.js, a MapCSS stylesheet and any icons/fills necessary
  5. Put the necessary embedding HTML in your page
  6. That’s it!

I’ll post a real live example somewhere in due course.

Future versions of Halcyon will also be able to read directly from .osm files, so you won’t even need a database.


Leave a Reply