Skip to content

[8.19] [Maps] Show labels after saving edits while staying on Vector tiles (… (#240728)#241285

Merged
nreese merged 1 commit intoelastic:8.19from
nreese:backport/8.19/pr-240728
Oct 30, 2025
Merged

[8.19] [Maps] Show labels after saving edits while staying on Vector tiles (… (#240728)#241285
nreese merged 1 commit intoelastic:8.19from
nreese:backport/8.19/pr-240728

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Oct 30, 2025

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

elastic#240728)

Closes elastic#240727
---

## Summary
When using **Maps → Create index (Draw shapes)**, the new layer defaults
to **Scaling → Use vector tiles**.
Adding label styling (Fixed or By value) previously did **not** display
labels until the user manually changed Scaling to **Limit results** and
back.
This PR makes labels appear immediately (after styling or save) on
vector-tiles layers by:

- Requesting MVT tiles with **`with_labels=true`** when label styling is
active
- **Refreshing** tile sources when label styling changes and after
saving edits
- Properly routing **GEOJSON_VECTOR** layers with `scalingType: MVT`
through the MVT pipeline

Elastic’s `_mvt` API returns suggested label points when
`with_labels=true`; this wires Kibana to use that path and refresh tiles
accordingly.
Kibana’s **Vector layer** docs describe the scaling modes this aligns
with.

> 🧠 Investigation and solution developed with the help of the large
language model **Claude Sonnet 4.5**, used to analyze the root cause and
assist in implementation.

---

### What changed (files)
1.
**`x-pack/platform/plugins/shared/maps/public/classes/layers/vector_layer/mvt_vector_layer/mvt_vector_layer.tsx`**
• Snapshots the current label descriptor and `hasLabels` flag into the
source request meta; any change invalidates the cached tiles and
re-fetches through the MVT layer.

2.
**`x-pack/platform/plugins/shared/maps/public/classes/layers/vector_layer/mvt_vector_layer/mvt_source_data.ts`**
• Respect `isForceRefresh` (was checking only
`forceRefreshDueToDrawing`).
• Generate a new token only when `hasLabels` or buffer change (prevents
loops).
• Include **`with_labels=true`** in tile requests when label styling is
active (Elasticsearch `_mvt` label points).

3.
**`x-pack/platform/plugins/shared/maps/public/classes/layers/wizards/new_vector_layer_wizard/wizard.tsx`**
• When Create index uses MVT scaling, emit an **MvtVectorLayer**
descriptor so the layer starts on the MVT pipeline and picks up the
label-refresh logic.

> **Note:** `geojson_vector_layer.tsx` is restored to match `main` (no
MVT source added by GeoJSON). Vector-tile rendering remains owned by
`MvtVectorLayer`.

Per Elastic’s docs, the vector-tile search API can return suggested
label points when `with_labels=true`; the Vector layer docs describe
when to use **Use vector tiles** vs **Limit results**. This change wires
Kibana’s MVT path to request tiles with labels and refresh them when
styling/saving, so labels render without a scaling toggle.

---

### Why
During the Create index workflow, vector-tiles scaling is the default.
Tiles are built server-side from indexed data, so unsaved edits and
label changes don’t show until tiles are refreshed.
By requesting tiles with labels and refreshing them on style or save,
labels now render as expected without a manual scaling toggle.

---

### Before / After
| Before | After |
|:--|:--|
| Create index → Draw point → Add label → Label missing until Scaling
changed | Create index → Draw point → Add label → Label appears
instantly (no toggle needed) |

**Before (GIF):**

![kibana_gif_not_working](https://github.com/user-attachments/assets/6295581d-a902-47a3-aeea-4f8dfb616793)

**After (GIF):**

![kibana_working_gif](https://github.com/user-attachments/assets/e859c649-6eb1-4139-adea-6bd7ed5f7986)

---

### Testing
This change was verified manually; **no new unit or functional tests
were added** in this PR.

**Manual validation steps**
- Add layer → Create index
- Draw a point or other shape
- Add label styling (Fixed value and By value) → labels appear
immediately without toggling scaling
- Modify label text → label updates in real time
- Toggle labels on/off → tiles refresh correctly
- Save edits → labels persist after saving
- No crashes, flickering, or infinite refresh loops

**Test coverage note**
Existing Jest tests for Maps layers and source syncing still pass.
Potential follow-ups:
- Label style change triggers `isForceRefresh=true`
- `with_labels=true` included in MVT tile requests when labels are
active
- GeoJSON→MVT rendering path switching works without regression

---

## Release note
**Fix:** Labels in the **Create index** flow now render with the default
**Use vector tiles** scaling as soon as label styling is applied (or
after save), without requiring a scaling toggle.

---

### Checklist
- [x] No new UI strings (i18n N/A); follows EUI sentence case
- [x] No HTTP API or security changes
- [ ] Unit tests updated/added *(none in this PR; validated manually)*
- [x] Include release note
- [ ] Labels (`release_note:*`, `backport:*`, `review`, `community`)
will be applied by maintainers during triage

---

### Identify risks
- **Scope:** Limited to Create index / MVT-scaling render path
- **Performance:** `with_labels` adds small label points per tile; only
used when labels are enabled
- **Mitigation:** Refresh is scoped to the affected layer; token
generation avoids loops

---

### Validation
```bash
nvm use 22.17.1
yarn kbn bootstrap
yarn lint
yarn test:jest x-pack/platform/plugins/shared/maps
yarn es snapshot --license trial
yarn start

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 3b3adac)

# Conflicts:
#	x-pack/platform/plugins/shared/maps/public/classes/layers/wizards/new_vector_layer_wizard/wizard.tsx
@nreese nreese requested a review from kibanamachine as a code owner October 30, 2025 13:29
@nreese nreese added the backport This PR is a backport of another PR label Oct 30, 2025
@nreese nreese enabled auto-merge (squash) October 30, 2025 13:29
@nreese nreese merged commit 2f6b2eb into elastic:8.19 Oct 30, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

3 participants