1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/**
* Method: drawText
* This method is only called by the renderer itself.
*
* Parameters:
* featureId - {String}
* style -
* location - {<OpenLayers.Geometry.Point>}
*/
OpenLayers.Renderer.VML.prototype.drawText= function(featureId, style, location) {
// If the user wants a halo, first draw the text with a
// thick stroke (using the halo color) and then draw the
// text normally over that
// Idea from:
// http://www.mail-archive.com/svg-developers@yahoogroups.com/msg01002.html
if (style.labelHaloColor) {
var haloStyle = OpenLayers.Util.extend({}, style);
haloStyle.fontStrokeColor = haloStyle.labelHaloColor;
haloStyle.fontStrokeWidth = haloStyle.labelHaloWidth || 2;
delete haloStyle.labelHaloColor;
if (haloStyle.labelBackgroundColor) {
delete haloStyle.labelBackgroundColor;
}
if (haloStyle.labelBorderColor) {
delete haloStyle.labelBorderColor;
}
if (haloStyle.labelBorderSize) {
delete haloStyle.labelBorderSize;
}
this.drawText2(featureId, haloStyle, location, true);
delete style.labelHaloColor;
if (style.labelHaloWidth) {
delete style.labelHaloWidth;
}
this.drawText2(featureId, style, location, false);
return;
}
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) | 0) + "px";
label.style.top = ((location.y/resolution - this.offset.y) | 0) + "px";
label.style.flip = "y";
textbox.innerText = style.label;
if (style.labelBackgroundColor) {
textbox.style.backgroundColor = style.labelBackgroundColor;
}
if (style.labelBorderColor || style.labelBorderSize) {
textbox.style.border = "solid " +
(style.labelBorderSize ? style.labelBorderSize : "1px") + " " +
(style.labelBorderColor ? style.labelBorderColor : "#000000");
}
if (style.fontColor) {
textbox.style.color = style.fontColor;
}
if (style.fontOpacity) {
textbox.style.filter = 'alpha(opacity=' + (style.fontOpacity * 100) + ')';
}
if (style.fontFamily) {
textbox.style.fontFamily = style.fontFamily;
}
if (style.fontSize) {
textbox.style.fontSize = style.fontSize;
}
if (style.fontWeight) {
textbox.style.fontWeight = style.fontWeight;
}
if (style.labelSelect === true) {
label._featureId = featureId;
textbox._featureId = featureId;
textbox._geometry = location;
textbox._geometryClass = location.CLASS_NAME;
}
textbox.style.whiteSpace = "nowrap";
// fun with IE: IE7 in standards compliant mode does not display any
// text with a left inset of 0. So we set this to 1px and subtract one
// pixel later when we set label.style.left
textbox.inset = "1px,0px,0px,0px";
if(!label.parentNode) {
label.appendChild(textbox);
this.textRoot.appendChild(label);
}
var align = style.labelAlign || "cm";
if (align.length == 1) {
align += "m";
}
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-1+"px";
label.style.top = parseInt(label.style.top)+yshift+"px";
};
/**
* Method: drawText2
* This method is only called by the renderer itself.
* See also http://trac.openlayers.org/ticket/2965 (label halo)
*
* Parameters:
* featureId - {String}
* style -
* location - {<OpenLayers.Geometry.Point>}
* useHalo - {Boolean}
*/
OpenLayers.Renderer.VML.prototype.drawText2= function(featureId, style, location, useHalo) {
var label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX +
(useHalo ? this.HALO_ID_SUFFIX : ""), "olv:shape");
// Add it to the DOM hierarchy
if(!label.parentNode) {
this.textRoot.appendChild(label);
}
// Set its dimension and position attributes
var resolution = this.getResolution();
label.style.left = ((location.x/resolution - this.offset.x) | 0) + "px";
label.style.top = ((location.y/resolution - this.offset.y) | 0) + "px";
label.style.flip = "y";
label.style.position = "absolute";
label.style.width = 1 + "px"; // some dummy value
label.style.height = 1 + "px"; // some dummy value
label.style.antialias = "true";
/*
// TODO: use built-in setStyle method for building style
var nodeStyle = { fillColor: style.fontColor,
fillOpacity: style.fontOpacity,
strokeColor: style.fontStrokeColor,
strokeWidth: style.fontHaloSize || 2,
strokeOpacity: style.fontOpacity
}
var nodeOptions = {
isFilled: style.fontColor,
isStroked: style.fontStrokeColor
}
this.setStyle(label, nodeStyle, nodeOptions, null);
*/
// Create the fill object
var myFill = document.createElement("olv:fill");
myFill.on = "true";
myFill.color = style.fontColor;
// Add it to the DOM hierarchy
label.appendChild(myFill);
// Create the stroke object. We need to define the
// stroke explicitly, otherwise we get a default
// black outline
var myStroke = document.createElement("olv:stroke");
if (style.fontStrokeColor) {
myStroke.on = "true";
myStroke.color = style.fontStrokeColor;
} else {
myStroke.on = "false";
}
if (style.fontStrokeWidth) {
myStroke.weight = style.fontStrokeWidth;
}
// Add it to the DOM hierarchy
label.appendChild(myStroke);
// Create the path object
var myPath = document.createElement("olv:path");
myPath.textpathok = "True";
myPath.v = "m 0,0 l 200,0";
// Add it to the DOM hierarchy
label.appendChild(myPath);
// Create the textpath object
var myTextPath = document.createElement("olv:textpath");
myTextPath.on = "true";
myTextPath.fitpath = "false";
myTextPath.string = style.label;
label.appendChild(myTextPath);
if (style.fontColor) {
myTextPath.style.color = style.fontColor;
}
if (style.fontOpacity) {
myFill.opacity = style.fontOpacity;
myStroke.opacity = style.fontOpacity;
}
// Setting the font family does not seem to work
// TODO: make this work!
if (style.fontFamily) {
myTextPath.style.fontFamily = style.fontFamily;
}
if (style.fontSize) {
myTextPath.style.fontSize = style.fontSize;
}
if (style.fontWeight) {
myTextPath.style.fontWeight = style.fontWeight;
}
var align = style.labelAlign || "cm";
if (align.length == 1) {
align += "m";
}
// Set the horizontal align
var hAlign;
switch (align.substr(0,1)) {
case 'l': hAlign = "left"; break;
case 'c': hAlign = "center"; break;
case 'r': hAlign = "right"; break;
}
myTextPath.style['v-text-align'] = hAlign;
if (style.labelSelect === true) {
label._featureId = featureId;
label._geometry = location;
label._geometryClass = location.CLASS_NAME;
}
myTextPath.style.whiteSpace = "nowrap";
// fun with IE: IE7 in standards compliant mode does not display any
// text with a left inset of 0. So we set this to 1px and subtract one
// pixel later when we set label.style.left
myTextPath.inset = "1px,0px,0px,0px";
var xshift = myTextPath.clientWidth *
(OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(0,1)]);
var yshift = myTextPath.clientHeight *
(OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(1,1)]);
label.style.left = parseInt(label.style.left)-xshift-1+"px";
label.style.top = parseInt(label.style.top)+yshift+"px";
}; |
Partager