mirror of
https://github.com/maputnik/editor.git
synced 2026-12-05 16:24:20 +00:00
Set min and max zoom for PMTiles sources (#2402)
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 | |---|---| | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-1028/before-pmtiles-source.png" width="400"> | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-1028/after-pmtiles-source.png" width="400"> | **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.
This commit is contained in:
1 parent
94c701ee16
commit
26a909ced7
3 files changed
+35
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -287,6 +287,8 @@ class GeoJSONSourceFieldJsonEditor extends React.Component<GeoJSONSourceFieldJso
|
||||
type PMTilesSourceEditorProps = {
|
||||
source: {
|
||||
url: string
|
||||
minzoom?: number
|
||||
maxzoom?: number
|
||||
}
|
||||
onChange(...args: unknown[]): unknown
|
||||
children?: React.ReactNode
|
||||
@@ -306,6 +308,27 @@ class PMTilesSourceEditor extends React.Component<PMTilesSourceEditorProps> {
|
||||
url: url.startsWith("pmtiles://") ? url : `pmtiles://${url}`
|
||||
})}
|
||||
/>
|
||||
{/* Left empty when unset, so the zoom range from the PMTiles header applies */}
|
||||
<FieldNumber
|
||||
label={t("Min Zoom")}
|
||||
fieldSpec={latest.source_vector.minzoom}
|
||||
value={this.props.source.minzoom}
|
||||
data-wd-key="modal:sources.add.minzoom"
|
||||
onChange={minzoom => this.props.onChange({
|
||||
...this.props.source,
|
||||
minzoom
|
||||
})}
|
||||
/>
|
||||
<FieldNumber
|
||||
label={t("Max Zoom")}
|
||||
fieldSpec={latest.source_vector.maxzoom}
|
||||
value={this.props.source.maxzoom}
|
||||
data-wd-key="modal:sources.add.maxzoom"
|
||||
onChange={maxzoom => this.props.onChange({
|
||||
...this.props.source,
|
||||
maxzoom
|
||||
})}
|
||||
/>
|
||||
{this.props.children}
|
||||
</div>;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user