YFZ
February 12, 2020, 4:44am
1
Hi,
Can anyone please tell me if it is possible to include an Authorization request header when with R Leaflet WMS? I tried the following Javascript plugin. GitHub - ticinum-aerospace/leaflet-wms-header: Custom headers on Leaflet TileLayer WMS It gives me the error below. I am not good at JS and I am not sure what went wrong.
I aso saw Kent37 posted a solution last year:
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…
has anyone been able to make it work? Thanks.
1 Like
kent37
February 12, 2020, 1:52pm
2
What is your R code? I am using a version of the code I posted with no issues.
YFZ
February 12, 2020, 8:41pm
3
Thanks for your reply. Would you mind if I ask if L.TileLayer.xhr you used is a plugin you develop youself? I could not find it anywhere. Thanks. My codes are below:
wms_headerPlugin <- htmlDependency("leaflet-wms-header","1.0.8",
src = normalizePath("D:/API/www/leaflet-wms-header/"),
script="index.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% addTiles() %>%
setView(145.98705368, -36.56692057, 14)%>%
registerPlugin(wms_headerPlugin) %>%
onRender("
function(el, x,data) {
var xhrLayer = new L.TileLayer.wmsHeader(
'https://xxx.com/api/wms ',
{
layers: 'xxxx',
service: 'wms',
format: 'image/png',
version: '1.3.0',
TIME: '2020-01-01T00:00:00Z/2021-01-01T00:00:00Z',
crs: 3857,
VARIABLECODES: 'xxx',
EXCEPTIONS: 'xxx',
request: 'xxx',
ORGANISATIONID:xxxx
}
, [
{ header: 'Authorization', value: 'Bearer token'},
{ header: 'content-type', value: 'text/plain'},
],null)
.addTo(this);
}")
kent37
February 13, 2020, 1:28am
4
Sorry, I thought my plugin was public but it is not at this time.
Looking at your code, a couple of things I see:
You may need a ?
at the end of your URL, that is what the wms example uses.
You don't need to call addTile
, your wmsHeader
replaces that.
Are you using an actual token value where you have 'Bearer token'
?
HTH
YFZ
February 13, 2020, 2:42am
5
Hi Kent,
I have tried those options (? and remove addTile
)and they did not seem to work. Yes, I have a token. I was able to get the png from the server with a normal GET API call. Did you try the leaflet-wms-header plugin? Any chance I can ask the name of the plugin you used? I might look around and see if I can still get it somewhere. Thanks again for answering my questions.
Y
kent37
February 13, 2020, 11:16am
6
I have not tried leaflet-wms-header. My application uses XYZ tiles, not WMS. Sorry I don't think I can help you any further.
YFZ
February 13, 2020, 9:19pm
7
Hi Kent, Thanks for your clarificaiton.
system
Closed
April 8, 2020, 1:19am
8
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.