From 2bf02bda35b3a705c1b596f81b8d0d0e3574fe0c Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 21 May 2009 22:02:05 +0000 Subject: [PATCH] Better fix for SVG rendering issues when redrawing complex graphics. Thanks tschaub for the investigation and the original patch which pointed me into the right direction. r=tschaub (pullup #2101) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9405 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Renderer/SVG.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Renderer/SVG.js b/lib/OpenLayers/Renderer/SVG.js index f3630f8c47..640447ebbf 100644 --- a/lib/OpenLayers/Renderer/SVG.js +++ b/lib/OpenLayers/Renderer/SVG.js @@ -291,23 +291,28 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { var href = "#" + id; pos = this.getPosition(node); widthFactor = this.symbolSize[id] / size; - // Only set the href if it is different from the current one. - // This is a workaround for strange rendering behavior in FF3. - if (node.getAttributeNS(this.xlinkns, "href") != href) { - node.setAttributeNS(this.xlinkns, "href", href); - } else if (size != parseFloat(node.getAttributeNS(null, "width"))) { - // hide the element (and force a reflow so it really gets - // hidden. This workaround is needed for Safari. - node.style.visibility = "hidden"; - this.container.scrollLeft = this.container.scrollLeft; + + // remove the node from the dom before we modify it. This + // prevents various rendering issues in Safari and FF + var parent = node.parentNode; + var nextSibling = node.nextSibling; + if(parent) { + parent.removeChild(node); } + + node.setAttributeNS(this.xlinkns, "href", href); node.setAttributeNS(null, "width", size); node.setAttributeNS(null, "height", size); node.setAttributeNS(null, "x", pos.x - offset); node.setAttributeNS(null, "y", pos.y - offset); - // set the visibility back to normal (after the Safari - // workaround above) - node.style.visibility = ""; + + // now that the node has all its new properties, insert it + // back into the dom where it was + if(nextSibling) { + parent.insertBefore(node, nextSibling); + } else if(parent) { + parent.appendChild(node); + } } else { node.setAttributeNS(null, "r", style.pointRadius); }