From 26a909ced7ba07ddc1f9db91ad9c78811c558609 Mon Sep 17 00:00:00 2001
From: SHAIK KHADEER BASHA
<120262074+KhadeerBasha1232@users.noreply.github.com>
Date: Fri, 4 Dec 2026 21:52:55 +0530
Subject: [PATCH] Set min and max zoom for PMTiles sources (#2402)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fixes #1028.
The PMTiles source editor only had a URL field, so there was no way to
set `minzoom` or `maxzoom` on a PMTiles source from Maputnik. That
matters when the file's header says one thing and you want another, for
example to overzoom past the last zoom level in the file. It now has Min
Zoom and Max Zoom fields, the same ones the tile URL editor uses.
MapLibre already lets a key in the source override the value it reads
from the PMTiles TileJSON (`load_tilejson.ts` uses `fromOptions.maxzoom
?? fromTileJSON.maxzoom`).
Unlike the tile URL editor, the fields stay empty until you set them,
rather than showing 0 and 22. That way a source you don't touch keeps
the zoom range from the PMTiles header.
**Before / after** (Data Sources → Add New Source → Vector (PMTiles)):
| Before | After |
|---|---|
|
|
|
**Performance:** no impact. This adds two inputs to the source modal;
nothing runs on the map's render path.
## Launch Checklist
- [x] Briefly describe the changes in this PR.
- [x] Link to related issues: fixes #1028.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
- [x] Write tests for all new functionality: `add new pmtiles source
with a max zoom` in `modals.spec.ts`. It fails on `main`.
- [x] Add an entry to `CHANGELOG.md` under the `## main` section.
Tested locally: `npm run lint` clean, `npx tsc --noEmit` clean, `npx
vitest run` (57 passed) and the full `npx playwright test` suite (221
passed). The new test fails when I put back `main`'s
`ModalSourcesTypeEditor.tsx`.
Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the change,
the test and this description. I've reviewed and tested the change and
can answer questions about it.
---
CHANGELOG.md | 1 +
e2e/modals.spec.ts | 11 +++++++++
.../modals/ModalSourcesTypeEditor.tsx | 23 +++++++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bc9e497..0f401bfe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- The sidebar can now be resized, both as a whole and in the split between the layer list and the layer editor
- Allow viewing and changing the map's max zoom in the debug modal
- Edit `text-variable-anchor-offset` as a list of anchors, each with an x and y offset; it previously showed no input
+- Set the min and max zoom of a PMTiles source, for example to overzoom past the last zoom level in the file
- _...Add new stuff here..._
### 🐞 Bug fixes
diff --git a/e2e/modals.spec.ts b/e2e/modals.spec.ts
index 6643923f..bcae3365 100644
--- a/e2e/modals.spec.ts
+++ b/e2e/modals.spec.ts
@@ -178,6 +178,17 @@ describe("modals", () => {
});
});
+ test("add new pmtiles source with a max zoom", async () => {
+ await when.setValue("modal:sources.add.source_id", "pmtileszoom");
+ await when.select("modal:sources.add.source_type", "pmtiles_vector");
+ await when.setValue("modal:sources.add.maxzoom", "15");
+ await when.click("modal:sources.add.add_source");
+ await when.wait(200);
+ await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
+ sources: { pmtileszoom: { type: "vector", maxzoom: 15 } },
+ });
+ });
+
test("add new raster source", async () => {
const sourceId = "rastertest";
await when.setValue("modal:sources.add.source_id", sourceId);
diff --git a/src/components/modals/ModalSourcesTypeEditor.tsx b/src/components/modals/ModalSourcesTypeEditor.tsx
index 7a08b815..c12f5088 100644
--- a/src/components/modals/ModalSourcesTypeEditor.tsx
+++ b/src/components/modals/ModalSourcesTypeEditor.tsx
@@ -287,6 +287,8 @@ class GeoJSONSourceFieldJsonEditor extends React.Component {
url: url.startsWith("pmtiles://") ? url : `pmtiles://${url}`
})}
/>
+ {/* Left empty when unset, so the zoom range from the PMTiles header applies */}
+ this.props.onChange({
+ ...this.props.source,
+ minzoom
+ })}
+ />
+ this.props.onChange({
+ ...this.props.source,
+ maxzoom
+ })}
+ />
{this.props.children}
;
}