If several layers use same externalGraphic URL, imageLoadedCallback() only called for one
richard-thomas opened this issue · 3 comments
If several layers use the same externalGraphic URL, imageLoadedCallback() will only be called for the first layer encountered. Thus if a second layer is being styled with the same imageURL, that layer will never be updated to use the externalGraphic image. Specifically, in function processExternalGraphicSymbolizers(), for the second (or subsequent) layer, if (imageLoadingState === IMAGE_LOADING) the second layer's imageLoadedCallback() function will be discarded.
I am wondering if there is an easy fix using a layer's "invalidated" flag, but haven't followed through the logic of how that works. One option would be to store a "callbacks" object containing multiple imageLoadedCallback() functions for each imageURL to be called in succession by the "image.onload" function. If this "callbacks" object uses the layer id as a key then that would avoid the problem of generating unnecessary callbacks when processExternalGraphicSymbolizers() is being executed for multiple symbols on one layer.
If it would help I can put together some code to demonstrate the problem sometime in the next day or two?
I can reproduce the bug with unit tests, so no need to demonstrate the problem. I can now try to make those failing tests pass.
It might take a while to fix this correctly. I also have to take into account the difference between creating two style functions from the same style object, or two style functions from different style objects that happen to reference the same image url. The image caching and style invalidation code is a bit hairy.
I have published v0.2.11 of SLDReader. Can you check if this fixes the callback problem?
Yes that works well with my code - and apparently without any unnecessary callbacks for multiple symbols on the same layer. I'm very happy for you to close the issue and thanks for the very speedy fix!