fixed rotation center for non-square symbols in non-defs mode (Webkit). r=bartvde (closes #2499)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10136 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-03-20 21:50:39 +00:00
parent 35168dc219
commit 7632e54a4d
2 changed files with 18 additions and 10 deletions

View File

@@ -41,10 +41,12 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
translationParameters: null,
/**
* Property: symbolSize
* {Object} Cache for symbol sizes according to their svg coordinate space
* 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].
*/
symbolSize: {},
symbolMetrics: null,
/**
* Property: isGecko
@@ -75,6 +77,8 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
this.translationParameters = {x: 0, y: 0};
this.supportUse = (navigator.userAgent.toLowerCase().indexOf("applewebkit/5") == -1);
this.isGecko = (navigator.userAgent.toLowerCase().indexOf("gecko/") != -1);
this.symbolMetrics = {};
},
/**
@@ -298,7 +302,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
var size = offset * 2;
var id = this.importSymbol(style.graphicName);
pos = this.getPosition(node);
widthFactor = this.symbolSize[id] / size;
widthFactor = this.symbolMetrics[id][0] * 3 / size;
// remove the node from the dom before we modify it. This
// prevents various rendering issues in Safari and FF
@@ -344,10 +348,10 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
"rotate(" + rotation + " " + pos.x + " " +
pos.y + ")");
} else {
var symbolCenter = 0.5 * this.symbolSize[id] / 3;
node.firstChild.setAttributeNS(null, "transform",
"rotate(" + rotation + " " + symbolCenter +
" " + symbolCenter + ")");
var metrics = this.symbolMetrics[id]
node.firstChild.setAttributeNS(null, "transform",
"rotate(" + style.rotation + " " + metrics[1] +
" " + metrics[2] + ")");
}
}
}
@@ -932,7 +936,11 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
var viewBox = [symbolExtent.left - width,
symbolExtent.bottom - height, width * 3, height * 3];
symbolNode.setAttributeNS(null, "viewBox", viewBox.join(" "));
this.symbolSize[id] = Math.max(width, height) * 3;
this.symbolMetrics[id] = [
Math.max(width, height),
symbolExtent.getCenterLonLat().lon,
symbolExtent.getCenterLonLat().lat
];
this.defs.appendChild(symbolNode);
return symbolNode.id;