Skip to main content

Style zoom level

The style zoom level is set in map styles using the styleZoom parameter.

The styleZoom and zoom parameters define the map zoom level in different projections. Unlike the zoom parameter, the styleZoom value accounts for Mercator projection distortions, which ensures that map objects are displayed at the same scale across different latitudes.

Description

Example style fragment:

{
type: 'polygon',
id: 'background',
filter: ['match', ['get', 'sublayer'], ['s_region'], true, false],
style: {
color: [
'interpolate', ['linear'], ['zoom'],
9, 'hsl(50, 61%, 90%)',
12, 'hsl(51, 37%, 90%)',
14, 'hsl(49, 48%, 91%)',
16, 'hsl(51, 51%, 92%)',
],
},
},

The object defines the background color for data where the sublayer field equals s_region. The expression in the color property sets the dependency of the background color on the zoom level via styleZoom.

Usage recommendations

  • Use the zoom parameter to work with the map zoom level. The value is the same at any latitude: both near the polar circle and at the equator.
  • Use styleZoom when you need to work with zoom level boundaries in styles. For example, when developing a map style in the Style editor to ensure that zoom-restricted objects are displayed correctly.

Parameter priority

By default, the zoom parameter is used. You can specify styleZoom in the map settings to set the zoom level that corresponds to the values in the style.

If both zoom and styleZoom parameters are set, styleZoom takes higher priority.

For dynamic control, use the following methods:

Examples

The example below shows the difference between zoom and styleZoom at the same value of 16.

The map with the zoom parameter:

The map with the styleZoom parameter: