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

Enable local ideograph generation by default #8008

Merged
merged 3 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions debug/tinysdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
layer.layout['text-field'] = "{name}";
}
}
map.setStyle(style, map.style.glyphSource.localIdeographFontFamily);
map.setStyle(style);
});
}

Expand All @@ -69,7 +69,8 @@
zoom: 8.8,
center: [121.574, 31.1489],
style: 'mapbox://styles/mapbox/streets-v10',
hash: true
hash: true,
localIdeographFontFamily: false
});

localizeLayers(originalMap);
Expand All @@ -79,7 +80,7 @@
zoom: 8.8,
center: [121.574, 31.1489],
style: 'mapbox://styles/mapbox/streets-v10',
localIdeographFontFamily: '"Noto Sans", "Noto Sans CJK SC", sans-serif',
//Uses default localIdeographFontFamily 'sans-serif'
hash: true
});

Expand Down
10 changes: 6 additions & 4 deletions docs/pages/example/local-ideographs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ description: >-
'Hangul Syllables' Unicode ranges. In these ranges, font settings from the
map's style will be ignored in favor of the locally available font. Keywords
in the fontstack defined in the map's style (light/regular/medium/bold) will
be translated into a CSS 'font-weight'. When using this setting, keep in mind
that the fonts you select may not be available on all users' devices. It is
best to specify at least one broadly available fallback font class such as
'sans-serif'.
be translated into a CSS 'font-weight'.

This setting is enabled by default to use the system 'sans-serif' font. When
overriding this setting, keep in mind that the fonts you select may not be available
on all users' devices. It is best to specify at least one broadly available
fallback font class such as 'sans-serif'.
tags:
- internationalization
pathname: /mapbox-gl-js/example/local-ideographs/
Expand Down
16 changes: 11 additions & 5 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const defaultOptions = {
renderWorldCopies: true,
refreshExpiredTiles: true,
maxTileCacheSize: null,
localIdeographFontFamily: 'sans-serif',
transformRequest: null,
fadeDuration: 300,
crossSourceCollisions: true
Expand Down Expand Up @@ -203,9 +204,10 @@ const defaultOptions = {
* @param {Object} [options.fitBoundsOptions] A [`fitBounds`](#map#fitbounds) options object to use _only_ when fitting the initial `bounds` provided above.
* @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
* @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
* @param {string} [options.localIdeographFontFamily=null] If specified, defines a CSS font-family
* for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges.
* @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
* font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges.
* In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
* Set to `false`, to enable font settings from the map's style for these glyph ranges.
* The purpose of this option is to avoid bandwidth-intensive glyph server requests. (see [Use locally generated ideographs](https://www.mapbox.com/mapbox-gl-js/example/local-ideographs))
* @param {RequestTransformFunction} [options.transformRequest=null] A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
* Expected to return an object with a `url` property and optionally `headers` and `credentials` properties.
Expand Down Expand Up @@ -950,13 +952,17 @@ class Map extends Camera {
* @param {Object} [options]
* @param {boolean} [options.diff=true] If false, force a 'full' update, removing the current style
* and building the given one instead of attempting a diff-based update.
* @param {string} [options.localIdeographFontFamily=null] If non-null, defines a css font-family
* for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables'
* ranges. Forces a full update.
* @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
* font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges.
* In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
* Set to `false`, to enable font settings from the map's style for these glyph ranges.
* Forces a full update.
* @returns {Map} `this`
* @see [Change a map's style](https://www.mapbox.com/mapbox-gl-js/example/setstyle/)
*/
setStyle(style: StyleSpecification | string | null, options?: {diff?: boolean} & StyleOptions) {
options = extend({}, { localIdeographFontFamily: defaultOptions.localIdeographFontFamily}, options);

if ((!options || (options.diff !== false && !options.localIdeographFontFamily)) && this.style && style) {
this._diffStyle(style, options);
return this;
Expand Down