Fix feature/layer styles dropped on import until refresh#120
Merged
Conversation
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.
479553a to
16056f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.insertemits a singlebatchcontaining both thefeature:entriesand their
style+feature:entries.featureSource's batch ordering (ord)deliberately processes
put style+(ord 2) beforeput feature(ord 3),so that the feature created afterwards can read its initial style from
state.stylesinsidereadFeature.But the
featureStyleandlayerStylehandlers only ever deleted fromstate.styles(ondel) and never wrote to it onput. So on import:getFeatureByIdreturns
undefined) and discards the signal update;state.stylesstill holds the dictionary loaded once at startup, so thefeature 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]onputin both thefeatureStyleandlayerStylehandlers, matching the intent of the existing batch ordering.No behaviour change for the already-working in-app editing path.
Testing
style+feature:entries -> styling nowrenders immediately, no refresh needed.