I am using Leaflet to access an authenticated tile server. The tile server needs an Authorization header added to each tile request. Apparently this is not possible in plain leaflet because it is using <img> tags to request tiles:
I would like to extend TileLayer to add the Authorization header but I'm stuck on a few points.
I found some JavaScript examples that point in the right direction, see links below. I can probably figure out the JavaScript to make the request, but I'm clueless about how to incorporate a subclassed TileLayer into the R wrapper around leaflet.js. Any example of using a custom TileLayer subclass from R would be very helpful!
My client is a Shiny app, not sure if that matters.
Thanks, Kent
OK, I figured this out, it is possible using htmlwidgets::onRender.
I'm using a variation of this TileLayer subclass. The function to create my custom tile layer is L.TileLayer.xhr. The renderLeaflet code looks roughly like this: