Skip to content

feat: highlight overlay for hover, multi-select, and custom colors#657

Open
BRaimbault wants to merge 4 commits into
masterfrom
feat/hover-events-multi-highlight
Open

feat: highlight overlay for hover, multi-select, and custom colors#657
BRaimbault wants to merge 4 commits into
masterfrom
feat/hover-events-multi-highlight

Conversation

@BRaimbault

@BRaimbault BRaimbault commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

What

Replaces direct feature-state styling on the base source with a cloned "highlight overlay" — a small GeoJSON source + cloned GL layers drawn above each layer's own base layers — so hover and persistent selection can each highlight one or more features, in an optional custom color, without touching the base source.

Why

The previous model (setHoverState toggling feature-state.hover directly on the base source) only supported a single hovered feature per layer and had no concept of persistent multi-selection or per-highlight color. This change adds both.

Key changes

  • Map#onMouseMove now tracks the hovered layer/feature and fires mouseenter/mouseleave events instead of writing hover state directly; Layer/LayerGroup gained an onMouseEnter/onMouseLeave option.
  • Layer#highlight(ids, color) / Layer#select(ids, color) (and the same on LayerGroup) accept a single id or array of ids plus an optional color, and drive the new overlay (src/utils/highlightOverlay.js). Hover and selection share one highlight color by design — see the doc comment on highlight()/select().
  • Layer#setVisibleIds/LayerGroup#setVisibleIds/Cluster#setVisibleIds filter which features render per layer, and drop any now-hidden id out of the highlight overlay too.
  • Cluster's separate polygon source now refreshes correctly after setVisibleIds(), and its clusterLayer paint reacts to hover/selection like the other layer builders.
  • Layer#setVisibility/removeFrom correctly show/hide and clean up the overlay's cloned layers along with the base ones.

Known issues

Highlighting a polygon-derived feature inside a Cluster subclass currently has no visible effect — documented in-code at src/layers/Cluster.js (the polygon-to-point conversion used for clustering). Root-caused but not fixed here; it's a bigger architectural change (a second overlay source scoped to the polygon source) better scoped as its own follow-up.

@BRaimbault BRaimbault marked this pull request as ready for review July 13, 2026 15:09
@sonarqubecloud

Copy link
Copy Markdown

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