mirror of
https://github.com/maputnik/editor.git
synced 2026-12-05 16:24:20 +00:00
Fixes #730. The Style Settings modal now has a "Use current map view" button above the Center field. It copies the map's current center, zoom, bearing and pitch into the style, so you don't have to copy them from the URL hash by hand. To make bearing and pitch available, the MapLibre map now reports them with center and zoom, and also reports after a rotate or pitch ends (before, only `dragend` and `zoomend` did). The OpenLayers renderer doesn't report bearing or pitch, so with it the button only fills center and zoom. Values are rounded before they go into the style: center to 5 decimals (about 1 m), zoom to 2, bearing and pitch to 1. Without that the style gets values like `2.1635000000000204`. The Center field gets a `key` that changes each time the button is clicked. `InputArray` only reads its value when it mounts, so it keeps half-typed coordinates while you edit, but that also means it wouldn't show a center set from outside. Remounting it on the button click shows the new center and leaves normal typing alone. **Before / after** (Style Settings): | Before | After | |---|---| | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-730/before-style-settings.png" width="400"> | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-730/after-style-settings.png" width="400"> | **Performance:** no measurable impact. The map calls the existing `onChange` once more at the end of a rotate or pitch gesture, which is the same work it already does after each drag and zoom. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Link to related issues: fixes #730. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality: `use current map view copies the map's view into the style` in `modals.spec.ts` opens the map at zoom 5, sets bearing 12 and pitch 30 in the form, clicks the button and checks that the style has the map's center, zoom, bearing 0 and pitch 0. It fails on `main`, and it also fails if the map doesn't report bearing and pitch. A second test, `use current map view shows the map's center in the form`, checks that the Center input shows the new value. - [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 (222 passed). The first test fails on `main`, and also fails if I put back `main`'s `MapMaplibreGl.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.