feat(core): derive layer visibility from visibleWhenLayerIds - #233
Conversation
Hosts can bind a layer to other layers so it stays on only while every listed layer is visible.
🦋 Changeset detectedLatest commit: 9926198 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR introduces derived layer visibility based on metaData.visibleWhenLayerIds, ensuring dependent layers automatically show/hide based on the visibility of required layers after each map-controller reduce. It also centralizes overlay z-indexing via a shared Z_INDEX_OVERLAY constant so selection/highlight overlays reliably render above catalog layers.
Changes:
- Add
metaData.visibleWhenLayerIdsto the map config schema and derive dependent layer visibility viasyncDependentLayerVisibility. - Apply dependent-visibility derivation after each
WithLayers.reduce(including after exclusive base-layer toggles). - Introduce a shared
Z_INDEX_OVERLAYconstant and reuse it across overlay layer implementations.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/js/ol-proxy/definitions/layer/VectorOverlayLayer.ts | Use shared Z_INDEX_OVERLAY for vector overlay layer z-index. |
| packages/core/src/js/lib/map/z-index.ts | Add shared overlay z-index constant. |
| packages/core/src/js/lib/map/schema.ts | Extend layer metadata schema with visibleWhenLayerIds. |
| packages/core/src/js/lib/map/lib/WithLayers.ts | Apply dependent visibility derivation after each reduce. |
| packages/core/src/js/lib/map/lib/WithLayers.test.ts | Add integration tests verifying derivation runs via WithLayers and MapController. |
| packages/core/src/js/lib/map/lib/WithLayerOverlays.ts | Import/re-export shared Z_INDEX_OVERLAY and ensure overlay definition uses it. |
| packages/core/src/js/lib/map/lib/syncDependentLayerVisibility.ts | Implement dependent-visibility derivation helper. |
| packages/core/src/js/lib/map/lib/syncDependentLayerVisibility.test.ts | Add unit tests for dependent-visibility behavior. |
| packages/core/src/js/lib/map/tests/schema.test.ts | Add schema test coverage for visibleWhenLayerIds. |
| .changeset/core-visible-when-layer-ids.md | Record minor bump for @mapsight/core. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const desired = requiredIds.every( | ||
| (requiredId) => layers[requiredId]?.options?.visible === true, | ||
| ); | ||
| const current = layer.options?.visible === true; | ||
| if (desired === current) { | ||
| continue; | ||
| } | ||
|
|
||
| if (!copied) { | ||
| result = {...layers}; | ||
| copied = true; | ||
| } | ||
| result[id] = { | ||
| ...layer, | ||
| options: { | ||
| ...layer.options, | ||
| visible: desired, | ||
| } as LayerState["options"], | ||
| }; | ||
| } | ||
|
|
||
| return result; |
Summary
metaData.visibleWhenLayerIdsso a layer stays visible only while every listed layer is on (AND).Z_INDEX_OVERLAYconstant so highlights stay above catalog layers.Test plan
pnpm --filter @mapsight/core exec vitest run src/js/lib/map/lib/syncDependentLayerVisibility.test.ts src/js/lib/map/lib/WithLayers.test.ts src/js/lib/map/__tests__/schema.test.tspnpm --filter @mapsight/core typecheckpnpm changeset status --since=origin/mainreports a minor bump for@mapsight/corevisibleWhenLayerIdsfollows it