Skip to content

Highlight

Overview

useHighlight(name, options) manages a reactive store of map highlights — styled GeoJSON features rendered on top of the map to indicate selection or focus. It maintains a dedicated system GeoJSON layer (HighlightsLayerName) and keeps highlights in sync with real-time service events on feature layers.

Highlights are debounced (configurable via options.updateDelay) and rendered sorted by zOrder from the properties.

Usage

javascript
import { useHighlight } from '@kalisio/kdk/map.client'

const {
  highlights, highlight, unhighlight,
  hasHighlight, getHighlight, clearHighlights
} = useHighlight('myMap', { updateDelay: 100, asBbox: false })

Parameters

ParameterTypeDefaultDescription
namestringUnique highlight store name within the application. Used as the key in the highlights namespace of the global store.
options.updateDelaynumber250Debounce delay in milliseconds for updating the highlights layer.
options.asBboxbooleanfalseWhen true, lines and polygons are highlighted using their bounding box polygon instead of the original geometry.
(map style properties)Any additional style properties are merged into each highlight feature as default style overrides.

Exposed

NameTypeDescription
highlightsreactive ObjectThe raw highlight store for this name. Keys are highlight IDs, values are highlight feature objects.
setCurrentActivity(activity)FunctionBinds the composable to a new map activity instance. Removes the highlights layer from the previous activity and registers it on the new one.
setHighlightMode(mode)FunctionSets the highlight filtering mode. 'highlightable-layers' (default) only highlights features from layers where isHighlightable is true. Any other string disables this filter.
hasHighlight(feature, layer)FunctionReturns true if a highlight exists for the given feature and layer.
getHighlight(feature, layer)FunctionReturns the highlight object for the given feature and layer, or undefined.
getHighlights(layer?, feature?)FunctionReturns all current highlights. Optionally filtered by layer and/or feature. Aggregates across all highlight stores (all names).
highlight(feature, layer, selected?)FunctionAdds or updates a highlight for the given feature. When selected is true (default), applies the engine selection style; otherwise uses the feature's own style. Returns the highlight object.
unhighlight(feature, layer)FunctionRemoves the highlight for the given feature and layer.
setHighlightEnabled(feature, layer, enabled?)FunctionShows or hides a single highlight by setting its style.visibility.
setHighlightsEnabled(layer, enabled?)FunctionShows or hides all highlights associated with a given layer.
clearHighlights()FunctionRemoves all highlights from the store and updates the layer.

Constants

NameDescription
HighlightsLayerNameUnique name of the system GeoJSON layer used to render highlights. Generated with uid().
HighlightsZIndexZ-index (999) of the highlights layer, ensuring it renders on top of all other layers.
HighlightMarginExtra pixels (8) added to a highlight marker's radius/size to visually encompass the target feature.

Lifecycle

  • beforeMount: Starts listening to feature service events on all existing layers.
  • beforeUnmount: Stops listening to feature service events and clears all highlights.
  • Registers layer-added / layer-removed handlers to track real-time events per layer.
  • Registers layer-disabled / layer-enabled handlers to toggle highlight visibility.
  • The highlights layer is created automatically when the first catalog layer is added to the activity, and removed when the activity changes.