Skip to content

Commit 7c8974a

Browse files
authored
Merge pull request #1309 from openlayers/clear-measure-cache
Clear text measure cache when loaded fonts have changed
2 parents 3531e47 + a7f5d46 commit 7c8974a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/text.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import mb2css from 'mapbox-to-css-font';
2+
import {checkedFonts} from 'ol/render/canvas.js';
23
import {createCanvas} from './util.js';
34

45
const hairSpacePool = Array(256).join('\u200A');
@@ -37,6 +38,12 @@ function measureText(text, letterSpacing) {
3738
}
3839

3940
const measureCache = {};
41+
checkedFonts.on('propertychange', () => {
42+
for (const key in measureCache) {
43+
delete measureCache[key];
44+
}
45+
});
46+
4047
export function wrapText(text, font, em, letterSpacing) {
4148
if (text.indexOf('\n') !== -1) {
4249
const hardLines = text.split('\n');

0 commit comments

Comments
 (0)