When using openlayers (v4.6.4) with font-awesome as marker icons, the icons do not display upon first load (even after clearing cache and hard reload). Instead, I see a rectangle resembling a broken character. It is only on the second load that they appear correctly.
https://i.stack.imgur.com/NrO5G.png
var mapMarkerIcon = new ol.style.Style({
text: new ol.style.Text({
text: '\uf041 ', // <-- fa marker unicode
font: 'Normal ' + 24 + 'px ' + 'FontAwesome',
textBaseline: 'bottom',
fill: new ol.style.Fill({
color: green,
})
})
});
It seems like openlayers tries to draw the unicode icon code before the fontawesome CSS has fully loaded. Only upon the second refresh when the CSS is cached does it work properly.
I cannot expect all users to manually refresh twice. Does anyone have suggestions on how to address this issue?
Is there a way to make JavaScript wait for the CSS to load?
I am considering loading just the specific needed icon (the map-marker) to speed up rendering, but even then, there's no guarantee that the CSS will be ready before the JS executes.
Could adding a small piece of javascript to redraw the icons after a short delay help?