Martin's Accept header vs other maplibre client #2869
Replies: 2 comments 13 replies
-
|
Here is the issue where I give the rationale for this: maplibre/maplibre-native#4236 (comment) I have open PRs against gl-js and native that would unblock tile servers like martin being actually able to serve MLT without that pain. The content negotiation for adding MLT to tiles.json is also in the plan, but first we need the basics to work if the style has Essentially:
Works with middleboxes, legacy clients, ... |
Beta Was this translation helpful? Give feedback.
-
|
I appreciate the elegance of the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As of #2775, Martin supports converting MVT tiles to MLT (and vice versa) on the fly, which is cool in theory. But in practice, it's been challenging to actually use it with other clients. I'm going to start with just a statement of the problem I'm having for now, and maybe follow up with a proposed solution later.
As background, I'll be referring to 3 levels of requests:
/style/my-style)/my-source)/my-source/{x}/{y}/{z})MaplibreGL JS
You need to patch the js client to send the appropriate
Acceptsheader while requesting tiles. Something like this:const mapOptions: MapOptions = { container: mapContainerId, - style: '/tileserver/styles/basic/style.json', // style URL + style: '/tileserver/style/basic-v2', + transformRequest: (url, resourceType) => { + if (resourceType === 'Tile' && url.includes('areamap')) { + return { + url, + headers: { Accept: 'application/vnd.maplibre-tile' }, + }; + } + return { url }; + }, };That's sufficient to request MLT, but the JS client will still assume the response is MVT unless you also update the style.json to declare the encoding of the source as
mlt.Something like this:
That works, but it's awkward because we've "hardcoded" something at the
stylelevel, when really getting MLT from martin requires headers be sent to the individual tile requests, and does not depend on the source encoding.Maplibre Native iOS (maybe other native platforms too - but I'm only using iOS)
You similarly need to patch the client to set the accepts headers. Something like this...
func makeUIView(context: Context) -> Self.UIViewType { ... + assert(MLNNetworkConfiguration.sharedManager.delegate == nil) + MLNNetworkConfiguration.sharedManager.delegate = context.coordinator ... } +extension MapViewWrapper.Coordinator: MLNNetworkConfigurationDelegate { + func willSend(_ request: NSMutableURLRequest) -> NSMutableURLRequest { + if request.url?.path.contains("/tileserver/areamap-mlt") == true { + request.setValue("application/vnd.maplibre-tile", forHTTPHeaderField: "Accept") + } + return request + } +}But this isn't working. I think it's because maplibre native is expecting the
encoding: mltto be set for the source metadata (the tile.json) not the style. Currently I don't think it's possible to edit the tile.json in the way for martin. Plus it would, like the note above, be awkward to "hard code" the encoding for a tile.json when ultimately it's the request headers which dictate what kind of tile response you get.Beta Was this translation helpful? Give feedback.
All reactions