Click and Hover
Style layers with vector features report taps and the mouse on their features while they are on a map:
onClick: the user tapped or clicked a feature of the layer.onEnter: a mouse or stylus moved onto a feature of the layer.onLeave: the mouse or stylus left the feature thatonEnterreported.
Set them as constructor parameters of a layer you add, or on a layer of the loaded style:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Details
- Each
StyleLayerFeatureEventholds the topmostRenderedFeatureof the layer under the pointer, and where the pointer is aspointandscreenPoint. - Every layer under a tap reports it, not only the topmost one, like gl-js
map.on('click', layerId, ...).MapLibreMap.onClickis called as well. - Features with an id are told apart: moving from one onto another reports
onLeavefor the first andonEnterfor the second. A layer of features without ids reports entering and leaving its features as a whole. - Removing the layer or loading a new style ends the calls.
CircleStyleLayer,FillStyleLayer,FillExtrusionStyleLayer,HeatmapStyleLayer,LineStyleLayerandSymbolStyleLayerreport them.- Touches don't hover, so
onEnterandonLeaveare only called for mice and styluses. - For annotation layers, see annotations: click and hover.