From 07bc2bcc3b492797954f600c7ffe0bd1a65b7062 Mon Sep 17 00:00:00 2001 From: SHAIK KHADEER BASHA <120262074+KhadeerBasha1232@users.noreply.github.com> Date: Fri, 4 Dec 2026 23:38:50 +0530 Subject: [PATCH] Add a line metrics checkbox to GeoJSON sources for line-gradient (#2403) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | |---|---| | | | **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. --- AGENTS.md | 5 +++++ CHANGELOG.md | 1 + e2e/modal-driver.ts | 5 +++++ e2e/modals.spec.ts | 12 ++++++++++++ src/components/modals/ModalSourcesTypeEditor.tsx | 9 +++++++++ src/locales/az/translation.json | 1 + src/locales/de/translation.json | 1 + src/locales/fr/translation.json | 1 + src/locales/he/translation.json | 1 + src/locales/it/translation.json | 1 + src/locales/ja/translation.json | 1 + src/locales/ko/translation.json | 1 + src/locales/pl/translation.json | 1 + src/locales/tr/translation.json | 1 + src/locales/zh/translation.json | 1 + 15 files changed, 42 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index ee8ac479..0e635fa7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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. diff --git a/CHANGELOG.md b/CHANGELOG.md index b495c8a4..69320ebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/e2e/modal-driver.ts b/e2e/modal-driver.ts index 3c0fce39..333f0d17 100644 --- a/e2e/modal-driver.ts +++ b/e2e/modal-driver.ts @@ -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 }) }); diff --git a/e2e/modals.spec.ts b/e2e/modals.spec.ts index bcae3365..545ec30b 100644 --- a/e2e/modals.spec.ts +++ b/e2e/modals.spec.ts @@ -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"); diff --git a/src/components/modals/ModalSourcesTypeEditor.tsx b/src/components/modals/ModalSourcesTypeEditor.tsx index c12f5088..c1964e36 100644 --- a/src/components/modals/ModalSourcesTypeEditor.tsx +++ b/src/components/modals/ModalSourcesTypeEditor.tsx @@ -402,6 +402,15 @@ class ModalSourcesTypeEditorInternal extends React.Component {this.renderEditor()} + {source.type === "geojson" && + onChange({ + ...source, + lineMetrics, + })} + />} {(source.type === "geojson" || source.type === "vector") && } ; diff --git a/src/locales/az/translation.json b/src/locales/az/translation.json index 4fb2c425..b63aa9e7 100644 --- a/src/locales/az/translation.json +++ b/src/locales/az/translation.json @@ -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.": "URL-dən yüklə. Qeyd edin ki, URL-də <1>CORS aktiv olmalıdır.", "Load from URL": "URL-dən yüklə", diff --git a/src/locales/de/translation.json b/src/locales/de/translation.json index 7f1c4fbf..cc0e624e 100644 --- a/src/locales/de/translation.json +++ b/src/locales/de/translation.json @@ -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.": "Von einer URL laden. Beachte, dass die URL <1>CORS aktiviert haben muss.", "Load from URL": "Von URL laden", diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json index 7ca8e22c..e05d32c3 100644 --- a/src/locales/fr/translation.json +++ b/src/locales/fr/translation.json @@ -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.": "Charger depuis une URL. Notez que l'URL doit avoir les <1>CORS activés.", "Load from URL": "Charger depuis une URL", diff --git a/src/locales/he/translation.json b/src/locales/he/translation.json index 506d9d20..4b99de18 100644 --- a/src/locales/he/translation.json +++ b/src/locales/he/translation.json @@ -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.": "פתיחה מכתובת, שימו לב: הכתובת צריכה לתמוך ב- CORS", "Load from URL": "פתיחה מתוך כתובת", diff --git a/src/locales/it/translation.json b/src/locales/it/translation.json index 0d29cee1..27de4b95 100644 --- a/src/locales/it/translation.json +++ b/src/locales/it/translation.json @@ -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.": "Carica da URL. Nota che l'URL deve avere l'abilitazione <1>CORS attivata.", "Load from URL": "Carica da URL", diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.json index 458b0472..e60468b4 100644 --- a/src/locales/ja/translation.json +++ b/src/locales/ja/translation.json @@ -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.": "URLから読み込む。注意: URLは <1>CORSを有効にする 必要があります。", "Load from URL": "URLから読み込む", diff --git a/src/locales/ko/translation.json b/src/locales/ko/translation.json index 8b5420f1..c51d1163 100644 --- a/src/locales/ko/translation.json +++ b/src/locales/ko/translation.json @@ -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.": "URL에서 불러옵니다. URL은 <1>CORS가 활성화되어 있어야 합니다.", "Load from URL": "URL에서 불러오기", diff --git a/src/locales/pl/translation.json b/src/locales/pl/translation.json index b8b50516..28c5a71d 100644 --- a/src/locales/pl/translation.json +++ b/src/locales/pl/translation.json @@ -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.": "Wczytaj styl z adresu URL. Serwer musi <1>zezwalać na dostęp przez CORS.", "Load from URL": "Wczytaj z adresu URL", diff --git a/src/locales/tr/translation.json b/src/locales/tr/translation.json index f097e4b6..f5ae4865 100644 --- a/src/locales/tr/translation.json +++ b/src/locales/tr/translation.json @@ -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.": "Bir URL'den yükleyin. URL'de <1>CORS etkin olmalıdır.", "Load from URL": "URL'den yükle", diff --git a/src/locales/zh/translation.json b/src/locales/zh/translation.json index c0c2b267..765f03bf 100644 --- a/src/locales/zh/translation.json +++ b/src/locales/zh/translation.json @@ -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.": "从URL加载。注意:URL必须启用 <1>CORS。", "Load from URL": "从URL加载",