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

View File

@@ -49,7 +49,8 @@
strokeWidth: 3,
strokeDashstyle: "dashdot",
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.graphicYOffset = -style_mark.graphicHeight;
style_mark.externalGraphic = "../img/marker.png";
// graphicTitle only works in Firefox and Internet Explorer
style_mark.graphicTitle = "this is a test tooltip";
// title only works in Firefox and Internet Explorer
style_mark.title = "this is a test tooltip";
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
style: layer_style,

View File

@@ -403,7 +403,8 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* 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),
* "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.
* 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.

View File

@@ -241,8 +241,9 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
drawExternalGraphic: function(geometry, style, featureId) {
var img = new Image();
if (style.graphicTitle) {
img.title = style.graphicTitle;
var title = style.title || style.graphicTitle;
if (title) {
img.title = title;
}
var width = style.graphicWidth || style.graphicHeight;

View File

@@ -239,6 +239,22 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
setStyle: function(node, style, options) {
style = style || node._style;
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 widthFactor = 1;
var pos;
@@ -248,20 +264,6 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
node.style.visibility = "hidden";
} else if (style.externalGraphic) {
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) {
node.setAttributeNS(null, "preserveAspectRatio", "none");
}

View File

@@ -207,12 +207,14 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
options = options || node._options;
var fillColor = style.fillColor;
var title = style.title || style.graphicTitle;
if (title) {
node.title = title;
}
if (node._geometryClass === "OpenLayers.Geometry.Point") {
if (style.externalGraphic) {
options.isFilled = true;
if (style.graphicTitle) {
node.title=style.graphicTitle;
}
var width = style.graphicWidth || style.graphicHeight;
var height = style.graphicHeight || style.graphicWidth;
width = width ? width : style.pointRadius*2;