Make text height detection independent of css settings

This commit is contained in:
Andreas Hocevar
2017-10-11 00:21:29 +02:00
parent 80dbedf946
commit 1fcb94a29c

View File

@@ -126,18 +126,19 @@ ol.render.canvas.TextReplay.labelCache_ = new ol.structs.LRUCache();
* @return {ol.Size} Measurement. * @return {ol.Size} Measurement.
*/ */
ol.render.canvas.TextReplay.measureTextHeight = (function() { ol.render.canvas.TextReplay.measureTextHeight = (function() {
var textContainer; var span;
return function(font, lines, widths) { return function(font, lines, widths) {
if (!textContainer) { if (!span) {
textContainer = document.createElement('span'); span = document.createElement('span');
textContainer.textContent = 'M'; span.textContent = 'M';
textContainer.style.visibility = 'hidden'; span.style.margin = span.style.padding = '0 !important';
textContainer.style.whiteSpace = 'nowrap'; span.style.position = 'absolute !important';
span.style.left = '-99999px !important';
} }
textContainer.style.font = font; span.style.font = font;
document.body.appendChild(textContainer); document.body.appendChild(span);
var height = textContainer.offsetHeight; var height = span.offsetHeight;
document.body.removeChild(textContainer); document.body.removeChild(span);
return height; return height;
}; };
})(); })();