Skip to content

Fix feature/layer styles dropped on import until refresh#120

Merged
ThomasHalwax merged 1 commit into
mainfrom
fix/feature-style-on-import
May 22, 2026
Merged

Fix feature/layer styles dropped on import until refresh#120
ThomasHalwax merged 1 commit into
mainfrom
fix/feature-style-on-import

Conversation

@ThomasHalwax
Copy link
Copy Markdown
Member

@ThomasHalwax ThomasHalwax commented May 22, 2026

Problem

When a layer is imported (drag & drop or paste), feature geometries appear
immediately on the map but their styling (e.g. line colour and width) only
becomes visible after a refresh.

Root cause

store.insert emits a single batch containing both the feature: entries
and their style+feature: entries. featureSource's batch ordering (ord)
deliberately processes put style+ (ord 2) before put feature (ord 3),
so that the feature created afterwards can read its initial style from
state.styles inside readFeature.

But the featureStyle and layerStyle handlers only ever deleted from
state.styles (on del) and never wrote to it on put. So on import:

  1. the style event fires first, finds no live feature yet (getFeatureById
    returns undefined) and discards the signal update;
  2. state.styles still holds the dictionary loaded once at startup, so the
    feature created next initialises with an empty style.

The style only appears after a refresh, when the init block re-reads
store.dictionary('style+') from the now-persisted entries.

Fix

Update state.styles[key] on put in both the featureStyle and
layerStyle handlers, matching the intent of the existing batch ordering.
No behaviour change for the already-working in-app editing path.

Testing

  • Imported a layer with per-feature style+feature: entries -> styling now
    renders immediately, no refresh needed.
  • Editing feature/layer styles on existing features continues to work.

When a layer is imported (drag & drop / paste), the store emits a single
batch containing both the feature entries and their `style+` entries.
`featureSource`'s batch ordering processes `put style+` (ord 2) before
`put feature` (ord 3) so that the freshly created feature can pick up its
style from `state.styles` in `readFeature`.

However, the `featureStyle` and `layerStyle` handlers only ever *deleted*
from `state.styles` (on `del`) and never wrote to it on `put`. As a result:

- the style handler ran first, found no live feature yet, and discarded
  the update;
- `state.styles` still held the stale dictionary loaded at startup, so the
  feature created afterwards initialised with an empty style.

The style only became visible after a refresh, when the init block
re-reads `store.dictionary('style+')` from the now-persisted entries.

Fix: update `state.styles[key]` on `put` in both handlers, matching the
intent of the existing batch ordering.
@ThomasHalwax ThomasHalwax force-pushed the fix/feature-style-on-import branch from 479553a to 16056f6 Compare May 22, 2026 10:16
@ThomasHalwax ThomasHalwax merged commit 0611243 into main May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant