Skip to content

Commit

Permalink
Enable local ideograph generation for glyphs in the 'CJK Unified Ideo…
Browse files Browse the repository at this point in the history
…graphs' and 'Hangul Syllables' ranges, using the system default sans-serif font.
  • Loading branch information
Asheem Mamoowala committed Mar 14, 2019
1 parent 6e50e15 commit 9f833c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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 @@ -130,6 +130,7 @@ const defaultOptions = {
renderWorldCopies: true,
refreshExpiredTiles: true,
maxTileCacheSize: null,
localIdeographFontFamily: 'sans-serif',
transformRequest: null,
fadeDuration: 300,
crossSourceCollisions: true
Expand Down Expand Up @@ -204,9 +205,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 @@ -951,13 +953,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

0 comments on commit 9f833c6

Please sign in to comment.