From 45c420782c3d923403c75ce93277725d728bb312 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sat, 15 Dec 2007 16:24:31 +0000 Subject: [PATCH] Don't flip SVG Y values anymore, since we're working in pixel space these days, and the Y transforms just make working with the SVG directly -- for example, with people modifying it to support text -- more difficult than it should be. git-svn-id: http://svn.openlayers.org/trunk/openlayers@5430 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Renderer/SVG.js | 15 ++++----------- tests/Renderer/test_SVG.html | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Renderer/SVG.js b/lib/OpenLayers/Renderer/SVG.js index 8f1dd0928f..c5a34da7a6 100644 --- a/lib/OpenLayers/Renderer/SVG.js +++ b/lib/OpenLayers/Renderer/SVG.js @@ -215,11 +215,10 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { var opacity = style.graphicOpacity || style.fillOpacity; node.setAttributeNS(null, "x", (x + xOffset).toFixed()); - node.setAttributeNS(null, "y", (-y + yOffset).toFixed()); + node.setAttributeNS(null, "y", (y + yOffset).toFixed()); node.setAttributeNS(null, "width", width); node.setAttributeNS(null, "height", height); node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); - node.setAttributeNS(null, "transform", "scale(1,-1)"); node.setAttributeNS(null, "style", "opacity: "+opacity); } else { node.setAttributeNS(null, "r", style.pointRadius); @@ -304,13 +303,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { */ createRoot: function() { var id = this.container.id + "_root"; - var root = this.nodeFactory(id, "g"); - - // flip the SVG display Y axis upside down so it - // matches the display Y axis of the map - root.setAttributeNS(null, "transform", "scale(1, -1)"); - return root; }, @@ -344,7 +337,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { drawCircle: function(node, geometry, radius) { var resolution = this.getResolution(); var x = (geometry.x / resolution + this.left); - var y = (geometry.y / resolution - this.top); + var y = (this.top - geometry.y / resolution); if (this.inValidRange(x, y)) { node.setAttributeNS(null, "cx", x); @@ -423,7 +416,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { drawRectangle: function(node, geometry) { var resolution = this.getResolution(); var x = (geometry.x / resolution + this.left); - var y = (geometry.y / resolution - this.top); + var y = (this.top - geometry.y / resolution); if (this.inValidRange(x, y)) { node.setAttributeNS(null, "x", x); @@ -504,7 +497,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { getShortString: function(point) { var resolution = this.getResolution(); var x = (point.x / resolution + this.left); - var y = (point.y / resolution - this.top); + var y = (this.top - point.y / resolution); if (this.inValidRange(x, y)) { return x + "," + y; diff --git a/tests/Renderer/test_SVG.html b/tests/Renderer/test_SVG.html index 842823094f..4cc71b0fb1 100644 --- a/tests/Renderer/test_SVG.html +++ b/tests/Renderer/test_SVG.html @@ -144,7 +144,7 @@ r.drawCircle(node, geometry, 3); t.eq(node.getAttributeNS(null, 'cx'), '2', "cx is correct"); - t.eq(node.getAttributeNS(null, 'cy'), '4', "cy is correct"); + t.eq(node.getAttributeNS(null, 'cy'), '-4', "cy is correct"); t.eq(node.getAttributeNS(null, 'r'), '3', "r is correct"); } @@ -271,7 +271,7 @@ r.drawRectangle(node, geometry); t.eq(node.getAttributeNS(null, "x"), "2", "x attribute is correctly set"); - t.eq(node.getAttributeNS(null, "y"), "4", "y attribute is correctly set"); + t.eq(node.getAttributeNS(null, "y"), "-4", "y attribute is correctly set"); t.eq(node.getAttributeNS(null, "width"), "6", "width attribute is correctly set"); t.eq(node.getAttributeNS(null, "height"), "8", "height attribute is correctly set"); } @@ -355,7 +355,7 @@ }; var string = r.getShortString(point); - t.eq(string, "2,4", "returned string is correct"); + t.eq(string, "2,-4", "returned string is correct"); }