From 16056f662701523ac19437f690abaea24f9b652e Mon Sep 17 00:00:00 2001 From: Thomas Halwax Date: Fri, 22 May 2026 12:15:30 +0200 Subject: [PATCH] Fix feature/layer styles being dropped on import until refresh 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. --- src/renderer/model/sources/featureSource.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderer/model/sources/featureSource.js b/src/renderer/model/sources/featureSource.js index 3f36b348..adb22264 100644 --- a/src/renderer/model/sources/featureSource.js +++ b/src/renderer/model/sources/featureSource.js @@ -167,7 +167,10 @@ export const featureSource = services => { layerStyle.on(({ type, key, value }) => { const layerId = ID.layerId(key) + // Keep state.styles in sync so features created later in the same batch + // (readFeature reads their initial style from state.styles) pick it up. if (type === 'del') delete state.styles[key] + else state.styles[key] = value source.getFeatures() .filter(feature => ID.layerId(feature.getId()) === layerId) .forEach(feature => feature.$.layerStyle(type === 'put' ? value : {})) @@ -176,7 +179,10 @@ export const featureSource = services => { featureStyle.on(({ type, key, value }) => { const featureId = ID.featureId(key) const feature = getFeatureById(featureId) + // Keep state.styles in sync so features created later in the same batch + // (readFeature reads their initial style from state.styles) pick it up. if (type === 'del') delete state.styles[key] + else state.styles[key] = value if (feature) feature.$.featureStyle(type === 'put' ? value : {}) })