Add a background attribute to line type custom layers to increase clickable width
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
I have custom layers to add multi-line layers (hiking and cycling trails) which are clickable on the front end (using `map.queryRenderedFeatures()`, an information panel on the clicked line is shown). Because these lines are typically 1-2px, it is very hard to click/tap on the line and not just on the surroundings.
I would like to see something like a `background` attribute added to the line that would have width and colour attributes (the colour could be set to alpha 0 for transparent) so that when I click on the background it returns a result for that layer. This should also be available to Studio, not just the api.
## Design Alternatives
The only way I have found to get around this is to duplicate the layer, set the line width to 20px (for example) and the opacity to 0. My front-end then queries this layer rather than the visible one.
It's quite a redundant method, and involves loading some very large tilesets twice.
## Design
Line type layers would include a `background` (or other name) attribute with width and colour properties.
Clicking on the background would return a result for `this.map.queryRenderedFeatures(e.point, { layers: [someLineLayers })` as per clicking on the line itself.
The advantage of this is simplification of layer maintenance and also avoids loading data sources twice on the same style.
Default value for the background would be 0 so not affect any existing line type layers.
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
The issue names no repository files or tests. Start by tracing line-layer rendering and map.queryRenderedFeatures() behavior, then determine how configurable background width and color should affect hit testing and Studio; done means background clicks return the line feature while the default width of 0 preserves existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100