[OpenLayers-Commits] r11600 -
sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Mar 1 10:39:32 EST 2011
Author: ahocevar
Date: 2011-03-01 07:39:30 -0800 (Tue, 01 Mar 2011)
New Revision: 11600
Modified:
sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/NG.js
sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/SVG2.js
Log:
pulling in improvements and bug fixes from Layer.SVG on trunk
Modified: sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/NG.js
===================================================================
--- sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/NG.js 2011-03-01 14:11:42 UTC (rev 11599)
+++ sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/NG.js 2011-03-01 15:39:30 UTC (rev 11600)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
Modified: sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/SVG2.js
===================================================================
--- sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/SVG2.js 2011-03-01 14:11:42 UTC (rev 11599)
+++ sandbox/ahocevar/renderer-ng/lib/OpenLayers/Renderer/SVG2.js 2011-03-01 15:39:30 UTC (rev 11600)
@@ -1,10 +1,10 @@
-/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
- * @requires OpenLayers/Renderer/Elements.js
+ * @requires OpenLayers/Renderer/NG.js
*/
/**
@@ -31,7 +31,7 @@
* Property: symbolMetrics
* {Object} Cache for symbol metrics according to their svg coordinate
* space. This is an object keyed by the symbol's id, and values are
- * an array of [width, centerX, centerY].
+ * an object with size, x and y properties.
*/
symbolMetrics: null,
@@ -131,7 +131,7 @@
if (style.externalGraphic) {
nodeType = "image";
} else if (this.isComplexSymbol(style.graphicName)) {
- nodeType = "use";
+ nodeType = "svg";
} else {
nodeType = "circle";
}
@@ -184,6 +184,10 @@
if (style.graphicTitle) {
node.setAttributeNS(null, "title", style.graphicTitle);
+ //Standards-conformant SVG
+ var label = this.nodeFactory(null, "title");
+ label.textContent = style.graphicTitle;
+ node.appendChild(label);
}
if (style.graphicWidth && style.graphicHeight) {
node.setAttributeNS(null, "preserveAspectRatio", "none");
@@ -208,6 +212,7 @@
node.setAttributeNS(null, "height", height);
node.setAttributeNS(this.xlinkns, "href", style.externalGraphic);
node.setAttributeNS(null, "style", "opacity: "+opacity);
+ node.onclick = OpenLayers.Renderer.SVG2.preventDefault;
} else if (this.isComplexSymbol(style.graphicName)) {
// the symbol viewBox is three times as large as the symbol
var offset = style.pointRadius * 3 * resolution;
@@ -223,7 +228,17 @@
parent.removeChild(node);
}
- node.setAttributeNS(this.xlinkns, "href", "#" + id);
+ // The more appropriate way to implement this would be use/defs,
+ // but due to various issues in several browsers, it is safer to
+ // copy the symbols instead of referencing them.
+ // See e.g. ticket http://trac.osgeo.org/openlayers/ticket/2985
+ // and this email thread
+ // http://osgeo-org.1803224.n2.nabble.com/Select-Control-Ctrl-click-on-Feature-with-a-graphicName-opens-new-browser-window-tc5846039.html
+ var src = document.getElementById(id);
+ node.firstChild && node.removeChild(node.firstChild);
+ node.appendChild(src.firstChild.cloneNode(true));
+ node.setAttributeNS(null, "viewBox", src.getAttributeNS(null, "viewBox"));
+
node.setAttributeNS(null, "width", size);
node.setAttributeNS(null, "height", size);
node.setAttributeNS(null, "x", node._x - offset);
@@ -244,16 +259,15 @@
if (rotation !== undefined || node._rotation !== undefined) {
node._rotation = rotation;
rotation |= 0;
- if(node.nodeName !== "svg") {
- node.setAttributeNS(null, "transform",
- "rotate(" + rotation + " " + node._x + " " + node._y + ")"
+ if (node.nodeName !== "svg") {
+ node.setAttributeNS(null, "transform",
+ ["rotate(", rotation, node._x, node._y, ")"].join(" ")
+ );
+ } else {
+ var metrics = this.symbolMetrics[id];
+ node.firstChild.setAttributeNS(null, "transform",
+ ["rotate(", rotation, metrics.x, metrics.y, ")"].join(" ")
);
- } else {
- var metrics = this.symbolMetrics[id];
- node.firstChild.setAttributeNS(null, "transform",
- "rotate(" + rotation + " " + metrics.x +
- " " + metrics.y + ")"
- );
}
}
}
@@ -318,10 +332,10 @@
return [8 * w, 4 * w, widthFactor, 4 * w].join();
default:
var parts = OpenLayers.String.trim(str).split(/\s+/g);
- for (var i=0, ii=parts.length; i<ii; i++) {
- parts[i] = parts[i] * widthFactor;
- }
- return parts.join();
+ for (var i=0, ii=parts.length; i<ii; i++) {
+ parts[i] = parts[i] * widthFactor;
+ }
+ return parts.join();
}
},
@@ -722,5 +736,34 @@
return symbolNode.id;
},
+ /**
+ * Method: getFeatureIdFromEvent
+ *
+ * Parameters:
+ * evt - {Object} An <OpenLayers.Event> object
+ *
+ * Returns:
+ * {<OpenLayers.Geometry>} A geometry from an event that
+ * happened on a layer.
+ */
+ getFeatureIdFromEvent: function(evt) {
+ var featureId = OpenLayers.Renderer.Elements.prototype.getFeatureIdFromEvent.apply(this, arguments);
+ if(!featureId) {
+ var target = evt.target;
+ featureId = target.parentNode && target != this.rendererRoot &&
+ target.parentNode._featureId;
+ }
+ return featureId;
+ },
+
CLASS_NAME: "OpenLayers.Renderer.SVG2"
-});
\ No newline at end of file
+});
+
+/**
+ * Function: OpenLayers.Renderer.SVG2.preventDefault
+ * Used to prevent default events (especially opening images in a new tab on
+ * ctrl-click) from being executed for externalGraphic and graphicName symbols
+ */
+OpenLayers.Renderer.SVG2.preventDefault = function(e) {
+ e.preventDefault && e.preventDefault();
+};
\ No newline at end of file
More information about the Commits
mailing list