[OpenLayers-Users] Re: SVG in Firefox problem

Rainer Spittel fb3rasp at gmail.com
Mon Aug 29 19:34:58 EDT 2011


Hi everyone,

I think I found a solution for this. The underlaying problem seems to be in
the SVG.js class.
In general, the method setStyle builds up a href for SVG elements which uses
an anchor tag. If the base-URI is not in the local path, the relative href
does not work and it will not render the symbol. This seems to be a Firefox
specific issue.

Anyway, if you add the absolute path to the page to the href, then all SVG
symbols are rendered correctly, i.e.:

  node.setAttributeNS(this.xlinkns, "href", window.location.href + "#" +
href);

Because I don't like to modify the core, I apply a patch in my mapping app
as follow:

if (jQuery.browser.mozilla) {
	var setStyleWithoutFirefoxPatch =
OpenLayers.Renderer.SVG.prototype.setStyle;
	OpenLayers.Renderer.SVG.prototype.setStyle = function(node, style, options)
{
		var rv = setStyleWithoutFirefoxPatch.call(this, node, style, options);
	
		if (node && node.getAttributeNS) {
		   	var href = node.getAttributeNS(this.xlinkns, "href");
			if (href && href.charAt(0) == '#') {
		    	node.setAttributeNS(this.xlinkns, "href", window.location.href +
href);
			}
		}
		return rv;
	}
}

I need to do some cross browser testing to see if the browser condition
needs to be more generic. The patch here requires jQuery.

Thanks,
Rainer

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/SVG-in-Firefox-problem-tp6735584p6740261.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list