More efficient font checking loop
This commit is contained in:
@@ -91,7 +91,7 @@ ol.render.canvas.labelCache = new ol.structs.LRUCache();
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {!Object.<string, boolean>}
|
* @type {!Object.<string, (number)>}
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.checkedFonts_ = {};
|
ol.render.canvas.checkedFonts_ = {};
|
||||||
|
|
||||||
@@ -128,29 +128,39 @@ ol.render.canvas.checkFont = (function() {
|
|||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
var done = true;
|
||||||
|
for (var font in checked) {
|
||||||
|
if (checked[font] < 60) {
|
||||||
|
if (isAvailable(font)) {
|
||||||
|
checked[font] = 60;
|
||||||
|
labelCache.clear();
|
||||||
|
} else {
|
||||||
|
++checked[font];
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!done) {
|
||||||
|
window.setTimeout(check, 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return function(fontSpec) {
|
return function(fontSpec) {
|
||||||
var fontFamilies = ol.css.getFontFamilies(fontSpec);
|
var fontFamilies = ol.css.getFontFamilies(fontSpec);
|
||||||
if (!fontFamilies) {
|
if (!fontFamilies) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fontFamilies.forEach(function(fontFamily) {
|
for (var i = 0, ii = fontFamilies.length; i < ii; ++i) {
|
||||||
if (!checked[fontFamily]) {
|
var fontFamily = fontFamilies[i];
|
||||||
checked[fontFamily] = true;
|
if (!(fontFamily in checked)) {
|
||||||
|
checked[fontFamily] = 60;
|
||||||
if (!isAvailable(fontFamily)) {
|
if (!isAvailable(fontFamily)) {
|
||||||
var callCount = 0;
|
checked[fontFamily] = 0;
|
||||||
var interval = window.setInterval(function() {
|
window.setTimeout(check, 25);
|
||||||
++callCount;
|
|
||||||
var available = isAvailable(fontFamily);
|
|
||||||
if (available || callCount >= 60) {
|
|
||||||
window.clearInterval(interval);
|
|
||||||
if (available) {
|
|
||||||
labelCache.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 25);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -596,7 +596,7 @@ ol.render.canvas.Replay.prototype.replay_ = function(
|
|||||||
chars = /** @type {string} */ (part[4]);
|
chars = /** @type {string} */ (part[4]);
|
||||||
label = /** @type {ol.render.canvas.TextReplay} */ (this).getImage(chars, false, true);
|
label = /** @type {ol.render.canvas.TextReplay} */ (this).getImage(chars, false, true);
|
||||||
anchorX = /** @type {number} */ (part[2]) + strokeWidth;
|
anchorX = /** @type {number} */ (part[2]) + strokeWidth;
|
||||||
anchorY = baseline * label.height + (0.5 - baseline) * strokeWidth - offsetY;
|
anchorY = baseline * label.height + (0.5 - baseline) * 2 * strokeWidth - offsetY;
|
||||||
this.replayImage_(context,
|
this.replayImage_(context,
|
||||||
/** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
|
/** @type {number} */ (part[0]), /** @type {number} */ (part[1]), label,
|
||||||
anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
|
anchorX, anchorY, declutterGroup, label.height, 1, 0, 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user