maptiler / tileserver-gl

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
https://tileserver.readthedocs.io/en/latest/
Other
2.24k stars 639 forks source link

4.5.2-4.6.1 breaks URL-based "glyphs" and "sprites" (concats URLs with root paths?) #1025

Closed alex-kowalczyk closed 1 year ago

alex-kowalczyk commented 1 year ago

With the following config.json and mystyle.json (relevant fragments) 4.5.1 displays nice map, while after updated to 4.6.0 it emits errors for glyphs and fonts and does not display vector map at all. Moreover, errors indicate that sprites URLs are concated with local "/data" root prefix. Revert to 4.5.1 fixed the issue.

Errors on startup:

mlgl: {
    class: 'Style',
    severity: 'ERROR',
    text: "Failed to load sprite: ENOENT: no such file or directory, open '/data/https://static.mydomain.eu/sprites/osm-liberty-topo@2x.json'"
}

Errors when serving:

ERROR: Trying to use Arial Unicode MS Regular as a fallback
ERROR: Font not found: Roboto Condensed Italic
ERROR: Trying to use Arial Unicode MS Regular as a fallback
ERROR: Font not found: Arial Unicode MS Regular
GET /fonts/Roboto%20Condensed%20Italic/0-255.pbf 400 41 - 4.819 ms
ERROR: Font not found: Arial Unicode MS Regular

config.json:

{
  "options": {
    "paths": {
      "root": "/data",
      "styles": "styles",
      "fonts": "",
      "sprites": "",
      "mbtiles": ""
    },
    "domains": [
      "my.domain"
    ],
    "serveAllFonts": false,
    "serveStaticMaps": false
  },
  "styles": {
    "mystyle": {
      "style": "mystyle.json",
      "tilejson": {
        "type": "overlay",
        "bounds": [12.08477,48.54292,18.86321,51.06426]
      }
    }
  },
  "sources": {
     "europe": {
        "url": "mbtiles://{europe}",
        "type": "vector"
     }
  },
  "data": {
    "europe": {
      "mbtiles": "tiles.mbtiles"
    }
  }
}

mystyle.json:

{
  "version": 8,
  "name": "MyStyle",
  "center": [18.4803, 54.46639],
  "zoom": 13,
  "sources": {
    "mystyle": {
      "type": "vector",
      "url": "mbtiles://tiles.mbtiles"
    },
  },
  "id": "mystyle"
  "sprite": "https://static.mydomain.eu/sprites/osm-liberty-topo",
  "glyphs": "https://fonts.mydomain.eu/{fontstack}/{range}.pbf",
  "layers": [...]
}
acalcutt commented 1 year ago

have you tried if v4.6.1 fixes it?

acalcutt commented 1 year ago

I just tested your style and it looks like it is the same in 4.6.1 . I didn't change anything specific to glyphs and sprites, so I will have to try and track it down.

alex-kowalczyk commented 1 year ago

@acalcutt thanks for your response. Looking at the changelog, this 4.5.2 change might be related: "chore: cleanup useless decodeURIComponent() calls" https://github.com/maptiler/tileserver-gl/pull/1002/files

acalcutt commented 1 year ago

I does seem like https://github.com/liberty-rider/tileserver-gl/blob/869ab0489cb7b5396b46c051deda6afd15f38808/src/serve_rendered.js#L26 partially causes the issue.

With that included the style json returns image

But with the old tester string it returns image

I do have to wonder though, did raster maps work at all for you before with this style? There is also this other code on the rendering side that always seems to append path https://github.com/maptiler/tileserver-gl/blob/master/src/serve_rendered.js#L1237-L1260 which seems like it would have broken rendering for this style, and that has been like that for a while

EDIT: nevermind on the second location, that would only apply if the string started with sprites:// or glyphs:// I think

alex-kowalczyk commented 1 year ago

I used vector tiles only. Do you mean server-side rendered rasters of my vectors? Just tried to access "raster" variant on 4.5.1 through tileserver UI and yes, they work fine (fonts and glyphs correctly rendered on them)

acalcutt commented 1 year ago

Ya, the rendering part I am talking about makes the images on the index page next to your style, and also the images for the raster page you are talking about, to the right of your style on the index page.

When I revert the HttpTester string the vector tiles work again and and the style looks correct.

However when it tries to render it looks like it uses https://github.com/maptiler/tileserver-gl/blob/master/src/serve_rendered.js#L1237-L1260 and maplibre-native gets an error it adds in the path.

mlgl: {
  class: 'Style',
  severity: 'ERROR',
  text: "Failed to load sprite: ENOENT: no such file or directory, open 'C:\\Users\\Andrew\\Documents\\GitHub\\tileserver-gl-wdb\\config\\https:\\tiles.wifidb.net\\styles\\WDB_DARK_MATTER\\sprite.png'"
}
acalcutt commented 1 year ago

I missed that the http testing code was actually in two places

https://github.com/liberty-rider/tileserver-gl/blob/869ab0489cb7b5396b46c051deda6afd15f38808/src/serve_style.js#L12 https://github.com/liberty-rider/tileserver-gl/blob/869ab0489cb7b5396b46c051deda6afd15f38808/src/serve_rendered.js#L26

Any chance you can put in a PR to revert these back to const httpTester = /^(http(s)?:)?\/\//;

it will be easier for me to approve the change if someone else puts it in.

alex-kowalczyk commented 1 year ago

Thanks! Will do the PR.

acalcutt commented 1 year ago

@Caerbannog , just an fyi. this broke in v4.5.2 with https://github.com/maptiler/tileserver-gl/pull/1002

alex-kowalczyk commented 1 year ago

@acalcutt here goes the PR.

acalcutt commented 1 year ago

Thanks for the PR. I'll merge it as soon at the tests finish and make a new release.

Just a side FYI, I don't think this sections in your config.json does anything.

  "sources": {
     "europe": {
        "url": "mbtiles://{europe}",
        "type": "vector"
     }
  },

that format would be used in your style, the mystyle.json fie, to reference (data -> europe) in config.json

Caerbannog commented 1 year ago

Ouch, sorry for creating this bug. I ignored the ^ in the regex when I reasoned about it.

acalcutt commented 1 year ago

v4.6.2 has been released, so let me know if that fixes your issue.

@Caerbannog I was just glad it wasn't my PR this time...haha

alex-kowalczyk commented 1 year ago

Just grabbed 4.6.2 docker image and tested with my jsons. Perfetto! Thank you so much @acalcutt !