Create a hover effect
Replicates the MapLibre example Create a hover effect, loading the same US-states GeoJSON file upstream loads.
The complete document
Section titled “The complete document”# yaml-language-server: $schema=https://docs.maplibre-yaml.org/schema/latest/map.schema.json# Gallery twin of https://maplibre.org/maplibre-gl-js/docs/examples/create-a-hover-effect/# Same US-states file as upstream, loaded by url — matching not just the# visual but the loading mode. The upstream version wires mousemove/# mouseleave + setFeatureState by hand; here per-feature hover is one flag.type: mapid: create-a-hover-effectconfig: center: [-100.486, 38.0] zoom: 3 mapStyle: "https://demotiles.maplibre.org/style.json"layers: - id: states type: fill source: type: geojson url: "https://maplibre.org/maplibre-gl-js/docs/assets/us_states.geojson" generateId: true paint: fill-color: "#627BC1" fill-opacity: 0.6 interactive: hover: highlight: true cursor: pointerWhat to notice
Section titled “What to notice”hover.highlight: truereplaces upstream’s mousemove/mouseleave handlers and manualsetFeatureStatecalls;generateId: truesupplies the feature ids feature-state needs on url-loaded data.- The highlight color is currently fixed (gold) — authorable highlight styling is on the backlog.