Flash support in Mapserver
Introduction
Recently the support of Flash output (SWF Files) has been added to Mapserver in addition to other output formats such as GD based formats (GIF, PNG, …)and vector outputs like PDF.
Library Used
The library chosen to output SWF files is the Ming library (http://www.opaque.net/ming/). Ming is a c library for generating SWF ("Flash") format movies, plus a set of wrappers for using the library from c++ and popular scripting languages like PHP, Python, and Ruby.
Building Mapserver with Flash support
1.Windows version
·Download the Ming library from the http://www.opaque.net/ming/ (the version currently supported is the 0.2a
·There are no makefile for Windows available in the distribution yet, but you can download a MS VC++ makefile (makefile.vc) from the DM Solutions site ( http://www2.dmsolutions.ca/mapserver/dl/ming-0.2a.zip contains makefile and also libming.lib)
·Copy the makefile.vc under the src directory (ming-0.2/src)
·nmake –f makefile.vc
·You should get at this point a libming.lib that will be linked with Mapserver
·Edit the makefile.vc in the mapserver directory and uncomment the flags MING_LIB, MING_INC and MING. Make also sure that they reflect your installation.
2.On Unix
Libming support in the unix have been added to configure and Makefile.Using the "--with-ming" flag should enable MING support on Unix. "--with-ming=dir" will try to find the include files and library in the indicated directory.
Note: compiling Mapserver4.4.2 with flash support (mingbeta version 0.3) requires the -DMING_VERSION_03 option otherwise the make fails. This option should be included in the configure.in after -DUSE_MING_FLASH as below:
MING ENABLED= "-DUSE_MING_FLASH -DMING_VERSION_03"
How to output SWF Files from Mapserver
There are 2 possible output types:
1) a single movie containing the raster output for all the layers. Todo theis declare the following in the map file :
OUTPUTFORMAT
NAME swf
MIMETYPE "application/x-shockwave-flash"
DRIVER swf
IMAGEMODE PC256
FORMATOPTION "OUTPUT_MOVIE=SINGLE"
END
2) A movie for every layer (Vector movie for vector layers and raster movie for raster layers)
OUTPUTFORMAT
NAME swf
MIMETYPE "application/x-shockwave-flash"
DRIVER swf
IMAGEMODE PC256
FORMATOPTION "OUTPUT_MOVIE=MULTIPLE"
END
Other output format options
* FORMATOPTION "FULL_RESOLUTION=FALSE"
The FULL_RESOLUTION applies only for vector layers. If set to FALSE, filtering will be applied to the vector elements. It results in a smaller SWF file. The default value is TRUE.
What are the resulting SWF files
Several SWF Files will be produced from a single map file: there will be one SWF file for each layer defined in the map file and one “main” SWF file containing critical information on the map file and the layers produced.
* The “main” SWF File will contain Action Script (AS) code that gives critical information on the map file and the SWF layers produced. Basically there will be an object called mapObj containing the height, width, extent, scale, number of layers, … Here is an example (in AS) of the contents of this main movie:
mapObj = new Object ();
mapObj.name = "DEMO_SWF";
mapObj.width = 400;
mapObj.height = 300;
mapObj.extent = "-2594561.353333,3467361.353333,3467361.353333,3840000.000000"; ;
mapObj.numlayers = 4;
mapObj.layers = new Array ();
function LayerObj (name, type, fullname, relativename) {
this.name = name;
this.type = type;
this.fullname = fullname;
this.relativename = relativename;
}
mapObj.layers[0] = new LayerObj ("park", "2", "c:/tmp/ms_tmp/102389536132841_layer_0.swf", "102389536132841_layer_0.swf");
mapObj.layers[1] = new LayerObj ("popplace", "4", "c:/tmp/ms_tmp/102389536132841_layer_1.swf", "102389536132841_layer_1.swf");
mapObj.layers[2] = new LayerObj ("rail", "1", "c:/tmp/ms_tmp/102389536132841_layer_2.swf", "102389536132841_layer_2.swf");
mapObj.layers[3] = new LayerObj ("road", "1", "c:/tmp/ms_tmp/102389536132841_layer_3.swf", "102389536132841_layer_3.swf");
This example is produced based on a map file with two layers defined in it.We create a layer class object cobatining usful information on a layer. The parameters are:
o Name : the name found in the map file
o Type : the type of layer ( 0 = Point Layer; 1=Line; 2=Polygon; 3=Raster;
4=Annotation; 6=Circle)
o Fullname : Full name of the file with path included
o Relative name : Relative Name
For example you can use maoObj.layers[0].name to extract the name of the first layer.
Note: All map parameters form Mapserver are not exported at this time. We should come up with a list of information of what we want to output. Note that this information can be used in a Flash application to load the SWF file, to build a legend, to build a scale bar …
* SWF Files for each layer
Each layer defined in the map file will have an associated SWF file created. The names of these SWF files are based on the name of the main file with an addition of “layer_X” at the end of the name (where X equals to the layer index).
These SWF will contain vector and raster data as well as some Action Script depending on the layer and some configurations in the map file. We will see these configurations in details in the following paragraphs.
What is currently supported and not supported.
1. Vector layers
* Layer Point (case MS_LAYER_POINT) : done
o msDrawMarkerSymbol
o msDrawLabel
* Layer line (case MS_LAYER_LINE) : done
o msDrawLineSymbol
o msDrawLabel
* Layer circle ( case MS_LAYER_CIRCLE) : not done (should be done easily but missing data for test)
omsCircleDrawLineSymbol
omsCircleDrawShadeSymbol
Layer annotation (case MS_LAYER_ANNOTATION): done
omsDrawMarkerSymbol
omsDrawLabel
Layer Polygon (MS_SHAPE_POLYGON): done
omsDrawShadeSymbol
omsDrawLineSymbol
omsDrawLabel
Vector Low Level functions
omsDrawMarkerSymbol
- case(MS_SYMBOL_TRUETYPE) : done
- case(MS_SYMBOL_PIXMAP) : done
- case(MS_SYMBOL_ELLIPSE) : done
- case(MS_SYMBOL_VECTOR) : done
omsDrawLineSymbol
- case : simple line : done
- drawing with the symbols : not done
omsDrawShadeSymbol
- case : solid fill polygon : done
- case : filled with symbols : can not be implemented for now (tried to create
a gd image to fill the shape but files created were huge)
omsCircleDrawLineSymbol : not done
omsCircleDrawShadeSymbol : not done
omsDrawLabel : done
omsDrawLabelCache : done
obillboard (shadow for texts) : not done
2.Raster Layer
- msDrawRasterLayer: done
3.WMS Layer
- msDrawWMSLayer: done
4.Surround components (Legend, scalebar) : not supported
How to configure the map file to export attributes
Exporting attributes works on a layer basis (It is only available for Vector Layers). To be able to export attributes to the SWF Files, you have to define a metadata called SWFDUMPATTRIBUTES in the layer section of the map file. Here is an example :
…….
LAYER
NAME park
METADATA
"DESCRIPTION""Parks"
"RESULT_FIELDS" "NAME_E YEAR_EST AREA_KMSQ"
"SWFDUMPATTRIBUTES" "NAME_E,AREA_KMSQ "
END
TYPE POLYGON
STATUS ON
DATA park
……
In this example, the values for the attributes NAME_E and AREA_KMSQ will be exported for each element in the layer.
The resulting SWF File will have the values of these attributes(written in Action Script). Here is an example related to the layer seen earlier:
nAttributes= 2;
Attributes = new Array();
Attributes[0] = “NAME_E”;
Attributes[1] = “AREA_KMSQ”
Element = new Array ();
Element[0] = new Array();
Element[0][0] = "Ellesmere Island National Park Reserve";
Element[0][1] = "1500”;
Element[1][0] = " Aulavik National park";
Element[1][1] = "1500”;
……
Events and Highlights
Here is what is currently implemented concerning events (Events here refer to mouse events happening on an element. The available events are MOUSEUP, MOUSEDOWN, MOUSEOVER, MOUSEOUT):
* Events are only available for layers that have defined attributes exported (using SWFDUMPATTRIBUTES). This is like defining that a certain layer is queryable.
* When a mouse event happens on one of the elements, there is an Action Script call that is made: _root.ElementSelecetd(LayerId, ShapeId, Event) . The Flash application who want to receive these events should define the function ElementSelected and use the information receive to do actions like retrieving the attribute values from the specific SWF for the specified shape and display it.
In order to have Highlighting, It has to be defined when the SWF is produced (Basically the shape is redrawn using a different color).
The question here is how do the user define that he wants highlighting or not. One possibility is that the highlight is available on queryable layers and use the Query Map object in the map file to extract the color and do a highlight when on MOUSEOVER. The current implementation will hightlight all objects that are in a layer that uses SWFDUMPATTRIBUTES. The highlighting uses the red color.
How to configure the map file to output raster SWF for vector layers?
One mechanism would be to use the metadata for layer objects to define a raster output for vector layers. We could use something like “SWFOUTPUT” “RASTER”.
Miscellaneous
* Fonts.
Ming uses a special type of fonts called FDB files. It does not yet support True type fonts.Please refer to ming documentation on how to produce FDB files (http://www.opaque.net/wiki/index.php?MingFAQ). There are also free true types fonts convert to FDB file at DM Solutions site (www. ….)
Last Update : 2003/06/16
assefa@dmsolutions.ca
没有评论:
发表评论