mapbox / mapbox/mapbox-gl-js

maxZoom: 0 is ignored

Open
#13,366 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 3.9.0

**browser**: Chrome 131.0.6778.205

### Steps to Trigger Behavior

1. Open example https://docs.mapbox.com/mapbox-gl-js/guides
2. In the suggested JS editor, set `maxZoom` to `0`:
```javascript
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
projection: 'globe', // Display the map as a globe, since satellite-v9 defaults to Mercator
zoom: 1,
maxZoom: 0,
center: [30, 15]
});
```

### Link to Demonstration

https://jsfiddle.net/7em46qau/2/

### Expected Behavior

Maximum zoom level 0 should be accepted as any other possible levels: user should not zoom in beyond this level.

### Actual Behavior

`maxZoom` is ignored like there is no value at all.

### Possible solution

Most likely, the existence of a property is checked with simple JS `if (property)` code. It will produce false for `0`. Additional check on `0` value should work: `if (property || property === 0)`.

### Temporal workaround

Set `maxZoom` to `0.0001`. It should pass existence check and then it will be rounded to `0`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the configuration in the linked JSFiddle using mapbox-gl-js 3.9.0, then trace how the Map options handle maxZoom. Done means maxZoom: 0 is honored and the map cannot zoom beyond level 0, with the existing workaround no longer needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.