MapLayerFetchHandler Type Alias

MapLayerFetchHandler = (request: MapLayerRequest, fetchRequest: MapLayerFetchRequest) => Promise<Response | undefined>

Wraps every map-layer network request issued through MapLayerImageryProvider — tiles, tooltips, capabilities, service metadata, and source validation. Registered via addMapLayerFetchHandler. Handlers form a pipeline we own, run in registration order: the first registered is the outermost. Requests a format issues outside the provider's request path (e.g. through its own session or token service client) are not routed; that format's documentation states which.

A handler may:

  • decline a request it does not manage (e.g. a format it does not serve) by returning undefined without calling fetchRequest: each handler receives its own copy of the request, so the next handler sees it exactly as the declining one received it, and if every handler declines we issue it ourselves with the default behavior in full;
  • pass a copy of the request with different query parameters or headers to fetchRequest; the request is offered to the remaining handlers, then issued as a credentialed send;
  • call fetchRequest one or more times (e.g. refresh an expired token and retry transparently);
  • return its own Response without calling fetchRequest (short-circuit);
  • throw MapLayerAuthenticationFailedError to report an unrecoverable authentication failure, transitioning the layer to RequireAuth.

A handler that has called fetchRequest must return a response (its own or the one received) or throw; it must not decline. This is not enforced: declining after sending makes the enclosing handler's fetchRequest issue the request again.

Invoked on the hot path of tile loading; handlers should be fast, cache their tokens internally, and coalesce concurrent refreshes (many tile requests observe an expired token at the same time). While a handler is registered, URL-keyed capability/service-metadata caches are bypassed so that customized responses are never shared across differing request contexts. Note that a single logical operation may invoke the pipeline more than once (e.g. the ArcGIS providers issue fallback and token-retry requests); each network request passes through it individually.

Defined in

Last Updated: 03 December, 2026