Merge pull request #10243 from ahocevar/fix-font-measure

Store correct font value
This commit is contained in:
Andreas Hocevar
2019-11-02 14:08:03 +01:00
committed by GitHub
3 changed files with 18 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -65,6 +65,22 @@ feature.setStyle(new Style({
}));
vectorSource.addFeature(feature);
// align left
feature = new Feature({
geometry: new Point([50, 50])
});
feature.setStyle(new Style({
text: new Text({
font: 'Ubuntu',
text: 'align left',
textAlign: 'left',
stroke: new Stroke({
color: [10, 10, 10, 0.5]
})
})
}));
vectorSource.addFeature(feature);
// background and padding
feature = new Feature({
geometry: new Point([-10, 0])

View File

@@ -333,7 +333,8 @@ export const measureTextHeight = (function() {
export function measureTextWidth(font, text) {
const measureContext = getMeasureContext();
if (font != measureFont) {
measureContext.font = measureFont = font;
measureContext.font = font;
measureFont = measureContext.font;
}
return measureContext.measureText(text).width;
}