Home | Products | Issue Tracker | FAQ | Download | |
Date: | 2013/08 |
---|---|
Author: | Alan Boudreault |
Contact: | aboudreault@mapgears.com |
Status: | Adopted |
Version: | MapServer 7.0 |
警告
this feature is experimental and backwards compatibility may be broken in the not-so-short term.
Currently, we can style our features by using classes and styles in the mapfile. We can do a lot of styling with the mapserver expressions. However, it might end up with a hundred of mapfile lines for a styling layer depending of the complexity of the data. It is also very hard to maintain. We can also specify the a STYLEITEM option (AUTO or [attribute]) where mapserver get the feature style, but this is very not flexible.
This RFC proposes the addition of a STYLEITEM javascript plugin. The goal of this plugin support is to be able to style our features programmatically. This will be accomplished through javascript using the V8 Engine.
MapServer will have a new addition: the V8 javascript engine integration. There will be a generic implementation in mapserver with the necessary stuff for the v8 engine: compiling and executing javascript code. It will also allow the use of javascript in some other parts of the mapserver code if needed.
The STYLEITEM javascript plugin will be similar to current styleitem options. Rather than writing classes in the layer definition, we will specify the javascript file to be executed for the feature styles. The shape attributes will be exposed to javascript. The javascript plugin will have to return one of these two options:
mapfile:
LAYER
NAME "my_vector_layer"
TYPE POINT
STATUS ON
STYLEITEM "javascript:///path/to/my/file.js"
CLASS
# empty class needed in current implementation of styleitem.
END
END
javascript:
require('./global_variables.js'); // for symbols array
// random symbol
var symbol = symbols[Math.floor(Math.random()*symbols.length)];
var style = style = "STYLE SIZE 12 SYMBOL '"+symbol+"'";
if (shape.attributes.COULEUR != '#000000') {
style += "COLOR '"+shape.attributes.COULEUR+"' END";
} else {
// random color
red = Math.random()*255;
green = Math.random()*255;
blue = Math.random()*255;
style += "COLOR "+red+" "+green+" "+blue+" END";
}
// return the style to MapServer
style;
None expected, new functionality.
None
Passed with +1 from Thomas, Daniel, Mike, Tamas, Stephen, Perry and Stephan