Merge pull request #140 from aabt/outline

Add label outline to SVG and Canvas renderers
This commit is contained in:
Antoine Abt
2012-01-17 04:45:50 -08:00
6 changed files with 63 additions and 13 deletions

View File

@@ -643,12 +643,25 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
* location - {<OpenLayers.Geometry.Point>}
*/
drawText: function(featureId, style, location) {
var drawOutline = (!!style.labelOutlineWidth);
// First draw text in halo color and size and overlay the
// normal text afterwards
if (drawOutline) {
var outlineStyle = OpenLayers.Util.extend({}, style);
outlineStyle.fontColor = outlineStyle.labelOutlineColor;
outlineStyle.fontStrokeColor = outlineStyle.labelOutlineColor;
outlineStyle.fontStrokeWidth = style.labelOutlineWidth;
delete outlineStyle.labelOutlineWidth;
this.drawText(featureId, outlineStyle, location);
}
var resolution = this.getResolution();
var x = ((location.x - this.featureDx) / resolution + this.left);
var y = (location.y / resolution - this.top);
var label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX, "text");
var suffix = (drawOutline)?this.LABEL_OUTLINE_SUFFIX:this.LABEL_ID_SUFFIX;
label = this.nodeFactory(featureId + suffix, "text");
label.setAttributeNS(null, "x", x);
label.setAttributeNS(null, "y", -y);
@@ -656,6 +669,12 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
if (style.fontColor) {
label.setAttributeNS(null, "fill", style.fontColor);
}
if (style.fontStrokeColor) {
label.setAttributeNS(null, "stroke", style.fontStrokeColor);
}
if (style.fontStrokeWidth) {
label.setAttributeNS(null, "stroke-width", style.fontStrokeWidth);
}
if (style.fontOpacity) {
label.setAttributeNS(null, "opacity", style.fontOpacity);
}
@@ -677,7 +696,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
} else {
label.setAttributeNS(null, "pointer-events", "none");
}
var align = style.labelAlign || "cm";
var align = style.labelAlign;
label.setAttributeNS(null, "text-anchor",
OpenLayers.Renderer.SVG.LABEL_ALIGN[align[0]] || "middle");
@@ -692,7 +711,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
label.removeChild(label.lastChild);
}
for (var i = 0; i < numRows; i++) {
var tspan = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan_" + i, "tspan");
var tspan = this.nodeFactory(featureId + suffix + "_tspan_" + i, "tspan");
if (style.labelSelect === true) {
tspan._featureId = featureId;
tspan._geometry = location;