Add a line metrics checkbox to GeoJSON sources for line-gradient (#2403)

Fixes #292.

`line-gradient` only renders when the line's GeoJSON source has
`"lineMetrics": true`, and Maputnik had no way to set that. Nothing in
`src` set or showed `lineMetrics`, so a gradient could only be made to
work by editing the source in the code editor. GeoJSON sources (both the
URL and the inline JSON kind) now have a "Line metrics" checkbox in the
Data Sources modal.

The `line-gradient` property itself already works: it shows up under the
line layer's paint properties and is edited in the expression editor
with `["line-progress"]`. I checked that with a style using an
`interpolate` over `line-progress`. So the checkbox was the missing
piece.

**Before / after** (Data Sources → Add New Source → GeoJSON (URL)):

| Before | After |
|---|---|
| <img
src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-292/before-geojson-source.png"
width="400"> | <img
src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-292/after-geojson-source.png"
width="400"> |

**Performance:** no impact on Maputnik itself. `lineMetrics` only
changes how MapLibre tiles that GeoJSON source when someone turns it on,
and that cost is the reason it's off by default in the spec.

## Launch Checklist

 - [x] Briefly describe the changes in this PR.
 - [x] Link to related issues: fixes #292.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
- [x] Write tests for all new functionality: `enable line metrics for a
GeoJSON source` in `modals.spec.ts` (with an `enableLineMetrics` action
in the modal driver). 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:
SHAIK KHADEER BASHA authored and GitHub committed 2026-12-04 20:08:50 +02:00
1 parent b7b24e5de3
commit 07bc2bcc3b
15 files changed
+42

No files matched your search

+5
View File
@@ -47,6 +47,11 @@ npm run test-unit
- Every input, select and button needs an accessible name. `InputString`, `InputNumber`, `InputSelect` and `InputButton` accept an `aria-label`.
- When a control repeats, as in the rows of an array or collection field, give each copy its own label that names the row and what it edits (for example `… row 2 X offset`), and pass it through `t()`. Controls that share one label can't be told apart with a screen reader.
## Translations
- Every new user-visible string goes through `t()` and needs a translation in each `src/locales/*/translation.json`, kept in alphabetical key order.
- `npm run i18n:extract` adds missing keys with the value `__STRING_NOT_TRANSLATED__`; replace each one with a real translation. `npx i18next-cli status` lists keys that are still missing.
## Pull Requests
- Pull requests should update `CHANGELOG.md` with a short description of the change.
+1
View File
@@ -13,6 +13,7 @@
- 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 a "Line metrics" checkbox to GeoJSON sources, which `line-gradient` needs to render
- _...Add new stuff here..._
### 🐞 Bug fixes
+5
View File
@@ -61,6 +61,11 @@ export class ModalDriver {
.getByRole("checkbox", { name: "Generate feature IDs" }).click();
},
enableLineMetrics: async () => {
await this.helper.get.element(".maputnik-add-source")
.getByRole("checkbox", { name: "Line metrics" }).click();
},
setFeatureIdProperty: async (sourceId: string, value: string) => {
const source = this.helper.get.element(".maputnik-active-source-type-editor")
.filter({ has: this.helper.get.element(".maputnik-active-source-type-editor-header").getByText("#" + sourceId, { exact: true }) });
+12
View File
@@ -232,6 +232,18 @@ describe("modals", () => {
});
});
test("enable line metrics for a GeoJSON source", async () => {
const sourceId = "line-metrics";
await when.setValue("modal:sources.add.source_id", sourceId);
await when.select("modal:sources.add.source_type", "geojson_url");
await when.modal.enableLineMetrics();
await when.click("modal:sources.add.add_source");
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
sources: { [sourceId]: { type: "geojson", lineMetrics: true } },
});
});
test("promote a vector source feature property to its ID", async () => {
const sourceId = "promoted-feature-ids";
await when.modal.addSource(sourceId, "tilejson_vector");
@@ -402,6 +402,15 @@ class ModalSourcesTypeEditorInternal extends React.Component<ModalSourcesTypeEdi
const { source, onChange } = this.props;
return <>
{this.renderEditor()}
{source.type === "geojson" &&
<FieldCheckbox
label={this.props.t("Line metrics")}
value={source.lineMetrics}
onChange={lineMetrics => onChange({
...source,
lineMetrics,
})}
/>}
{(source.type === "geojson" || source.type === "vector") &&
<SourceFeatureIdFields source={source} onChange={onChange} />}
</>;
+1
View File
@@ -109,6 +109,7 @@
"Light color": "İşıq rəngi",
"Light intensity": "İşıq intensivliyi",
"Light position": "İşıq mövqeyi",
"Line metrics": "Xətt metrikləri",
"Links": "Keçidlər",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "URL-dən yüklə. Qeyd edin ki, URL-də <1>CORS aktiv olmalıdır</1>.",
"Load from URL": "URL-dən yüklə",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "Lichtfarbe",
"Light intensity": "Lichtintensität",
"Light position": "Lichtposition",
"Line metrics": "Linienmetriken",
"Links": "Links",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "Von einer URL laden. Beachte, dass die URL <1>CORS aktiviert</1> haben muss.",
"Load from URL": "Von URL laden",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "Couleur de la lumière",
"Light intensity": "Intensité de la lumière",
"Light position": "Position de la lumière",
"Line metrics": "Métriques de ligne",
"Links": "Liens",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "Charger depuis une URL. Notez que l'URL doit avoir les <1>CORS activés</1>.",
"Load from URL": "Charger depuis une URL",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "צבע האור",
"Light intensity": "חוזק האור",
"Light position": "מיקום האור",
"Line metrics": "מדדי קו",
"Links": "קישורים",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "פתיחה מכתובת, שימו לב: הכתובת צריכה לתמוך ב- CORS",
"Load from URL": "פתיחה מתוך כתובת",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "Colore della luce",
"Light intensity": "Intensità della luce",
"Light position": "Posizione della luce",
"Line metrics": "Metriche delle linee",
"Links": "Collegamenti",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "Carica da URL. Nota che l'URL deve avere l'abilitazione <1>CORS attivata</1>.",
"Load from URL": "Carica da URL",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "ライトカラー",
"Light intensity": "ライト強度",
"Light position": "ライト位置",
"Line metrics": "ラインメトリクス",
"Links": "リンク",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "URLから読み込む。注意: URLは <1>CORSを有効にする</1> 必要があります。",
"Load from URL": "URLから読み込む",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "라이트 색상",
"Light intensity": "라이트 강도",
"Light position": "라이트 위치",
"Line metrics": "라인 메트릭",
"Links": "링크",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "URL에서 불러옵니다. URL은 <1>CORS가 활성화</1>되어 있어야 합니다.",
"Load from URL": "URL에서 불러오기",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "Kolor światła",
"Light intensity": "Natężenie światła",
"Light position": "Położenie źródła światła",
"Line metrics": "Metryki linii",
"Links": "Odnośniki",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "Wczytaj styl z adresu URL. Serwer musi <1>zezwalać na dostęp przez CORS</1>.",
"Load from URL": "Wczytaj z adresu URL",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "Işık rengi",
"Light intensity": "Işık yoğunluğu",
"Light position": "Işık konumu",
"Line metrics": "Çizgi metrikleri",
"Links": "Bağlantılar",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "Bir URL'den yükleyin. URL'de <1>CORS etkin</1> olmalıdır.",
"Load from URL": "URL'den yükle",
+1
View File
@@ -109,6 +109,7 @@
"Light color": "光源颜色",
"Light intensity": "光源强度",
"Light position": "光源位置",
"Line metrics": "线条度量",
"Links": "链接",
"Load from a URL. Note that the URL must have <1>CORS enabled</1>.": "从URL加载。注意:URL必须启用 <1>CORS</1>。",
"Load from URL": "从URL加载",