Repository navigation
fix: stored layer state is what the map draws - #22
Merged
Merged
Conversation
Layer managers (the built-in panel, embedding apps like EOGPT) read GET /assets, but the live viewer drew from other state, so order, opacity and style regularly disagreed with what they showed: - update_style and PATCH replaced the whole stored style while viewers merged the patch; a reload then dropped every key not resent. Styles are now merged server-side (explicit null clears a key) and the complete result is broadcast with `full: true`. - set_opacity was broadcast-only. It is now stored as style.opacity, like GeoTIFF alpha and tile-layer opacity, which were never stored either. - One opacity model: the alpha byte of a #RRGGBBAA colour is the drawn alpha and style.opacity multiplies fills, outlines, markers and rasters. The hidden 0.5 fill factor is gone (default fill and drawn-shape alpha halved to keep their look); hover now lifts the fill colour's alpha. - All style -> paint goes through one viewer function (applyAssetStyle) for add, restore, update_style, set_opacity and asset_updated. - Vector defaults are materialized into the stored style at creation, and add_* broadcasts carry the stored (status-expanded) style. - Stacking: z-changing broadcasts carry the full stored z map (layer_z) and the viewer adopts it instead of renumbering itself; the session snapshot now includes z_index. Rasters added after a reload no longer land on top of vectors in the viewer while the DB has them below. reorder_assets renumbers every asset (unlisted ones stay below, as the viewer does), and move_layer/reorder rebuild the live stack from the same numbers. - Tile layers are restored on reload; drawn-shape broadcasts carry name, type and z. - The parent page is notified on reorder_assets and on snapshot restore. - SDK: Asset carries z_index/bbox, style parse keeps opacity/animate/status, reorder_assets(); docs describe merge and opacity semantics. Tests: a DB-only harness so asset/order/style tests run again (the MCP session manager's single-use lifespan errored every test after the first; their stale 200-vs-201 asserts are fixed), test_layer_state.py, and a headless-browser check comparing MapLibre's live stack/paint with GET /assets, live and after reload (11 of its 17 checks fail on main). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hover lift added a flat 8% to every fill's alpha, so outline-only layers (fill alpha 00) gained a tint under the cursor they never had. Lift by the old 0.5 -> 0.72 ratio only, which matches the previous hover look exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
What the server stored for a layer often differed from what the viewer drew, so any client that read layer state back (a layer panel, a reload, a second viewer) disagreed with the map. Specifically:
set_opacity,add_geotiff_*(alpha=…)andadd_tile_layer(opacity=…)only reached live viewers; after a reload every layer was back at 100%.style.opacityandset_opacitygave different results for the same number, and#3388ff40drew at about 13%, not 25%.update_styleandPATCH /assets/{id}overwrote the whole stored style, while the live viewer merged the patch. A partial update looked right until the next reload, then colours and labels fell back to defaults.z_index, and the viewer renumbered layers by its own rules, so later inserts landed in a different place than the database said.Change
Server
update_style,asset_updatedandPATCHmerge into the stored style. Sending a key asnullremoves it.set_opacity, GeoTIFFalphaand tileopacityare all stored asstyle.opacity, normalised to 0..1 (percentages are accepted too).reorder_assetsrenumbers every asset 0..n-1, with the listed ids (top first) on top and the rest kept below in their existing order.layer_zmap. The snapshot includesz_indexandbbox.create_assetand the add events acceptvisible, so a layer can be added hidden without a flash.Viewer (
serve_map)applyAssetStyle()is now the single place a style becomes paint, used for add, update, opacity and snapshot restore.opacitymultiplies it. Hover raises the fill colour's alpha instead.layer_znumbers instead of renumbering on its own.assetschanged.reorder_assetsis added toesip-contract.jschange events.Defaults and SDK
#3388ff20,#7cc24240) so the defaults look the same as before.Assetgainsz_indexandbbox,_parse_assetkeeps opacity, animate and status, and there is a newreorder_assets().docs/llm-context.mddescribes the alpha, opacity, merge and stacking rules.Behaviour changes for clients
null.set_opacitynow persists and is read back fromstyle.opacity.Tests
server/tests/_harness.pyadds a DB-only lifespan. Several layer test files only ran their first test because the MCP session manager can't be started twice. While fixing that, I updated 9 stale== 200asserts to201.test_layer_state.py(new, 16 tests): merge semantics, stored opacity on every path, reorder,layer_zbroadcasts, snapshotz_index, and adding hidden layers.test_layer_state_browser.py(new, Playwright, skips if unavailable): it compares MapLibre's rendered paint and order with the API, live and after a reload. 11 of its 17 checks fail onmainand all pass on this branch.🤖 Generated with Claude Code