openlayers icon indicating copy to clipboard operation
openlayers copied to clipboard

Post processing of ol/source/WMTS tiles

Open M393 opened this issue 6 months ago • 3 comments

Is your feature request related to a problem? Please describe. I'd like to replace the background-color from white to tranparent for tiles loaded with an ol/source/WMTS. Here is my first attempt at that, which works, but in some cases the original tile including the white background is displayed for a split second.

My second attempt uses a subclass of ol/DataTile with the same constructor interface as ol/ImageTile and resolves the white flashing, but according to the apidocs only a subclass of ol/ImageTile may be used. https://github.com/openlayers/openlayers/blob/7cf17b80aeefe7e6de867703f4239b362b19496b/src/ol/source/WMTS.js#L34

Describe the solution you'd like Achieve my goal in an api-compatible way. The tileClass config option seems to be too restrictive for that.

M393 avatar Jun 20 '25 10:06 M393

You can use the ImageTile source with a loader. In the loader, post-process the fetched image and (asynchronously) return a canvas or ImageBitmap.

ahocevar avatar Jun 20 '25 12:06 ahocevar

You can use the TileImage source with a loader.

Assuming you meant an ol/source/ImageTile. I see the classes ol/source/WMTS inherits from are deprecated, is it planned to switch the inheritance of ol/source/WMTS to ol/source/ImageTile?

Currently ol/source/WMTS creates the tile url for me. With an ol/source/ImageTile I'd have to manually add the WMTS parameters to the url. I'll probably also need the same functionality for an ol/source/TileWMS.

Is there any way to have OpenLayers create the complete url for me with ol/source/ImageTile?

Thanks for taking the time to respond.

M393 avatar Jun 20 '25 12:06 M393

The idea would be to provide URL functions, like those in the ol/source namespace (wms, mapserver, etc.) for WMTS, and make sure the existing ones work for ol/source/ImageTile too. Sources like ol/source/WMTS would then only be small wrappers around these url functions. We did the same for all ol/source/Image subclasses.

If you're interested to help out, a start with WMTS would be appreciated.

ahocevar avatar Jun 21 '25 16:06 ahocevar