Avoid creating unnecessary images in tile layers #3246
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When rendering tiled layers, we call
source.getTile()
many times while looking for loaded images at alternate zoom levels. For image tile layers, calls togetTile
createImage
elements. When we only need to check if a tile is loaded, it is unnecessary to create a new tile with an unusedImage
.Since all of the
ol.source.Tile
types create a tile cache in the same way and have the same implementation ofcanExpireCache
andexpireCache
, we can move the repeated code to theol.source.Tile
base class (see 2cf1fe5).Then, since an image cannot already have the loaded state if it is not in the cache, the check for loaded images can avoid calling
getTile
and instead check the cache (see e5432f7). The DOM and Canvas tile layer renderers can share the same implementation ofcreateLoadedTileFinder
function. The WebGL renderer needs a custom implementation since it also checks with the map renderer to see if the tile texture is loaded.Without these changes, the first rendering of the full screen example (not in full screen mode) fills the cache with 80 images though only 12 are used (on my current screen width). And these extra cached images are not used as you zoom out. By the time I zoom out to level one, about 1350
Image
elements have been created. On this branch, the same sequence (zooming one step at a time to level 1) creates 350Image
elements.