} 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"
+});
+
+/**
+ * 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
diff --git a/tests/Layer/Vector.html b/tests/Layer/Vector.html
index 1a47aaf4c3..30395638ff 100644
--- a/tests/Layer/Vector.html
+++ b/tests/Layer/Vector.html
@@ -458,9 +458,7 @@
t.plan(9);
var map = new OpenLayers.Map("map");
- var layer = new OpenLayers.Layer.Vector(null, {
- drawn: true
- });
+ var layer = new OpenLayers.Layer.Vector();
map.addLayer(layer);
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(10, 10)
@@ -477,6 +475,7 @@
};
// draw feature with no state
+ layer.drawn = true;
layer.drawFeature(feature);
t.ok(log.feature === feature, "[no state] drawFeature called with correct feature");
t.ok(log.style.display !== "none", "[no state] drawFeature called with style display not none");
@@ -707,6 +706,54 @@
(-y + customStyle6.graphicYOffset).toFixed().toString(),
"graphicYOffset correctly set");
}
+ if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.SVG2') {
+ feature.style = customStyle1;
+ layer.drawFeature(feature);
+ var resolution = map.getResolution();
+ t.eq(root.firstChild.getAttributeNS(null, 'width'),
+ (2*customStyle1.pointRadius*resolution).toString(),
+ "given a pointRadius, width equals 2*pointRadius");
+ t.eq(root.firstChild.getAttributeNS(null, 'height'),
+ (2*customStyle1.pointRadius*resolution).toString(),
+ "given a pointRadius, height equals 2*pointRadius");
+ feature.style = customStyle2;
+ layer.drawFeature(feature);
+ t.eq(root.firstChild.getAttributeNS(null, 'width'),
+ root.firstChild.getAttributeNS(null, 'height'),
+ "given a graphicWidth, width equals height");
+ t.eq(root.firstChild.getAttributeNS(null, 'width'),
+ (customStyle2.graphicWidth*resolution).toString(),
+ "width is set correctly");
+ feature.style = customStyle3;
+ layer.drawFeature(feature);
+ t.eq(root.firstChild.getAttributeNS(null, 'height'),
+ root.firstChild.getAttributeNS(null, 'width'),
+ "given a graphicHeight, height equals width");
+ t.eq(root.firstChild.getAttributeNS(null, 'height'),
+ (customStyle3.graphicHeight*resolution).toString(),
+ "height is set correctly");
+ feature.style = customStyle4;
+ layer.drawFeature(feature);
+ t.eq(root.firstChild.getAttributeNS(null, 'height'),
+ (customStyle4.graphicHeight*resolution).toString(),
+ "given graphicHeight and graphicWidth, both are set: height");
+ t.eq(root.firstChild.getAttributeNS(null, 'width'),
+ (customStyle4.graphicWidth*resolution).toString(),
+ "given graphicHeight and graphicWidth, both are set: width");
+ feature.style = customStyle5;
+ layer.drawFeature(feature);
+ t.eq(root.firstChild.getAttributeNS(null, 'style'),
+ 'opacity: '+customStyle5.graphicOpacity.toString()+((OpenLayers.Util.getBrowserName() == "opera" || OpenLayers.Util.getBrowserName() == "safari") ? "" : ';'),
+ "graphicOpacity correctly set");
+ feature.style = customStyle6;
+ layer.drawFeature(feature);
+ t.eq(root.firstChild.getAttributeNS(null, 'x'),
+ (geometryX + customStyle6.graphicXOffset*resolution).toString(),
+ "graphicXOffset correctly set");
+ t.eq(root.firstChild.getAttributeNS(null, 'y'),
+ (-geometryY + customStyle6.graphicYOffset*resolution).toString(),
+ "graphicYOffset correctly set");
+ }
if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') {
feature.style = customStyle1;
layer.drawFeature(feature);
diff --git a/tests/Renderer/SVG2.html b/tests/Renderer/SVG2.html
new file mode 100644
index 0000000000..b4aaa283ce
--- /dev/null
+++ b/tests/Renderer/SVG2.html
@@ -0,0 +1,424 @@
+
+
+
+
+
+
+
+
+
diff --git a/tests/list-tests.html b/tests/list-tests.html
index 61c7b9e58f..920527f82f 100644
--- a/tests/list-tests.html
+++ b/tests/list-tests.html
@@ -185,6 +185,7 @@
Renderer/Canvas.html
Renderer/Elements.html
Renderer/SVG.html
+ Renderer/SVG2.html
Renderer/VML.html
Request.html
Request/XMLHttpRequest.html
diff --git a/tests/speed/vector-renderers.html b/tests/speed/vector-renderers.html
new file mode 100644
index 0000000000..4d88dfc009
--- /dev/null
+++ b/tests/speed/vector-renderers.html
@@ -0,0 +1,25 @@
+
+
+
+ Vector Features Performance Test
+
+
+
+
+
+ Vector Rendering Performance
+
+
+ This is a benchmark for vector rendering performance. Test results are
+ written to the debug console.
+ Select a renderer here:
+
+
+
+ The benchmark shows the time needed to render the features, and how long a
+ move (drag or zoom) takes. Drag and zoom around to produce move results.
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/speed/vector-renderers.js b/tests/speed/vector-renderers.js
new file mode 100644
index 0000000000..a11b36119e
--- /dev/null
+++ b/tests/speed/vector-renderers.js
@@ -0,0 +1,70 @@
+var map, vectorLayer, drawFeature, features
+
+map = new OpenLayers.Map('map', {
+ eventListeners: {
+ movestart: function() {
+ console.time("move");
+ },
+ moveend: function() {
+ console.timeEnd("move");
+ }
+ }
+});
+
+// allow testing of specific renderers via "?renderer=Canvas", etc
+var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
+renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
+
+vectorLayer = new OpenLayers.Layer.Vector("Vector Layer", {
+ isBaseLayer: true,
+ renderers: renderer,
+ eventListeners: {
+ beforefeaturesadded: function() {
+ console.time("addFeatures");
+ },
+ featuresadded: function() {
+ console.timeEnd("addFeatures");
+ }
+ }
+});
+
+map.addLayers([vectorLayer]);
+map.addControl(new OpenLayers.Control.MousePosition());
+map.setCenter(new OpenLayers.LonLat(0, 0), 2);
+
+features = new Array(500);
+var x, y, points
+for (var i = 0; i < 500; i++) {
+ x = 90-Math.random()*180;
+ y = 45-Math.random()*90;
+ var pointList = [];
+ for(var p=0; p<19; ++p) {
+ var a = p * (2 * Math.PI) / 20;
+ var r = Math.random() * 3 + 1;
+ var newPoint = new OpenLayers.Geometry.Point(x + (r * Math.cos(a)),
+ y + (r * Math.sin(a)));
+ pointList.push(newPoint);
+ }
+ pointList.push(pointList[0]);
+ features[i] = new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.LinearRing(pointList));
+
+}
+vectorLayer.addFeatures(features);
+
+var select = document.getElementById("renderers");
+var renderers = OpenLayers.Layer.Vector.prototype.renderers;
+var option;
+for (var i=0, len=renderers.length; i