Merge pull request #451 from ahocevar/more-title

There is no reason to restrict graphicTitle to externalGraphic symbols.
This commit is contained in:
ahocevar
2012-05-15 07:46:33 -07:00
5 changed files with 30 additions and 23 deletions
+4 -3
View File
@@ -49,7 +49,8 @@
strokeWidth: 3, strokeWidth: 3,
strokeDashstyle: "dashdot", strokeDashstyle: "dashdot",
pointRadius: 6, pointRadius: 6,
pointerEvents: "visiblePainted" pointerEvents: "visiblePainted",
title: "this is a green line"
}; };
/* /*
@@ -70,8 +71,8 @@
style_mark.graphicXOffset = 10; // default is -(style_mark.graphicWidth/2); style_mark.graphicXOffset = 10; // default is -(style_mark.graphicWidth/2);
style_mark.graphicYOffset = -style_mark.graphicHeight; style_mark.graphicYOffset = -style_mark.graphicHeight;
style_mark.externalGraphic = "../img/marker.png"; style_mark.externalGraphic = "../img/marker.png";
// graphicTitle only works in Firefox and Internet Explorer // title only works in Firefox and Internet Explorer
style_mark.graphicTitle = "this is a test tooltip"; style_mark.title = "this is a test tooltip";
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", { var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
style: layer_style, style: layer_style,
+2 -1
View File
@@ -403,7 +403,8 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* graphicZIndex - {Number} The integer z-index value to use in rendering. * graphicZIndex - {Number} The integer z-index value to use in rendering.
* graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default), * graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default),
* "square", "star", "x", "cross", "triangle". * "square", "star", "x", "cross", "triangle".
* graphicTitle - {String} Tooltip for an external graphic. * graphicTitle - {String} Tooltip when hovering over a feature. *deprecated*, use title instead
* title - {String} Tooltip when hovering over a feature. Not supported by the canvas renderer.
* backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic. * backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic.
* backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic. * backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic.
* backgroundXOffset - {Number} The x offset (in pixels) for the background graphic. * backgroundXOffset - {Number} The x offset (in pixels) for the background graphic.
+3 -2
View File
@@ -241,8 +241,9 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
drawExternalGraphic: function(geometry, style, featureId) { drawExternalGraphic: function(geometry, style, featureId) {
var img = new Image(); var img = new Image();
if (style.graphicTitle) { var title = style.title || style.graphicTitle;
img.title = style.graphicTitle; if (title) {
img.title = title;
} }
var width = style.graphicWidth || style.graphicHeight; var width = style.graphicWidth || style.graphicHeight;
+16 -14
View File
@@ -239,6 +239,22 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
setStyle: function(node, style, options) { setStyle: function(node, style, options) {
style = style || node._style; style = style || node._style;
options = options || node._options; options = options || node._options;
var title = style.title || style.graphicTitle;
if (title) {
node.setAttributeNS(null, "title", title);
//Standards-conformant SVG
// Prevent duplicate nodes. See issue https://github.com/openlayers/openlayers/issues/92
var titleNode = node.getElementsByTagName("title");
if (titleNode.length > 0) {
titleNode[0].firstChild.textContent = title;
} else {
var label = this.nodeFactory(null, "title");
label.textContent = title;
node.appendChild(label);
}
}
var r = parseFloat(node.getAttributeNS(null, "r")); var r = parseFloat(node.getAttributeNS(null, "r"));
var widthFactor = 1; var widthFactor = 1;
var pos; var pos;
@@ -248,20 +264,6 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
node.style.visibility = "hidden"; node.style.visibility = "hidden";
} else if (style.externalGraphic) { } else if (style.externalGraphic) {
pos = this.getPosition(node); pos = this.getPosition(node);
if (style.graphicTitle) {
node.setAttributeNS(null, "title", style.graphicTitle);
//Standards-conformant SVG
// Prevent duplicate nodes. See issue https://github.com/openlayers/openlayers/issues/92
var titleNode = node.getElementsByTagName("title");
if (titleNode.length > 0) {
titleNode[0].firstChild.textContent = style.graphicTitle;
} else {
var label = this.nodeFactory(null, "title");
label.textContent = style.graphicTitle;
node.appendChild(label);
}
}
if (style.graphicWidth && style.graphicHeight) { if (style.graphicWidth && style.graphicHeight) {
node.setAttributeNS(null, "preserveAspectRatio", "none"); node.setAttributeNS(null, "preserveAspectRatio", "none");
} }
+5 -3
View File
@@ -207,12 +207,14 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
options = options || node._options; options = options || node._options;
var fillColor = style.fillColor; var fillColor = style.fillColor;
var title = style.title || style.graphicTitle;
if (title) {
node.title = title;
}
if (node._geometryClass === "OpenLayers.Geometry.Point") { if (node._geometryClass === "OpenLayers.Geometry.Point") {
if (style.externalGraphic) { if (style.externalGraphic) {
options.isFilled = true; options.isFilled = true;
if (style.graphicTitle) {
node.title=style.graphicTitle;
}
var width = style.graphicWidth || style.graphicHeight; var width = style.graphicWidth || style.graphicHeight;
var height = style.graphicHeight || style.graphicWidth; var height = style.graphicHeight || style.graphicWidth;
width = width ? width : style.pointRadius*2; width = width ? width : style.pointRadius*2;