Measure height only once per font
This commit is contained in:
@@ -135,18 +135,22 @@ ol.render.canvas.TextReplay.labelCache_ = new ol.structs.LRUCache();
|
|||||||
*/
|
*/
|
||||||
ol.render.canvas.TextReplay.measureTextHeight = (function() {
|
ol.render.canvas.TextReplay.measureTextHeight = (function() {
|
||||||
var span;
|
var span;
|
||||||
return function(font, lines, widths) {
|
var heights = {};
|
||||||
if (!span) {
|
return function(font) {
|
||||||
span = document.createElement('span');
|
var height = heights[font];
|
||||||
span.textContent = 'M';
|
if (height == undefined) {
|
||||||
span.style.margin = span.style.padding = '0 !important';
|
if (!span) {
|
||||||
span.style.position = 'absolute !important';
|
span = document.createElement('span');
|
||||||
span.style.left = '-99999px !important';
|
span.textContent = 'M';
|
||||||
|
span.style.margin = span.style.padding = '0 !important';
|
||||||
|
span.style.position = 'absolute !important';
|
||||||
|
span.style.left = '-99999px !important';
|
||||||
|
}
|
||||||
|
span.style.font = font;
|
||||||
|
document.body.appendChild(span);
|
||||||
|
height = heights[font] = span.offsetHeight;
|
||||||
|
document.body.removeChild(span);
|
||||||
}
|
}
|
||||||
span.style.font = font;
|
|
||||||
document.body.appendChild(span);
|
|
||||||
var height = span.offsetHeight;
|
|
||||||
document.body.removeChild(span);
|
|
||||||
return height;
|
return height;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user