mapbox / mapbox/mapbox-gl-js

self-intersect area can not callback click event

Open
#12,736 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 2.12.0

### Question

I created a self-intersect vector polygon layer, and added click listener to it.When I click the no self-intersect area, I can got the callback.But when I click the self-intersect area, I can not got the callback.I want know if mapbox-gl support add click listener to self-intersect polygon?
![image](https://github.com/mapbox/mapbox-gl-js/assets/31084241/89b6e620-94f6-44de-bcff-2a3370daa276)

I think `map.queryRenderedFeatures()` return [], when I click self-intersect area.
```javascript
const delegate = (e) => {
const filteredLayers = layers.filter(layerId => this.getLayer(layerId));
const features = filteredLayers.length ? this.queryRenderedFeatures(e.point, {layers: filteredLayers}) : [];
if (features.length) {
// Here we need to mutate the original event, so that preventDefault works as expected.
e.features = features;
listener.call(this, e);
delete e.features;
}
};
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the click-listener delegate and queryRenderedFeatures call shown in the issue, then reproduce the behavior with a self-intersecting polygon in Mapbox GL JS 2.12.0. Trace why the self-intersecting area returns no features; done means clicks there produce the expected callback without breaking ordinary polygon clicks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.