Skip to content

Commit 2a11d83

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Add documentation for the scale factor API (internal-9299)
GitOrigin-RevId: 713d22636e4955bac8445d4ab89b9c08fc2306e2
1 parent 883778a commit 2a11d83

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/style-spec/reference/v8.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,7 +3221,6 @@
32213221
"minimum": [0.1, 0.1],
32223222
"maximum": [10, 10],
32233223
"experimental": true,
3224-
"private": true,
32253224
"expression": {
32263225
"interpolated": false
32273226
},
@@ -3738,7 +3737,6 @@
37383737
"minimum": [0.1, 0.1],
37393738
"maximum": [10, 10],
37403739
"experimental": true,
3741-
"private": true,
37423740
"expression": {
37433741
"interpolated": false
37443742
},

src/ui/map.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ const defaultOptions = {
399399
* @param {Object} [options.locale=null] A patch to apply to the default localization table for UI strings such as control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language;
400400
* see [`src/ui/default_locale.js`](https://github.com/mapbox/mapbox-gl-js/blob/main/src/ui/default_locale.js) for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
401401
* @param {boolean} [options.testMode=false] Silences errors and warnings generated due to an invalid accessToken, useful when using the library to write unit tests.
402+
* @param {number} [options.scaleFactor=1] The scale factor for text and icon sizes in symbol layers.
403+
* A value greater than `1` increases label sizes, useful for improving accessibility or adjusting
404+
* for high-density displays. The scale factor is clamped per-layer by `text-size-scale-range`
405+
* and `icon-size-scale-range` style properties.
406+
* This option is experimental and may change in future releases.
402407
* @param {'raster' | 'icon_set' | 'auto'} [options.spriteFormat='auto'] The format of the image sprite to use. If set to `'auto'`, vector iconset will be used for all mapbox-hosted sprites and raster sprite for all custom URLs.
403408
* @param {ProjectionSpecification} [options.projection='mercator'] The [projection](https://docs.mapbox.com/mapbox-gl-js/style-spec/projection/) the map should be rendered in.
404409
* Supported projections are:
@@ -1209,28 +1214,57 @@ export class Map extends Camera {
12091214
getMaxPitch(): number { return this.transform.maxPitch; }
12101215

12111216
/**
1212-
* Returns the map's current scale factor.
1217+
* Returns the map's current scale factor for symbol sizing.
12131218
*
1214-
* @returns {number} Returns the map's scale factor.
1215-
* @private
1219+
* The scale factor multiplies text and icon sizes in symbol layers, useful for
1220+
* accessibility or adapting to different display densities.
1221+
* This method is experimental and may change in future releases.
1222+
*
1223+
* @memberof Map#
1224+
* @returns {number} The map's current scale factor (default `1`).
1225+
* @experimental
12161226
*
12171227
* @example
12181228
* const scaleFactor = map.getScaleFactor();
1229+
*
1230+
* @see {@link Map#setScaleFactor}
1231+
* @see [text-size-scale-range](https://docs.mapbox.com/style-spec/reference/layers/#layout-symbol-text-size-scale-range)
12191232
*/
12201233
getScaleFactor(): number {
12211234
return this._scaleFactor;
12221235
}
12231236

12241237
/**
1225-
* Sets the map's scale factor.
1238+
* Sets the map's scale factor for symbol sizing.
1239+
*
1240+
* The scale factor multiplies text and icon sizes in symbol layers. This is useful for
1241+
* improving accessibility (larger labels for users with vision impairments) or adjusting
1242+
* label sizes for different display densities.
1243+
*
1244+
* The effective scale factor for each symbol layer is clamped to that layer's
1245+
* `text-size-scale-range` and `icon-size-scale-range` properties,
1246+
* allowing fine-grained control over which layers scale and by how much.
1247+
*
1248+
* Calling this method triggers a re-layout of symbol layers whose effective scale factor changed.
1249+
* This method is experimental and may change in future releases.
12261250
*
1227-
* @param {number} scaleFactor The scale factor to set.
1251+
* @memberof Map#
1252+
* @param {number} scaleFactor The scale factor to apply (default `1`). Values greater
1253+
* than `1` increase sizes; values less than `1` decrease sizes.
12281254
* @returns {Map} Returns itself to allow for method chaining.
1229-
* @private
1255+
* @experimental
12301256
*
12311257
* @example
1232-
*
1258+
* // Increase map labels for accessibility (clamped by text-size-scale-range)
12331259
* map.setScaleFactor(2);
1260+
*
1261+
* @example
1262+
* // Reset to default size
1263+
* map.setScaleFactor(1);
1264+
*
1265+
* @see {@link Map#getScaleFactor}
1266+
* @see [text-size-scale-range](https://docs.mapbox.com/style-spec/reference/layers/#layout-symbol-text-size-scale-range)
1267+
* @see [icon-size-scale-range](https://docs.mapbox.com/style-spec/reference/layers/#layout-symbol-icon-size-scale-range)
12341268
*/
12351269
setScaleFactor(scaleFactor: number): this {
12361270
this._scaleFactor = scaleFactor;

0 commit comments

Comments
 (0)