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

Requests to third-party server for fonts #1030

Open
simonseyock opened this issue Nov 20, 2023 · 8 comments
Open

Requests to third-party server for fonts #1030

simonseyock opened this issue Nov 20, 2023 · 8 comments

Comments

@simonseyock
Copy link
Member

simonseyock commented Nov 20, 2023

This lines will cause requests to a third-party server:

ol-mapbox-style/src/text.js

Lines 158 to 161 in f85e5ff

export function getFonts(
fonts,
templateUrl = 'https://cdn.jsdelivr.net/npm/@fontsource/{font-family}/{fontweight}{-fontstyle}.css'
) {

font = mb2css(
getFonts
? getFonts(
fontArray,
glStyle.metadata ? glStyle.metadata['ol:webfonts'] : undefined
)
: fontArray,
textSize,
textLineHeight
);

style = applyStyleFunction(
layer,
glStyle,
sourceOrLayers,
resolutions,
spriteData,
spriteImageUrl,
getFonts,
options.getImage
);

This is not really documented, in the stylefunction docs you find this:

Function that receives a font stack and the url template from the GL style's metadata['ol:webfonts'] property (if set) as arguments, and returns a (modified) font stack that is available. Font names are the names used in the Mapbox Style object. If not provided, the font stack will be used as-is. This function can also be used for loading web fonts.

In the fonts part of the docs you find this:

If no metadata['ol:webfonts'] property is available on the Style object, Fontsource Fonts will be used. It is also possible for the application to load other fonts. If a font is already available in the browser, ol-mapbox-style will not load it.

This does not make it clear that by default a third-party server will be requested.

Also in my personal opinion this should be an opt-in feature instead of the default behavior.

@simonseyock simonseyock changed the title Requests to third-party server Requests to third-party server for fonts Nov 20, 2023
@ahocevar
Copy link
Member

@simonseyock If that's made opt-in, 99% of all maps will be displayed with incorrect fonts. So I don't think this would be practical. Especially given the fact that most users will be using maps that also come from a 3rd party server.

If you have a suggestion for a doc improvement, feel free to create a pull request.

@simonseyock
Copy link
Member Author

Ok, you are probably right. I see if I can improve the docs here.

@ahocevar
Copy link
Member

ahocevar commented Nov 30, 2023

Note: Ideally, map publishers like MapTiler or basemap.de should include an ol:webfonts entry in their style jsons, and provide web fonts next to their map tiles. The ol:webfonts metadata option was added after FOSS4G 2022, to give map publishers a direct way to avoid having to use 3rd party font servers.

@simonseyock, I think you're closer to basemap.de than I am, so maybe you can remind them to update their style jsons. And maybe @klokan can help to get the same done at MapTiler. For reference, here is the documentation: https://github.com/openlayers/ol-mapbox-style#font-handling.

@jdnarvaez
Copy link

how is this supposed to work when used in conjunction directly with a mapbox url? I cannot seem to find where I would be able to intercept the style object or style object request to inject the webfonts attribute

@ahocevar
Copy link
Member

You cannot, but I think ot would make sense to ads an option for that.

@simonseyock
Copy link
Member Author

@simonseyock, I think you're closer to basemap.de than I am, so maybe you can remind them to update their style jsons. And maybe @klokan can help to get the same done at MapTiler. For reference, here is the documentation: https://github.com/openlayers/ol-mapbox-style#font-handling.

I try to establish a contact here 👍

@marcjansen
Copy link
Member

I mention some people close to the basemap.de Team: @stenderg @sratjens @TheCartographerDev

@ahocevar
Copy link
Member

See #1058

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

4 participants