diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 7447acace7..573c0276ef 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -54,7 +54,7 @@ import {create as createTransform, apply as applyTransform} from './transform.js /** - * @typedef {function(PluggableMap, ?FrameState): boolean} PostRenderFunction + * @typedef {function(PluggableMap, ?FrameState): any} PostRenderFunction */ diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index 9bbbc61115..7555ec3335 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -280,7 +280,9 @@ class MapRenderer extends Disposable { * @protected */ scheduleExpireIconCache(frameState) { - frameState.postRenderFunctions.push(/** @type {import("../PluggableMap.js").PostRenderFunction} */ (expireIconCache)); + if (iconImageCache.canExpireCache()) { + frameState.postRenderFunctions.push(expireIconCache); + } } /** diff --git a/src/ol/style/IconImageCache.js b/src/ol/style/IconImageCache.js index 0780d814e1..b9809c7c89 100644 --- a/src/ol/style/IconImageCache.js +++ b/src/ol/style/IconImageCache.js @@ -37,11 +37,18 @@ class IconImageCache { this.cacheSize_ = 0; } + /** + * @return {boolean} Can expire cache. + */ + canExpireCache() { + return this.cacheSize_ > this.maxCacheSize_; + } + /** * FIXME empty description for jsdoc */ expire() { - if (this.cacheSize_ > this.maxCacheSize_) { + if (this.canExpireCache()) { let i = 0; for (const key in this.cache_) { const iconImage = this.cache_[key];