SWF viewer

From Wildsong
Jump to navigationJump to search

What does it take to build a simple SWF (Flash) based vector map viewer? (As opposed to plain html+javascript or java.)

Depends on what you mean by a "SWF-based map viewer".

There are two ways to think about using SWF with a mapserver. The first obvious way (to me) is that the imagemap portion of the page is generated as a SWF file, meaning that the map itself can be animated. For example, you can support very nice zoom and pan operations.

The second way is to use mapserver to generate static image files in png or jpeg format, and to use SWF in the user interface. That way you can support things like fancy rollover buttons.

An aside: there is actually a scripting language embedded in Flash called actionscript. Actionscript is just a subset of javascript (or both are subsets of ecmascript if you prefer). Therefore, if you are a happy javascript programmer you can quickly adapt your skills to actionscript.

To create the user interface you can build the page with Dreamweaver; or you could use the PHP SWF extension or the external Ming library for PHP, and write PHP code to generate the SWF page. Or you can combine them.

Since I don't have Dreamweaver access at the moment I am working with ming.

Ming build notes

I built ming as a loadable extension for PHP (which is easier than building a new version of php.) Current ming is 0.3 and php is 4.4.2.

You have to download both ming and ming-php tar balls from http://ming.sourceforge.net

On a TSL 2.2 Linux system, I had to add the bison and libungif-devel rpm packages to get ming to compile. I had to install libungif on the target server.

./configure; make
cd php_ext
make
sudo make install
edit php.ini to add a line 'extension=php_ming.so'

If you build a dynamic library then "make install" does not correctly install the library. I did this by hand on the TSL system. Building static works too.

cp libming.so /usr/lib/libming.so.0.3beta1.0
cd /usr/lib
ln -fs libming.so.0.3beta1.0 libming.so.0
ln -fs libming.so.0 libming.so.0

Once I had the php module installed correctly I created this simple SWF example as a test. More test samples are on the PHP/SWF tests page.

Mapserver build notes

Mapserver can generate SWF files directly, if you have compiled it with support for the ming library. So next I rebuilt mapserver with the added command line option to 'configure': --with-ming

There is an error in the mapserver source code! Oh no! MING_VERSION_03 needs to be defined for UNIX (is defined for MSC). (See http://lists.dmsolutions.ca/pipermail/mapserver-users/2004-May/018580.html)

Adding -DMING_VERSION_03 to the MING definition line in Makefile allows it to compile.

It's still working! Adding SWF did not break basic mapserver functionality. Good. Now to try the SWF feature. Well, simply changing IMAGETYPE from PNG to SWF does NOT do it! I had guessed it might be harder than that.

I just found this Mapserver Flash demo, http://aris.cseas.kyoto-u.ac.jp/fmv/fmv.html The zip file for this project is on the UMN server.

I revamped my City of Corvallis simple example yet again to generate SWF output instead of png. You can try it. Pretty exciting, huh? Since it looks exactly the same as PNG output, I mean. :-)

Flash Demos

I got the demos going on my server, not exciting but more progress. http://mapserver.wildsong.biz/fmv/ and http://mapserver.wildsong.biz/fmvpro/

Links

PHP reference for ming

I like the simple user interface on this server: http://www.downtownbethesda.com/

Layers turn on and off at different scales, there are basically no controls; just pan and zoom. Pan by dragging, and zoom with slider or scroll wheel.

[Worldkit] "worldKit is an easy to use and flexible mapping application for the Web. Light weight GIS. It's a SWF based app, configured by XML, data fed by RSS. Stand-alone use or integration in larger projects."