Edit text-variable-anchor-offset as a list of anchors with offsets (#2393)

`text-variable-anchor-offset` is the only layer property whose spec
type, `variableAnchorOffsetCollection`, had no input. `InputSpec` fell
through to its `default` case, so the layer editor showed the label with
nothing next to it, even when the layer had a value. It also logged `No
proper field input for text-variable-anchor-offset` on every render
(mentioned in #1524). HarelM suggested looking for spec properties that
maputnik doesn't support yet in #2391, and this is the one I found for
layers.

The value is a flat list of anchors, each followed by its `[x, y]`
offset, e.g. `["top", [0, 4], "left", [3, 0]]`. The new
`InputVariableAnchorOffsetCollection` shows one row per anchor: an
anchor dropdown (the same nine values as `text-variable-anchor`), then
the x and y offsets. It reuses the add/remove row layout and the delete
button from `InputDynamicArray`. "Add value" appends `center` with `[0,
0]`, and removing the last row unsets the property.

`FieldFunction` used to route every value of this type to the plain
input, including expressions. It now does that only for a literal list
(`isVariableAnchorOffsetCollection` in `spec-helper.ts`). An expression,
including the `["literal", ...]` that "Convert to expression" produces,
opens the expression editor as it does for other properties.

| Before | After |
|---|---|
|
![before](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-anchor-offset/before.png)
|
![after](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-anchor-offset/after.png)
|

Both show a symbol layer with `"text-variable-anchor-offset": ["top",
[0, 1], "left", [2, 0]]` in Chromium.

**Performance:** none. The input only renders for this one property, and
the type check is a single pass over a short array.

## Launch Checklist

 - [x] Briefly describe the changes in this PR.
- [x] Link to related issues: #1524 (the console warning), follow-up to
#2391.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
- [x] Write tests for all new functionality: three e2e tests in
`layers-list.spec.ts` (save an anchor with its offset, change the
anchor, remove a row) and a unit test for
`isVariableAnchorOffsetCollection`. All three e2e tests fail on `main`,
and the anchor and remove tests fail when I change the expected anchor
or skip the delete.
 - [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` (213
passed). I also checked it in the dev server: editing an offset,
changing an anchor, adding and removing rows all save to the style, and
a layer whose value is a `case` expression opens in the expression
editor.

Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the change,
the tests 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 07:51:16 +02:00
1 parent 3a5d9aee9e
commit c9f44b0cd6
9 files changed
+183 -4

No files matched your search

+2 -2
View File
@@ -5,7 +5,7 @@ import { DataProperty, type Stop } from "./DataProperty";
import { ZoomProperty } from "./ZoomProperty";
import { ExpressionProperty } from "./ExpressionProperty";
import {function as styleFunction} from "@maplibre/maplibre-gl-style-spec";
import {findDefaultFromSpec} from "../libs/spec-helper";
import {findDefaultFromSpec, isVariableAnchorOffsetCollection} from "../libs/spec-helper";
import { type MappedLayerErrors } from "../libs/definitions";
@@ -100,7 +100,7 @@ function getDataType(value: any, fieldSpec={} as any) {
else if (fieldSpec.type === "padding") {
return "value";
}
else if (fieldSpec.type === "variableAnchorOffsetCollection") {
else if (fieldSpec.type === "variableAnchorOffsetCollection" && isVariableAnchorOffsetCollection(value)) {
return "value";
}
else if (isZoomField(value)) {