Passing token to Worldmap node

Below are the contents of a function node in a FlowFuse dashboard. A token has been provided to limit access to requests coming from the flowfuse instance editor URL. The URL in the function is referring to a WMTS.
It isn't working but I'm not sure if it is because the node-red worldmap cannot pass a token, this function isn't defined properly, or, there is an issue with the token. Looking at the Leaflet documentation it suggests replacing {y} with {-y} rather than setting tms:true.

function setArcGisLayer(msg) {
    msg.payload = {
        command: {
            map: {
                name: "My Layer",
                url: "https://tiles.arcgis.com/tiles/Z4shJ8PtFfHyRvWx/arcgis/rest/services/wah_image/MapServer/tile/{z}/{x}/{-y}.png?token=REALLY_LONG_TOKEN",
                opt: {
                    attribution: "© ArcGIS"
                }
            },
            lat: -3.720188,
            lon: 115.319731,
            zoom: 16
        }
    };
    return msg;
}

return setArcGisLayer(msg);

Arcgis is WMS not TMS so you should be OK with {y}.
What errors do you get in the javascript console (maybe the network tab to see if it fails to get the tile etc)

The error I am seeing is 404 Not Found

Sounds like the resource (tile) doesn't exist then. Or maybe Arcgis is failing to reply correctly (eg see https://community.safe.com/data-7/i-get-a-404-http-error-not-found-when-trying-to-read-data-from-my-arcgis-feature-service-10196)

At least the token seems to work as you are not being rejected.
Do you have another client that can get a map tile and compare the url ?
(EG maybe fix values for the x/y/z )

Normally I would check with QGIS but this token restricts the requests to be made from the flowfuse URL so I am limited in what I can do. I did query Leaflet in with an http flow with the same results. I also tested with this function which I have used on another dashboard for getting the layer names from the server. This doesn't return any layer names but doesn't throw any errors either which tells me the TOKEN is probably fine.

return async function(msg) {
    const { DOMParser } = xmldom;
    
    
    const url = `${msg.url || 'https://tiles.arcgis.com/tiles/Z4shJ8PtFfHyRvWx/arcgis/rest/services/wah_image/MapServer?token=VERY_LONG_TOKEN'}?service=WMS&version=1.3.0&request=GetCapabilities`;
    
    try {
        const response = await fetch(url);
        const text = await response.text();
        const parser = new DOMParser();
        const xmlDoc = parser.parseFromString(text, "text/xml");
        
        const layers = xmlDoc.getElementsByTagName('Layer');
        const layerNames = [];
        
        // Convert HTMLCollection to Array and iterate
        Array.from(layers).forEach(layer => {
            const nameElements = layer.getElementsByTagName('Name');
            if (nameElements.length > 0 && nameElements[0].textContent) {
                layerNames.push(nameElements[0].textContent);
            }
        });
        
        msg.payload = layerNames;
        return msg;
    } catch (error) {
        msg.error = 'Error fetching WMS layers: ' + error;
        msg.payload = [];
        return msg;
    }
}(msg);

What x y z do you end up using ?
Can you setup a simple http request node to do the same request just for that tile... If that also gives 404 I still suspect you are out of range of your map tiles.

Yes, I have done that as well. Same 404 error. This works fine with other WMS, just wasn't sure if I was sending the token correctly. That part seems to work. If I put the token in an environment variable how would I configure that in the URL string?

I think I will just get my own ArcGIS account and create some maps and layers for testing.

1 Like

I just found out the map is defined as UTM using this crs definiton EPSG:32750. Can this be configured in the worldmap node?

Hi - I don't think so - I think Leaflet only has a few built in - see Leaflet docs - Documentation - Leaflet - a JavaScript library for interactive maps - and we don't expose those anyway. I think you may be better off trying to get Arcgis to serve them up on a different projection if you can.

Okay, I was thinking the same thing. Thanks.

I don't know Arcgis well enough but this is probably the area - Geometry projections | Documentation | Esri Developer

I just received this information that defines the projection. The storageFormat may be a show stopper. Still looking into it.
tiles.txt (2.8 KB)