I have a large number of cached vector features which I am caching for speed. However, as they need to change size depending on view resolution, I have to do various updates on them with each increment, which sort of defeats the purpose of caching.
Is there a way for cached styles to update their scale (and other options, like offSet) when resolution changes?
Here's the basic code:
const imageVectorStyle = function(image, resolution) {
// Caching both the style and the icon, fyi.
let style = styleCache[image.getProperties().name];
if (style) {
//The style exists in the cache, but since the resolution has changed
//since caching, I have to update the scale.
style.getImage().setScale(1 / resolution);
return style
}
else {
const imageProperties = image.getProperties();
let imageIcon = iconcache[imageProperties.src];
if (!imageIcon) {
imageIcon = new Icon({
offset: imageProperties.offset,
size: imageProperties.size,
stroke: new Stroke({color: '#dee2e6', width: 1 }),
// Here scale is set based on resolution when the style is first created.
scale: 1 / resolution,
crossOrigin: 'anonymous',
src: imageProperties.src
});
}
}
}