esri-leaflet-vector icon indicating copy to clipboard operation
esri-leaflet-vector copied to clipboard

Updating token for vector layer?

Open martingraham opened this issue 9 months ago • 2 comments

Describe the problem

I'm making an app where there's a possibility of the token timing out during use (I'd like to change that but out of my control). Having looked through the code the token looks baked into the urls sent to the maplibre layers?

Describe the proposed solution

It would be great if there was a function (if possible, if it's not fair enough) to update the token used by a particular layer. The calling app would handle when to do this.

Alternatives considered

No response

Additional Information

No response

martingraham avatar May 12 '25 08:05 martingraham

This is pretty timely since we will probably be introducing something like this soon for some upcoming features.

For now you can access the private _glMap object https://github.com/Esri/esri-leaflet-vector/blob/master/src/MaplibreGLLayer.js#L169C10-L169C16 which returns the Map object and then use getSource() and VectorTileSource.setUrl() to update the token.

The whole chain would probably look something like this:

const layer = L.esri.Vector.vectorTileLayer("ITEM_ID", {
  token: "...",
}).addTo(map);

layer._glMap.getSource("esri").setTileUrl("tile url with new token")

patrickarlt avatar May 12 '25 21:05 patrickarlt

Thanks Patrick!

martingraham avatar May 13 '25 08:05 martingraham