adding support for line breaks to SVG, SVG2 and Canvas renderers. Also adds vertical alignment support to Canvas. p=vog,fredj,me r=me (closes #2193)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11838 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -570,8 +570,8 @@ OpenLayers.Renderer.SVG2 = OpenLayers.Class(OpenLayers.Renderer.NG, {
|
||||
* Method: drawText
|
||||
* Function for drawing text labels.
|
||||
* This method is only called by the renderer itself.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* Parameters:
|
||||
* featureId - {String|DOMElement}
|
||||
* style - {Object}
|
||||
* location - {<OpenLayers.Geometry.Point>}, will be modified inline
|
||||
@@ -583,14 +583,12 @@ OpenLayers.Renderer.SVG2 = OpenLayers.Class(OpenLayers.Renderer.NG, {
|
||||
var g = OpenLayers.Renderer.NG.prototype.drawText.apply(this, arguments);
|
||||
var text = g.firstChild ||
|
||||
this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_text", "text");
|
||||
var tspan = text.firstChild ||
|
||||
this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan", "tspan");
|
||||
|
||||
var res = this.getResolution();
|
||||
text.setAttributeNS(null, "x", location.x / res);
|
||||
text.setAttributeNS(null, "y", - location.y / res);
|
||||
g.setAttributeNS(null, "transform", "scale(" + res + ")");
|
||||
|
||||
|
||||
if (style.fontColor) {
|
||||
text.setAttributeNS(null, "fill", style.fontColor);
|
||||
}
|
||||
@@ -609,10 +607,9 @@ OpenLayers.Renderer.SVG2 = OpenLayers.Class(OpenLayers.Renderer.NG, {
|
||||
if (style.fontStyle) {
|
||||
text.setAttributeNS(null, "font-style", style.fontStyle);
|
||||
}
|
||||
if(style.labelSelect === true) {
|
||||
if (style.labelSelect === true) {
|
||||
text.setAttributeNS(null, "pointer-events", "visible");
|
||||
text._featureId = featureId;
|
||||
tspan._featureId = featureId;
|
||||
} else {
|
||||
text.setAttributeNS(null, "pointer-events", "none");
|
||||
}
|
||||
@@ -623,18 +620,43 @@ OpenLayers.Renderer.SVG2 = OpenLayers.Class(OpenLayers.Renderer.NG, {
|
||||
if (OpenLayers.IS_GECKO === true) {
|
||||
text.setAttributeNS(null, "dominant-baseline",
|
||||
OpenLayers.Renderer.SVG2.LABEL_ALIGN[align[1]] || "central");
|
||||
} else {
|
||||
tspan.setAttributeNS(null, "baseline-shift",
|
||||
OpenLayers.Renderer.SVG2.LABEL_VSHIFT[align[1]] || "-35%");
|
||||
}
|
||||
|
||||
tspan.textContent = style.label;
|
||||
|
||||
if(!text.parentNode) {
|
||||
text.appendChild(tspan);
|
||||
var labelRows = style.label.split('\n');
|
||||
var numRows = labelRows.length;
|
||||
while (text.childNodes.length > numRows) {
|
||||
text.removeChild(text.lastChild);
|
||||
}
|
||||
for (var i = 0; i < numRows; i++) {
|
||||
var tspan = text.childNodes[i] ||
|
||||
this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan_" + i, "tspan");
|
||||
if (style.labelSelect === true) {
|
||||
tspan._featureId = featureId;
|
||||
}
|
||||
if (OpenLayers.IS_GECKO === false) {
|
||||
tspan.setAttributeNS(null, "baseline-shift",
|
||||
OpenLayers.Renderer.SVG2.LABEL_VSHIFT[align[1]] || "-35%");
|
||||
}
|
||||
tspan.setAttribute("x", location.x / res);
|
||||
if (i == 0) {
|
||||
var vfactor = OpenLayers.Renderer.SVG2.LABEL_VFACTOR[align[1]];
|
||||
if (vfactor == null) {
|
||||
vfactor = -.5;
|
||||
}
|
||||
tspan.setAttribute("dy", (vfactor*(numRows-1)) + "em");
|
||||
} else {
|
||||
tspan.setAttribute("dy", "1em");
|
||||
}
|
||||
tspan.textContent = (labelRows[i] === '') ? ' ' : labelRows[i];
|
||||
if (!tspan.parentNode) {
|
||||
text.appendChild(tspan);
|
||||
}
|
||||
}
|
||||
|
||||
if (!text.parentNode) {
|
||||
g.appendChild(text);
|
||||
}
|
||||
|
||||
|
||||
return g;
|
||||
},
|
||||
|
||||
@@ -786,6 +808,15 @@ OpenLayers.Renderer.SVG2.LABEL_VSHIFT = {
|
||||
"b": "0"
|
||||
};
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Renderer.SVG2.LABEL_VFACTOR
|
||||
* {Object}
|
||||
*/
|
||||
OpenLayers.Renderer.SVG2.LABEL_VFACTOR = {
|
||||
"t": 0,
|
||||
"b": -1
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: OpenLayers.Renderer.SVG2.preventDefault
|
||||
* Used to prevent default events (especially opening images in a new tab on
|
||||
|
||||
Reference in New Issue
Block a user