Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMTiles URLs in MapLibre are not valid URLs #509

Open
bdon opened this issue Jan 6, 2025 · 6 comments
Open

PMTiles URLs in MapLibre are not valid URLs #509

bdon opened this issue Jan 6, 2025 · 6 comments

Comments

@bdon
Copy link
Member

bdon commented Jan 6, 2025

Currently the PMTiles URLs in MapLibre look like this:

pmtiles://https://example.com/tiles.pmtiles

These cannot be parsed by URL parsers correctly.

We could instead change it to this:

pmtiles+https://example.com/tiles.pmtiles
pmtiles+http://example.com/tiles.pmtiles

This would require changing the addProtocol call, using two for HTTP and HTTPS.

maplibregl.addProtocol("pmtiles+http",protocol.http);
maplibregl.addProtocol("pmtiles+https",protocol.https);
@bdon
Copy link
Member Author

bdon commented Jan 17, 2025

It also needs to work if no protocol is passed, which is interpreted as "the same protocol as the page, with path relative to the page"

@KiwiKilian
Copy link

KiwiKilian commented Jan 17, 2025

I don't know the URL RFC in details or much about URL parsers, but by just looking at the output of a current chromium browser, I'm in high support of moving to a spec compliant scheme!

Image

@bdon
Copy link
Member Author

bdon commented Jan 17, 2025

I'm in support of this, but we need to figure out a solution for protocol-relative URLs as I mentioned above.

Right now if you have a static index.html with a MapLibre embed, you can refer to a relative tileset like this:

pmtiles://example.pmtiles

Currently this behaves correctly because the underlying fetch will ask for example.pmtiles which is interpreted as a resource using the same protocol and with a path relative to the index.html you're on right now.

Let's consider someone that uses HTTPS in local development, and pushes both index.html and example.pmtiles to GitHub pages. Under our proposed pmtiles+https:// solution and pmtiles+http:// solution, we would need to:

  1. have the developer add both protocols:
maplibregl.addProtocol("pmtiles+http",protocol.http);
maplibregl.addProtocol("pmtiles+https",protocol.https);

Specify the pmtiles location in the style dynamically:

url: `pmtiles+${location.protocol}//example.pmtiles`

Internally we then need to make assumptions about the URL passed to interpret that as a relative URL and not a hostname with TLD .pmtiles.

Trying to think of workarounds...

@louwers
Copy link

louwers commented Jan 17, 2025

MapLibre Native supports pmtiles://file://..., pmtiles://asset://, pmtiles://http://, pmtiles://https:// right now...

@KiwiKilian
Copy link

KiwiKilian commented Jan 17, 2025

@louwers Is this duplicate protocol pattern also used with mbtiles:// for MLN?

@louwers
Copy link

louwers commented Jan 17, 2025

No mbtiles:// will load a local mbtiles file, an MBTiles file cannot be efficiently queried over a network like PMTiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants