SVG externalgraphic files loaded as Image()
richard-thomas opened this issue · 1 comments
sldreader attempts to load SVG in external files as Image( ) in function loadExternalGraphic() which amongst other things will trigger image.onerror (instead of image.onload) callback as such files are not raster images. Strangely when running under Webpack (5.8.0) webpack-dev-server (3.11.0), it does actually call image.onload and my SVG images are correctly rendered. I do not understand why this should be as the standard JavaScript behaviour is to give an error on loading if setting image.src to an SVG file.
The outcome in my code is that SVG files although actually loaded by the browser (as visible in the Inspector Network tab) are then ignored and the fallback symbology is used. I should add that the imageLoadedCallback() function is otherwise proving very useful for me to update Canvas elements (part of a legend) with PNG (& SVG) when they have finally loaded, instead of blocking rendering of the whole legend.
Tested with sldreader 0.2.8 in Chrome 88.0.4324.104 (Official Build) (64-bit) under Windows 10.
Not a bug - sorry for the misdirection! After a bit more investigation, I now understand that SVG is a valid format to load with Image(). The problem I had was that the basic HTTP server I was using served SVG files with mime type 'image/svg-xml' instead of 'image/svg+xml'. This causes the browser to refuse to render the SVG and flag an "image.onerror" event. Unfortunately this means I need to find a new basic Android web server as "Tiny Web Server" cannot be configured to fix the SVG mime time.