if labelAlign is set, translate to AnchorPointX and AnchorPointY

This commit is contained in:
Bart van den Eijnden
2012-02-24 18:20:41 +01:00
parent 3b81b423a5
commit 617ba736a2

View File

@@ -948,22 +948,26 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
}
// add in optional Font
if(symbolizer.fontFamily != null ||
symbolizer.fontSize != null ||
symbolizer.fontWeight != null ||
symbolizer.fontStyle != null) {
this.writeNode("Font", symbolizer, node);
symbolizer.fontSize != null ||
symbolizer.fontWeight != null ||
symbolizer.fontStyle != null) {
this.writeNode("Font", symbolizer, node);
}
// add in optional LabelPlacement
if ((symbolizer.labelAnchorPointX != null ||
symbolizer.labelAnchorPointY != null) ||
if (symbolizer.labelAnchorPointX != null ||
symbolizer.labelAnchorPointY != null ||
symbolizer.labelAlign != null ||
symbolizer.labelXOffset != null ||
symbolizer.labelYOffset != null ||
symbolizer.labelRotation != null ||
symbolizer.labelPerpendicularOffset != null) {
this.writeNode("LabelPlacement", symbolizer, node);
this.writeNode("LabelPlacement", symbolizer, node);
}
// add in optional Halo
if(symbolizer.haloRadius != null ||
symbolizer.haloColor != null ||
symbolizer.haloOpacity != null) {
this.writeNode("Halo", symbolizer, node);
symbolizer.haloColor != null ||
symbolizer.haloOpacity != null) {
this.writeNode("Halo", symbolizer, node);
}
// add in optional Fill
if(symbolizer.fillColor != null ||
@@ -975,8 +979,12 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
"LabelPlacement": function(symbolizer) {
var node = this.createElementNSPlus("sld:LabelPlacement");
if (symbolizer.labelAnchorPointX != null ||
symbolizer.labelAnchorPointY != null) {
this.writeNode("PointPlacement", symbolizer, node);
symbolizer.labelAnchorPointY != null ||
symbolizer.labelAlign != null ||
symbolizer.labelXOffset != null ||
symbolizer.labelYOffset != null ||
symbolizer.labelRotation != null) {
this.writeNode("PointPlacement", symbolizer, node);
}
if (symbolizer.labelPerpendicularOffset != null) {
this.writeNode("LinePlacement", symbolizer, node);
@@ -996,7 +1004,8 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
"PointPlacement": function(symbolizer) {
var node = this.createElementNSPlus("sld:PointPlacement");
if (symbolizer.labelAnchorPointX != null ||
symbolizer.labelAnchorPointY != null) {
symbolizer.labelAnchorPointY != null ||
symbolizer.labelAlign != null) {
this.writeNode("AnchorPoint", symbolizer, node);
}
if (symbolizer.labelXOffset != null ||
@@ -1010,11 +1019,33 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
},
"AnchorPoint": function(symbolizer) {
var node = this.createElementNSPlus("sld:AnchorPoint");
if (symbolizer.labelAnchorPointX != null) {
this.writeNode("AnchorPointX", symbolizer.labelAnchorPointX, node);
var x = symbolizer.labelAnchorPointX,
y = symbolizer.labelAnchorPointY;
if (x != null) {
this.writeNode("AnchorPointX", x, node);
}
if (symbolizer.labelAnchorPointY != null) {
this.writeNode("AnchorPointY", symbolizer.labelAnchorPointY, node);
if (y != null) {
this.writeNode("AnchorPointY", y, node);
}
if (x == null && y == null) {
var xAlign = symbolizer.labelAlign.substr(0, 1),
yAlign = symbolizer.labelAlign.substr(1, 1);
if (xAlign === "l") {
x = 0;
} else if (xAlign === "c") {
x = 0.5;
} else if (xAlign === "r") {
x = 1;
}
if (yAlign === "b") {
y = 0;
} else if (yAlign === "m") {
y = 0.5;
} else if (yAlign === "t") {
y = 1;
}
this.writeNode("AnchorPointX", x, node);
this.writeNode("AnchorPointY", y, node);
}
return node;
},