Add support for SVG renderer ( Heavily inspired from rdewit’s patch http://trac.osgeo.org/openlayers/ticket/2965 )

This commit is contained in:
Antoine Abt
2012-01-05 17:32:00 +01:00
parent 5be7e7f844
commit be585c5f23
2 changed files with 27 additions and 2 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);
}
@@ -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;