mirror of
https://github.com/maputnik/editor.git
synced 2026-12-05 16:24:20 +00:00
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.
103 lines
3.9 KiB
TypeScript
103 lines
3.9 KiB
TypeScript
import { v1 as uuid } from "uuid";
|
|
import { PlaywrightHelper } from "./playwright-helper";
|
|
|
|
export class ModalDriver {
|
|
private readonly helper = new PlaywrightHelper();
|
|
|
|
public when = {
|
|
fillLayers: async (opts: { type: string; layer?: string; id?: string }) => {
|
|
const { when, get, then } = this.helper;
|
|
const id = opts.id ?? `${opts.type}:${uuid()}`;
|
|
|
|
await when.select("add-layer.layer-type.select", opts.type);
|
|
await when.type("add-layer.layer-id.input", id);
|
|
|
|
if (opts.layer) {
|
|
const input = get.elementByTestId("add-layer.layer-source-block").locator("input");
|
|
await input.click();
|
|
await input.fill(opts.layer);
|
|
// The source input is a controlled downshift combobox; wait for React to
|
|
// settle on the typed value before submitting.
|
|
await then(input).shouldHaveValue(opts.layer);
|
|
// Close the autocomplete menu so it does not intercept the add button.
|
|
await get.elementByTestId("add-layer.layer-id.input").click();
|
|
}
|
|
await when.click("add-layer");
|
|
|
|
return id;
|
|
},
|
|
|
|
open: async () => {
|
|
await this.helper.when.click("layer-list:add-layer");
|
|
},
|
|
|
|
close: async (key: string) => {
|
|
await this.helper.when.click(key + ".close-modal");
|
|
},
|
|
|
|
/**
|
|
* Adds a source of the given type from the sources modal, keeping whatever
|
|
* defaults that type's editor prefills.
|
|
*/
|
|
addSource: async (sourceId: string, sourceType: string) => {
|
|
const { when } = this.helper;
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", sourceType);
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.wait(200);
|
|
},
|
|
|
|
/** Adds one of the predefined public sources listed in the sources modal. */
|
|
addPublicSource: async (index = 0) => {
|
|
await this.helper.get.element(".maputnik-public-source-select").nth(index).click();
|
|
},
|
|
|
|
deleteFirstActiveSource: async () => {
|
|
await this.helper.get.element(".maputnik-active-source-type-editor-header-delete").first().click();
|
|
},
|
|
|
|
enableGeneratedFeatureIds: async () => {
|
|
await this.helper.get.element(".maputnik-add-source")
|
|
.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 }) });
|
|
const input = source.getByRole("textbox", { name: "Feature ID property" });
|
|
await input.fill(value);
|
|
await input.blur();
|
|
},
|
|
|
|
setNewSourceFeatureIdMapping: async (mapping: Record<string, string>) => {
|
|
await this.helper.get.element(".maputnik-add-source [data-wd-key='source-promote-id-mapping'] .cm-content").click();
|
|
await this.helper.when.typeKeys("{selectall}");
|
|
await this.helper.when.typeText(JSON.stringify(mapping));
|
|
},
|
|
|
|
/** Fills one number box of a coordinate pair in the image/video source editor. */
|
|
setCoordinateValue: async (index: number, value: string) => {
|
|
const input = this.helper.get
|
|
.elementByTestId("modal:sources")
|
|
.locator(".maputnik-array input")
|
|
.nth(index);
|
|
await input.fill(value);
|
|
await input.blur();
|
|
},
|
|
|
|
exportCreateHtml: async () => {
|
|
await this.helper.get.element(".maputnik-modal-export-buttons button").last().click();
|
|
},
|
|
|
|
exportSaveStyle: async () => {
|
|
await this.helper.stubSaveFilePicker();
|
|
await this.helper.get.element(".maputnik-modal-export-buttons button").first().click();
|
|
},
|
|
};
|
|
}
|