Date: | 2006/06/07 |
---|---|
Author: | Steve Lime |
Contact: | steve.lime at DNR.STATE.MN.US |
Status: | Passed (in process) |
Version: | MapServer 5.0 |
Id: | $Id: ms-rfc-19.txt 8278 2008-12-23 21:34:31Z hobu $ |
Description: Presently MapServer supports binding of label and style properties for a few select attributes (e.g. angle). However, it is cumbersome to add new bindings which leads to unnecessarily complex structures and code that is difficult to maintain. This RFC presents ideas to bring a bit of order to that chaos and make expansion of this capability easier to achieve.
A new structure called attributeBindingObj would be added:
typedef struct {
char *item;
char index;
} attributeBindingObj;
Several new enumerations would then define what properties could be bound:
#define MS_STYLE_BINDING_LENGTH ...
#define MS_STYLE_BINDING_ENUM { MS_STYLE_BINDING_SIZE, MS_STYLE_BINDING_ANGLE, ... };
#define MS_LABEL_BINDING_LENGTH ...
#define MS_LABEL_BINDING_ENUM { MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, ... };
Several elements would be removed from layerObj and styleObj. For example, angleitem, angleitemindex and similar members would be removed. styleObj’s and labelObj’s would each take on 2 new members:
char hasBindings;
attributeBindingObj bindings[MS_STYLE_BINDING_LENGTH];
Options like SIZEITEM and ANGLEITEM would go away. Instead a more logical syntax such as:
STYLE
SIZE [mySizeItem]
ANGLE [myAngleItem]
COLOR 255 0 0
SYMBOL 'square'
END
Square brackets have been used in MapServer templates and expressions to bind to attributes so they are a natural choice to denote attribute bindings in this case.
Similarly MapScript would loose the ability to set/get the xxxITEM properties. Instead the style and label objects would get setBinding and deleteBinding methods:
(in Perl)
$style->setBinding($mapscript::MS_STYLE_BINDING_SIZE, 'mySizeItem');
$style->deleteBinding($mapscript::MS_STYLE_BINDING_COLOR);
void msStyleBindAttributes(shapeObj *shape, styleObj *style)
{
if(style->bindings[MS_STYLE_BINDING_SIZE].item)
style->size = atoi(shape->values[style->bindings[MS_STYLE_BINDING_SIZE].index]);
if(style->bindings[MS_STYLE_BINDING_ANGLE].item)
style->angle = atoi(shape->values[style->bindings[MS_STYLE_BINDING_ANGLE].index]);
...
}
This does affect a number of parameters, however they are lightly used so this is probably worth the risk. The primary risk is breaking mapfiles as opposed to scripts. Given that this will definitely break some stuff I think it is most appropriate as a 5.0 change.
+1 Lime, Morissette, Woodbridge