Unable to load WMTSTileSource url, in CustomJS, CORS policy: No 'Access-Control-Allow-Origin'

Hi, setting the WMTSTileSource url works fine in python, but bokeh cant load it inside a CustomJS.

Getting the error “Access to image at ‘https://tile.openstreetmap.org/{z}/{x}/{y}.png’ from origin ‘https://xxxx.xxxxxxx.ca’ has been blocked by Access to image at ‘https://tile.openstreetmap.org/{z}/{x}/{y}.png’ from origin ‘https://xxxx.xxxxxxx.ca’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

I changed my personal address above to xxxx.xxx…

Does bokeh have a way around this? like sending the Get to a proxy or something? I bet changing the Vendors (bokeh.tile_providers — Bokeh 2.3.2 Documentation) in a CustomJS could get around this, but Vendorsdoesnt appear to exist in my WMTSTileSource…

Minimal example here:

from bokeh.models import WMTSTileSource, Button, CustomJS
from bokeh.plotting import figure, show, output_notebook
from bokeh.tile_providers import *
from bokeh.layouts import row

TEST_tilesource = WMTSTileSource(url='https://tile.opentopomap.org/{z}/{x}/{y}.png',

tile_provider = get_provider(TEST_tilesource)

p = figure(x_range=(-14000000, -6000000),
           y_range=(6000000, 7000000),


SwitchBasemap = Button(label="Switch Basemap", align='center')
SwitchBasemap.js_on_click(CustomJS(args=dict(wmts=p.renderers[0].tile_source), code="""
        wmts.url = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";


I don’t think anyone has ever asked about swapping out the tile provider before. I’d like to think there is a simple solution, but browsers also have security concerns/polices around loading external resources into HTML canvases, so it will require some investigation. A GitHub Issue with details woudl be appropriate.

In the mean time, my only suggestion is to try making entire separate plots in layout, and having the callback toggle the visibility of each, instead of setting the tile provider url.

1 Like

Just a nice feature for the user to swap basemaps without having to change anything in python and re-run. That work around works great for now though, good idea, thanks!