Bounding box on mouseover event for small points and narrow lines
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
When attempting to hover on a small point or a narrow line, there is only a small number of pixels that allow the mouseover event to activate.

Originally raised by [Stevage](https://github.com/mapbox/mapbox-gl-js/issues/2537#issuecomment-271781655_)
## Design Alternatives
[SO source for ideas](https://stackoverflow.com/questions/51039362/popup-for-a-line-in-mapbox-gl-js-requires-padding-or-approximate-mouse-over)
- Creating a layer with wider lines that's invisible
- "The only other thing I can think of is `querySourceFeatures` and use turf to do a [pointToLineDistance](http://turfjs.org/docs/#pointToLineDistance) but that would be even slower and messy than just adding that invisible mouse target layer."
## Design
### Mock-Up
It may be unintuitive hovering on a line that doesn't exist, but at least in my application in my opinion its better than not knowing what that line is.
The developer may have to trial and error the bounding box margin to determine which is best.
### Concepts
### Implementation
This would work although it would require adding a new parameter to `map.on`.
`map.on('mouseenter', layer, {boundary: 5})` representing 5 pixels of entering the layer.
Another option could be through the layer or paint specification
```js
let layer = {
...
"paint": {
"line-width": 0.3,
"line-width-event": 2
}
}
```
Or rename to `line-width-hover`, or move it to the root layer instead of paint as it isn't visually rendered
Willing to contribute
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the map.on event API and the layer paint specification described in the issue. Compare the proposed event boundary parameter with the proposed line-width-event or line-width-hover property, then clarify one design and its edge cases before implementation; done means a documented, tested way to expand hover targeting for small points or narrow lines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100