added support for text labels. This also adds getCentroid methods to all
geometries. Thanks crschmidt for the great help with this patch, and thanks to camptocamp for the initial work on this and rcoup for creating the first patches. r=crschmidt (closes #1895) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9262 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -108,13 +108,19 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
left = left - this.offset.x;
|
||||
top = top - this.offset.y;
|
||||
}
|
||||
|
||||
|
||||
var org = left + " " + top;
|
||||
this.root.setAttribute("coordorigin", org);
|
||||
var roots = [this.root, this.vectorRoot, this.textRoot];
|
||||
var root;
|
||||
for(var i=0, len=roots.length; i<len; ++i) {
|
||||
root = roots[i];
|
||||
|
||||
var size = this.size.w + " " + this.size.h;
|
||||
this.root.setAttribute("coordsize", size);
|
||||
|
||||
var size = this.size.w + " " + this.size.h;
|
||||
root.setAttribute("coordsize", size);
|
||||
|
||||
}
|
||||
// flip the VML display Y axis upside down so it
|
||||
// matches the display Y axis of the map
|
||||
this.root.style.flip = "y";
|
||||
@@ -132,12 +138,23 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
*/
|
||||
setSize: function(size) {
|
||||
OpenLayers.Renderer.prototype.setSize.apply(this, arguments);
|
||||
|
||||
this.rendererRoot.style.width = this.size.w + "px";
|
||||
this.rendererRoot.style.height = this.size.h + "px";
|
||||
|
||||
this.root.style.width = this.size.w + "px";
|
||||
this.root.style.height = this.size.h + "px";
|
||||
|
||||
// setting width and height on all roots to avoid flicker which we
|
||||
// would get with 100% width and height on child roots
|
||||
var roots = [
|
||||
this.rendererRoot,
|
||||
this.root,
|
||||
this.vectorRoot,
|
||||
this.textRoot
|
||||
];
|
||||
var w = this.size.w + "px";
|
||||
var h = this.size.h + "px";
|
||||
var root;
|
||||
for(var i=0, len=roots.length; i<len; ++i) {
|
||||
root = roots[i];
|
||||
root.style.width = w;
|
||||
root.style.height = h;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -582,12 +599,15 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
/**
|
||||
* Method: createRoot
|
||||
* Create the main root element
|
||||
*
|
||||
* Parameters:
|
||||
* suffix - {String} suffix to append to the id
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} The main root element to which we'll add vectors
|
||||
* {DOMElement}
|
||||
*/
|
||||
createRoot: function() {
|
||||
return this.nodeFactory(this.container.id + "_root", "olv:group");
|
||||
createRoot: function(suffix) {
|
||||
return this.nodeFactory(this.container.id + suffix, "olv:group");
|
||||
},
|
||||
|
||||
/**************************************
|
||||
@@ -762,6 +782,55 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
|
||||
return node;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawText
|
||||
* This method is only called by the renderer itself.
|
||||
*
|
||||
* Parameters:
|
||||
* featureId - {String}
|
||||
* style -
|
||||
* location - {<OpenLayers.Geometry.Point>}
|
||||
*/
|
||||
drawText: function(featureId, style, location) {
|
||||
var label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX, "olv:rect");
|
||||
var textbox = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_textbox", "olv:textbox");
|
||||
|
||||
var resolution = this.getResolution();
|
||||
label.style.left = (location.x/resolution - this.offset.x).toFixed() + "px";
|
||||
label.style.top = (location.y/resolution - this.offset.y).toFixed() + "px";
|
||||
label.style.flip = "y";
|
||||
|
||||
textbox.innerText = style.label;
|
||||
|
||||
if (style.fillColor) {
|
||||
textbox.style.color = style.fontColor;
|
||||
}
|
||||
if (style.fontFamily) {
|
||||
textbox.style.fontFamily = style.fontFamily;
|
||||
}
|
||||
if (style.fontSize) {
|
||||
textbox.style.fontSize = style.fontSize;
|
||||
}
|
||||
if (style.fontWeight) {
|
||||
textbox.style.fontWeight = style.fontWeight;
|
||||
}
|
||||
textbox.style.whiteSpace = "nowrap";
|
||||
textbox.inset = "0px,0px,0px,0px";
|
||||
|
||||
if(!label.parentNode) {
|
||||
label.appendChild(textbox);
|
||||
this.textRoot.appendChild(label);
|
||||
}
|
||||
|
||||
var align = style.labelAlign || "cm";
|
||||
var xshift = textbox.clientWidth *
|
||||
(OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(0,1)]);
|
||||
var yshift = textbox.clientHeight *
|
||||
(OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(1,1)]);
|
||||
label.style.left = parseInt(label.style.left)-xshift+"px";
|
||||
label.style.top = parseInt(label.style.top)+yshift+"px";
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawSurface
|
||||
@@ -886,3 +955,16 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
|
||||
CLASS_NAME: "OpenLayers.Renderer.VML"
|
||||
});
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Renderer.VML.LABEL_SHIFT
|
||||
* {Object}
|
||||
*/
|
||||
OpenLayers.Renderer.VML.LABEL_SHIFT = {
|
||||
"l": 0,
|
||||
"c": .5,
|
||||
"r": 1,
|
||||
"t": 0,
|
||||
"m": .5,
|
||||
"b": 1
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user