Ming

From OpenStreetMap Wiki
Jump to navigation Jump to search

broom

This article or section may contain out-of-date information. The information may no longer be correct, or may no longer have relevance.
If you know about the current state of affairs, please help keep everyone informed by updating this information. (Discussion)

Thanks to Steve, we now have the Ming library installed on the server. Ming is a super-flexible (LGPL) library that enables you to dynamically produce Flash .SWF files from the scripting language of your choice, which in OSM's case is Ruby.

Like many such projects, Ming is excellently engineered and badly documented. More information on using Ming with OSM will follow, but here are some starting points.

  • libming.net is the official docs wiki, but still in very early stages.
  • gazb's Ming examples (PHP) is a goldmine of working Ming code that you can learn from.
  • PHP Ming docs are probably the best (though still incomplete) function reference available.
  • Ming-Ruby has a few real Ruby examples.
  • Adobe's ActionScript dictionary is the essential ActionScript reference. Warning for Mac users - ridiculously slow in Safari, so use Firefox.

Using Ming on dev.openstreetmap.org

Ming-Ruby doesn't appear to be capable of writing direct to the browser under mod_ruby: it sends stuff to stdout rather than to the Apache Request object. Instead, we must write the SWF to a temporary file, then output the file:

require 'ming/ming'
include Ming

r = Apache.request
r.content_type = 'application/x-shockwave-flash'
r.send_http_header

Ming.set_scale(20.0)       # any number you like, but remember the Ming. bit
Ming.set_SWF_version(6)    # the behaviour of your ActionScript will depend on the version chosen

(put the rest of your code here, remembering to finish with a next_frame)

filename='/tmp/swf_'+rand(65535).to_s
m.save(filename)           # where m is your SWFMovie object
wholefile=File.read(filename)
r.print(wholefile)
File.delete(filename)

Issues

write_exports is missing from Ming-Ruby. Required patch is here, hopefully we can apply it soon.

Examples

Here's a fairly fatuous example of Ming running on dev.