maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
https://martin.maplibre.org
Apache License 2.0
2.33k stars 216 forks source link

Improved handling of glyph urls as commonly used in styles #1443

Open bzeiss opened 4 months ago

bzeiss commented 4 months ago

When trying to make the font service working, I stumbled across a small problem that is easy to fix, but not so easy to find out why it didn't work (at least for me).

I'm using a tilemaker mbtiles file together with publicly available openmaptiles style, for example, https://github.com/openmaptiles/osm-bright-gl-style/blob/master/style.json. Practically all openmapstyle styles listed on https://openmaptiles.org/styles/, have one thing in common in how they specify the glph url. They do it as something like "glyphs": "https://api.maptiler.com/fonts/{fontstack}/{range}.pbf?key={key}",

When I first tried to make Martin work as glyph server, I adapted the url to "glyphs": "font/{fontstack}/{range}.pbf"

This didn't work. Martin successfully scanned the font directory that I have provided:

Configured font Open Sans Regular with 883 glyphs (0020-FFFD) from fonts/open-sans/OpenSans-Regular.ttf

But when I tried to access the service with http://localhost:3000/font/Open%20Sans%20Regular/0-255.pbf as I have watched maplibre request the glyphs, I would get a response "can not parse "255.pbf" to a u32".

After enabling the debug logs, I got

2024-07-28T10:59:28Z DEBUG actix_web::types::path] Failed during Path extractor deserialization. Request path: "/font/Open%20Sans%20Regular/0-255.pbf" [2024-07-28T10:59:28Z DEBUG actix_web::middleware::logger] Error in response: Error("can not parse \"255.pbf\" to a u32")

After some tinkering, I found out that http://localhost:3000/font/Open%20Sans%20Regular/0-255 works, but http://localhost:3000/font/Open%20Sans%20Regular/0-255 .pbf doesn't. After changing the glyph urls in the styles to "glyphs": "font/{fontstack}/{range}", everything started to work perfectly.

Ideally there would be either a pointer in the documentation how the glyph urls need to look like or the server would automatically detect such pbf urls and handle them correctly.

Thanks for this great server. I really enjoy tinkering with it!

CommanderStorm commented 2 weeks ago

@bzeiss is there a reason you closed the issue?

bzeiss commented 2 weeks ago

I have lost interest and it's a non issue once you know how to work around it. So it fell victim to a github issue cleanup I did. Feel free to make a copy of the text if you think it is.