diff --git a/CHANGELOG.md b/CHANGELOG.md index aeb67627..1c67eae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Set the min and max zoom of a PMTiles source, for example to overzoom past the last zoom level in the file - Change a layer's type from the layer editor; properties the new type doesn't support are removed - Add a "Line metrics" checkbox to GeoJSON sources, which `line-gradient` needs to render +- Add a "Use current map view" button to the style settings modal that fills center, zoom, bearing and pitch from the map - _...Add new stuff here..._ ### 🐞 Bug fixes diff --git a/e2e/layer-editor.spec.ts b/e2e/layer-editor.spec.ts index de0b6bea..63e4d575 100644 --- a/e2e/layer-editor.spec.ts +++ b/e2e/layer-editor.spec.ts @@ -366,7 +366,7 @@ describe("layer editor", () => { test("should convert to an expression without crashing", async () => { await when.makeExpression("circle-radius"); - await then(get.element("[data-wd-key='spec-field-container:circle-radius'] .maputnik-expression-editor")).shouldBeVisible(); + await then(get.expressionEditor("circle-radius")).shouldBeVisible(); await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ layers: [{ id, paint: { "circle-radius": ["interpolate", ["linear"], ["zoom"], 6, 5, 10, 5] } }], }); diff --git a/e2e/layers-list.spec.ts b/e2e/layers-list.spec.ts index 6ff3528e..fb0c0f54 100644 --- a/e2e/layers-list.spec.ts +++ b/e2e/layers-list.spec.ts @@ -234,7 +234,7 @@ describe("layers list", () => { await when.setValueToPropertyArray("spec-field:icon-padding", "5"); await when.makeExpression("icon-padding"); - await then(get.element("[data-wd-key='spec-field-container:icon-padding'] .cm-content")).shouldContainText('"literal"'); + await then(get.expressionEditor("icon-padding")).shouldContainText('"literal"'); }); describe("text-variable-anchor-offset", () => { @@ -263,16 +263,16 @@ describe("layers list", () => { test("should identify each anchor and offset by row and axis", async () => { await when.addValueToPropertyArray("spec-field:text-variable-anchor-offset", "8"); - await then(get.element("[data-wd-key='spec-field:text-variable-anchor-offset'] select[aria-label$='row 1 anchor']")).shouldBeVisible(); - await then(get.element("[data-wd-key='spec-field:text-variable-anchor-offset'] input[aria-label$='row 2 X offset']")).shouldHaveValue("0"); - await then(get.element("[data-wd-key='spec-field:text-variable-anchor-offset'] input[aria-label$='row 2 Y offset']")).shouldHaveValue("8"); + await then(get.variableAnchorOffsetControl(1, "anchor")).shouldBeVisible(); + await then(get.variableAnchorOffsetControl(2, "X offset")).shouldHaveValue("0"); + await then(get.variableAnchorOffsetControl(2, "Y offset")).shouldHaveValue("8"); }); test("should remove an anchor row", async () => { // the row's delete button shares the function stop's class await when.deleteFunctionStop("text-variable-anchor-offset"); - await then(get.element("[data-wd-key='spec-field:text-variable-anchor-offset'] select")).shouldNotExist(); + await then(get.variableAnchorOffsetControl(1, "anchor")).shouldNotExist(); }); }); }); diff --git a/e2e/maputnik-driver.ts b/e2e/maputnik-driver.ts index 6401af7d..0ac67033 100644 --- a/e2e/maputnik-driver.ts +++ b/e2e/maputnik-driver.ts @@ -433,6 +433,18 @@ export class MaputnikDriver { return "neither"; }), + /** The expression editor a spec field shows once its value is an expression. */ + expressionEditor: (fieldName: string) => + this.helper.get.elementByTestId("spec-field-container:" + fieldName).locator(".maputnik-expression-editor"), + + /** One control of a text-variable-anchor-offset row, e.g. `(2, "X offset")`. Rows count from 1. */ + variableAnchorOffsetControl: (row: number, control: "anchor" | "X offset" | "Y offset") => + this.helper.get.elementByTestId("spec-field:text-variable-anchor-offset").getByLabel(`row ${row} ${control}`), + + /** The longitude or latitude input of the Center field in the style settings modal. */ + styleCenterInput: (axis: "longitude" | "latitude") => + this.helper.get.elementByTestId("modal:settings").getByLabel("Center", { exact: true }).nth(axis === "longitude" ? 0 : 1), + spritePixel: (id: string, x: number, y: number) => this.helper.get.canvasPixel(`sprite-preview:${id}`, x, y), canvas: () => this.helper.get.element("canvas"), diff --git a/e2e/modals.spec.ts b/e2e/modals.spec.ts index 545ec30b..3daeb9d4 100644 --- a/e2e/modals.spec.ts +++ b/e2e/modals.spec.ts @@ -502,6 +502,31 @@ describe("modals", () => { }); }); + describe("when the map is at zoom 5", () => { + beforeEach(async () => { + await when.setStyle("geojson", 5); + await when.click("nav:settings"); + await when.setValue("modal:settings.bearing", "12"); + await when.setValue("modal:settings.pitch", "30"); + }); + + test("use current map view copies the map's view into the style", async () => { + await when.click("modal:settings.view-from-map"); + await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ + center: [2.1635, 41.3805], + zoom: 5, + bearing: 0, + pitch: 0, + }); + }); + + test("use current map view shows the map's center in the form", async () => { + await when.click("modal:settings.view-from-map"); + await then(get.styleCenterInput("longitude")).shouldHaveValue("2.1635"); + await then(get.styleCenterInput("latitude")).shouldHaveValue("41.3805"); + }); + }); + test("sky and fog blends", async () => { await when.setValue("modal:settings.sky-horizon-blend", "0.3"); await when.setValue("modal:settings.fog-ground-blend", "0.2"); diff --git a/e2e/sprite-picker.spec.ts b/e2e/sprite-picker.spec.ts index 50a3e50f..2685cc5c 100644 --- a/e2e/sprite-picker.spec.ts +++ b/e2e/sprite-picker.spec.ts @@ -80,7 +80,7 @@ describe("sprite picker", () => { test("keeps expressions in the existing expression editor", async () => { await when.chooseSprite("green"); await when.makeExpression("icon-image"); - await then(get.element("[data-wd-key='spec-field-container:icon-image'] .maputnik-expression-editor")).shouldBeVisible(); + await then(get.expressionEditor("icon-image")).shouldBeVisible(); await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ layers: [{ id: "symbols", layout: { "icon-image": ["literal", "green"] } }] }); await then(get.elementByTestId("spec-field-input:icon-image")).shouldNotExist(); }); diff --git a/src/components/App.tsx b/src/components/App.tsx index 7cc25c04..118acce6 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -119,6 +119,8 @@ type AppState = { lng: number, lat: number, }, + bearing?: number, + pitch?: number, _from: "map" | "app" }, maplibreGlDebugOptions: Partial & { @@ -710,6 +712,8 @@ export class App extends React.Component { lng: number, lat: number, }, + bearing?: number, + pitch?: number, _from: "map" | "app" }) => { this.setState({ @@ -973,6 +977,7 @@ export class App extends React.Component { /> { const center = map.getCenter(); const zoom = map.getZoom(); - this.props.onChange({center, zoom, _from: "map"}); + this.props.onChange({center, zoom, bearing: map.getBearing(), pitch: map.getPitch(), _from: "map"}); }; mapViewChange(); @@ -257,6 +257,8 @@ class MapMaplibreGlInternal extends React.Component { diff --git a/src/components/modals/ModalSettings.tsx b/src/components/modals/ModalSettings.tsx index 6d2b90e9..f84518eb 100644 --- a/src/components/modals/ModalSettings.tsx +++ b/src/components/modals/ModalSettings.tsx @@ -13,18 +13,32 @@ import { FieldColor } from "../FieldColor"; import { Modal } from "./Modal"; import { FieldJson } from "../FieldJson"; import { Block } from "../Block"; +import { InputButton } from "../InputButton"; import { spec as fieldSpecAdditional } from "../../libs/field-spec-additional"; import type {OnStyleChangedCallback, StyleSpecificationWithId} from "../../libs/definitions"; type ModalSettingsInternalProps = { mapStyle: StyleSpecificationWithId + mapView: { + zoom: number + center: { + lng: number + lat: number + } + bearing?: number + pitch?: number + } onStyleChanged: OnStyleChangedCallback onChangeMetadataProperty(...args: unknown[]): unknown isOpen: boolean onOpenToggle(): void } & WithTranslation; -class ModalSettingsInternal extends React.Component { +class ModalSettingsInternal extends React.Component { + state = { + viewFromMapCount: 0, + }; + changeTransitionProperty(property: keyof TransitionSpecification, value: number | undefined) { const transition = { ...this.props.mapStyle.transition, @@ -133,6 +147,21 @@ class ModalSettingsInternal extends React.Component this.props.onStyleChanged(changedStyle); } + setViewFromMap = () => { + const {zoom, center, bearing, pitch} = this.props.mapView; + // Rounded so the style doesn't get values like 2.1635000000000204 + const round = (value: number, digits: number) => +value.toFixed(digits); + const changedStyle: StyleSpecificationWithId = { + ...this.props.mapStyle, + center: [round(center.lng, 5), round(center.lat, 5)], + zoom: round(zoom, 2), + }; + if (bearing !== undefined) changedStyle.bearing = round(bearing, 1); + if (pitch !== undefined) changedStyle.pitch = round(pitch, 1); + this.props.onStyleChanged(changedStyle); + this.setState(({viewFromMapCount}) => ({viewFromMapCount: viewFromMapCount + 1})); + }; + render() { const metadata = this.props.mapStyle.metadata || {} as any; const {t, onChangeMetadataProperty, mapStyle} = this.props; @@ -223,7 +252,16 @@ class ModalSettingsInternal extends React.Component onChange={(value) => onChangeMetadataProperty("maputnik:locationiq_access_token", value)} /> + + {t("Use current map view")} + + + {/* InputArray only reads its value on mount, so remount it to show a center set by the button */}