Add support for SVG renderer ( Heavily inspired from rdewit’s patch http://trac.osgeo.org/openlayers/ticket/2965 )
This commit is contained in:
@@ -415,6 +415,12 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
|
|||||||
*/
|
*/
|
||||||
LABEL_ID_SUFFIX: "_label",
|
LABEL_ID_SUFFIX: "_label",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: LABEL_OUTLINE_SUFFIX
|
||||||
|
* {String}
|
||||||
|
*/
|
||||||
|
LABEL_OUTLINE_SUFFIX: "_outline",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Renderer.Elements
|
* Constructor: OpenLayers.Renderer.Elements
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -643,12 +643,25 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
|||||||
* location - {<OpenLayers.Geometry.Point>}
|
* location - {<OpenLayers.Geometry.Point>}
|
||||||
*/
|
*/
|
||||||
drawText: function(featureId, style, location) {
|
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 resolution = this.getResolution();
|
||||||
|
|
||||||
var x = ((location.x - this.featureDx) / resolution + this.left);
|
var x = ((location.x - this.featureDx) / resolution + this.left);
|
||||||
var y = (location.y / resolution - this.top);
|
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, "x", x);
|
||||||
label.setAttributeNS(null, "y", -y);
|
label.setAttributeNS(null, "y", -y);
|
||||||
@@ -656,6 +669,12 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
|||||||
if (style.fontColor) {
|
if (style.fontColor) {
|
||||||
label.setAttributeNS(null, "fill", 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) {
|
if (style.fontOpacity) {
|
||||||
label.setAttributeNS(null, "opacity", style.fontOpacity);
|
label.setAttributeNS(null, "opacity", style.fontOpacity);
|
||||||
}
|
}
|
||||||
@@ -692,7 +711,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
|||||||
label.removeChild(label.lastChild);
|
label.removeChild(label.lastChild);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < numRows; i++) {
|
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) {
|
if (style.labelSelect === true) {
|
||||||
tspan._featureId = featureId;
|
tspan._featureId = featureId;
|
||||||
tspan._geometry = location;
|
tspan._geometry = location;
|
||||||
|
|||||||
Reference in New Issue
Block a user